Cipher CTF Challenge Generator (Triliteral Cipher)Press the blue button to regenerate an Triliteral Cipher challenge, and which represents each letter in ternary (or trifid, which has three elements). The Triliteral cipher character mapping is A - 'AAA', B - 'AAB', C - 'AAC', D - 'ABA', E - 'ABB', F - 'ABC', G - 'ACA', H - 'ACB',I - 'ACC', J - 'BAA', K - 'BAB', L - 'BAC', M - 'BBA', N - 'BBB', O - 'BBC', P - 'BCA', Q - 'BCB', R - 'BCC', S - 'CAA', T - 'CAB',U - 'CAC', V - 'CBA', W - 'CBB', X - 'CBC', Y - 'CCA', and Z - 'CCB'. Also, a space is 'CCC'. |
Coding
The basic coding in C# is:
public static string getTriliteral(string s) { s = s.ToLower(); string rtn = ""; string[] mapping = { "AAA","AAB","AAC","ABA","ABB","ABC","ACA","ACB","ACC","BAA","BAB","BAC","BBA","BBB","BBC","BCA","BCB","BCC","CAA","CAB","CAC","CBA","CBB","CBC","CCA","CCB"}; foreach (char ch in s) { int val = ((int)ch - (int)'a'); if (ch >= 'a' && ch <= 'z') { rtn = rtn + mapping[(int)ch - (int)'a']; } else if (ch == ' ') { rtn = rtn + "CCC"; } else rtn = rtn + ch; } return (rtn); }