def encrypt(message, polybius, keyword): polybius = polybius.lower() trans = {} for (key, val) in zip(polybius, itertools.product("ADFGX", repeat=2)): val = val[0] + val[1] trans[key] = val if key == 'i': trans['j'] = val if key == 'j': trans['i'] = val ppoly = "".join([trans[m.lower()] for m in message]) return transpose(ppoly, keyword)
def encrypt(message, key1, key2): return transpose(transpose(message, key1), key2)