Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
24
Task/Substitution-cipher/MiniScript/substitution-cipher.mini
Normal file
24
Task/Substitution-cipher/MiniScript/substitution-cipher.mini
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue