Substitution cipher: Difference between revisions

mNo edit summary
Line 1,293:
crypted file into original/decrypted file. This type of Encryption/Decryption sc
heme is often called a Substitution Cipher.</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<lang Mathematica>SeedRandom[1234];
a=Characters@"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ";
map=Thread[a->RandomSample[a]];
ClearAll[SubstitutionCipherEncode,SubstitutionCipherDecode]
SubstitutionCipherEncode[input_String,map_]:=StringReplace[input,map]
SubstitutionCipherDecode[input_String,map_]:=StringReplace[input,Reverse/@map]
str="The quick brown fox jumps over the lazy dog,who barks VERY loudly!";
encoded=SubstitutionCipherEncode[str,map]
decoded=SubstitutionCipherDecode[encoded,map]
str===decoded</lang>
{{out}}
<pre>"DebTyUsLNTg2H01TWHSTfUt5qTHZb2T7ebTl4 8TQHc,0eHTg42NqTuK6CTlHUQl8!"
"The quick brown fox jumps over the lazy dog,who barks VERY loudly!"
True</pre>
 
=={{header|MiniScript}}==
1,111

edits