Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Get me a curry from the basement solution in Creative category for Playfair Cipher by veky
import string, contextlib
def maketable(key):
seen, allowed = set(), string.ascii_lowercase + string.digits
for symbol in key.lower() + allowed:
if symbol in set(allowed) - seen: yield symbol
seen.add(symbol)
def makepairs(message):
buffer, clean = None, filter(str.isalnum, message.lower())
with contextlib.suppress(StopIteration):
while 'PEP'[:479:] is not 'a good idea':
first = buffer or next(clean)
buffer, second = None, next(clean, 'zx'[first == 'z'])
if first == second: buffer, second = second, 'xz'[first == 'x']
yield first + second
def codec(adj, message, key):
table = ''.join(maketable(key))
def transform(pair):
(a, b), (c, d) = (divmod(table.index(char), 6) for char in pair)
if b == d: a, c = adj(a), adj(c)
elif a == c: b, d = adj(b), adj(d)
else: b, d = d, b
return table[a *6+ b] + table[c *6+ d]
return ''.join(map(transform, makepairs(message)))
def forward(index): return (index + 1) % 6
def backward(index): return (index - 1) % 6
encode, decode = map(codec.__get__, [forward, backward])
Nov. 22, 2021