Substitution cipher: Difference between revisions

Content deleted Content added
No edit summary
JoeStrout (talk | contribs)
added MiniScript example
Line 978:
crypted file into original/decrypted file. This type of Encryption/Decryption sc
heme is often called a Substitution Cipher.</pre>
 
=={{header|MiniScript}}==
<lang MiniScript>alphabet = "abcdefghijklmnopqrstuvwxyz".split("")
cipher = alphabet[0:]
cipher.shuffle
encode = {}
decode = {}
for i in alphabet.indexes
encode[alphabet[i]] = cipher[i]
decode[cipher[i]] = alphabet[i]
encode[alphabet[i].upper] = cipher[i].upper
decode[cipher[i].upper] = alphabet[i].upper
end for
 
apply = function(map, s)
chars = s.split("")
for i in chars.indexes
if map.hasIndex(chars[i]) then chars[i] = map[chars[i]]
end for
return chars.join("")
end function
 
msg = "Now is the time for all good men (and women) to come together."
secretCode = apply(encode, msg)
print secretCode
print apply(decode, secretCode)</lang>
{{out}}
<pre>Rzs ho wft whxt bzv ykk nzzg xtr (yrg szxtr) wz jzxt wzntwftv.
Now is the time for all good men (and women) to come together.</pre>
 
 
=={{header|Perl}}==