Playfair cipher: Difference between revisions

m
Line 1,106:
to = (to == "" && from == "J") ? "I" : to
 
function canonical(s, dup_toX=true)
s = replace(replace(uppercase(s), from => to), r"[^A-Z]" => "")
a, dupcount = [c for c in s], 0
for i in 1:2:length(a)-1
if s[i] == s[i + 1]
dup_toX && splice!(a, i+1+dupcount:i+dupcount, 'X')
dupcount += 1
end
Line 1,120:
 
# Translate key into an encoding 5x5 translation matrix.
keyletters = unique([c for c in canonical(key * "ABCDEFGHIJKLMNOPQRSTUVWXYZ", false)])
m = Char.((reshape(UInt8.(keyletters[1:25]), 5, 5)'))
 
4,108

edits