Playfair cipher: Difference between revisions
Content added Content deleted
Line 1,120: | Line 1,120: | ||
# Translate key into an encoding 5x5 translation matrix. |
# Translate key into an encoding 5x5 translation matrix. |
||
keyletters = unique([c for c in canonical(key * "ABCDEFGHIJKLMNOPQRSTUVWXYZ")]) |
keyletters = unique([c for c in canonical(key * "ABCDEFGHIJKLMNOPQRSTUVWXYZ")]) |
||
m = reshape(keyletters[1:25], 5, 5) |
m = reshape(keyletters[1:25], 5, 5) |
||
# encod is a dictionary of letter pairs for encoding. |
# encod is a dictionary of letter pairs for encoding. |
||
encod = Dict() |
encod = Dict() |
||
Line 1,149: | Line 1,149: | ||
canontxt = canonical(txt) |
canontxt = canonical(txt) |
||
letterpairs = map(x -> canontxt[x], findall(r"(.)(?:(?!\1)(.))?", canontxt)) |
letterpairs = map(x -> canontxt[x], findall(r"(.)(?:(?!\1)(.))?", canontxt)) |
||
if isencode |
if isencode |
||
# Encode text |
# Encode text |