Skip to content

Instantly share code, notes, and snippets.

@martok
Created April 2, 2013 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martok/5296877 to your computer and use it in GitHub Desktop.
Save martok/5296877 to your computer and use it in GitHub Desktop.
decode[text_String, key_String] := Module[{textCode, keyCode},
textCode =
Cases[ToCharacterCode[
ToUpperCase@
text], _?(IntervalMemberQ[Interval@{65, 90}, #] &)] - 65;
keyCode =
Cases[ToCharacterCode[
ToUpperCase@
key], _?(IntervalMemberQ[Interval@{65, 90}, #] &)] - 65;
keyCode = If[Length[textCode] < Length[keyCode],
keyCode[[;; Length@textCode]],
PadRight[keyCode, Length@textCode, keyCode]];
FromCharacterCode[Mod[textCode - keyCode, 26] + 65]]
table1 := Table[
a[[2]] -> a[[1]], {a,
Transpose[{CharacterRange["A", "Z"], Range[0, 25]}]}];
table2 := Table[
a[[1]] -> a[[2]], {a,
Transpose[{CharacterRange["A", "Z"], Range[0, 25]}]}];
konvert[val_] := PadLeft[IntegerDigits[val, 26], 3, "A"] /. table1;
konvertBack[str_] := FromDigits[Characters[str] /. table2, 26]
step[st_] := Block[{str, a, b, c},
str := StringJoin[konvert[st]];
a := decode["UHG", str];
b := decode["NZCBXBXUSXDBXIWZWMMLLVLHM", str];
c := decode["WEQ", str];
{str, a, b, c}
];
Export["3st.txt", ParallelTable[step[i], {i, 0, 26^3}], "Text"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment