Playfair cipher: Difference between revisions

Content added Content deleted
Line 1,109: Line 1,109:
s = replace(replace(uppercase(s), from => to), r"[^A-Z]" => "")
s = replace(replace(uppercase(s), from => to), r"[^A-Z]" => "")
a, dupcount = [c for c in s], 0
a, dupcount = [c for c in s], 0
b = deepcopy(a)
for i in 1:2:length(a)-1
for i in 1:2:length(a)-1
if a[i] == a[i + 1]
if s[i] == s[i + 1]
splice!(b, i+1+dupcount:i+dupcount, 'X')
splice!(a, i+1+dupcount:i+dupcount, 'X')
dupcount += 1
dupcount += 1
end
end
end
end
s = String(b)
s = String(a)
return isodd(length(s)) ? s * "X" : s
return isodd(length(s)) ? s * "X" : s
end
end