Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
partial solution in Clear category for Vigenere Cipher by DiZ
from itertools import accumulate, cycle
from functools import partial
from string import ascii_uppercase
def vigenere(mode, message, key):
"""Vigenere cipher (mode = 1 to encode, -1 to decode)"""
return ''.join(ascii_uppercase[ord(m) + ord(k) * mode] for m, k in zip(message, cycle(key)))
encode, decode = partial(vigenere, 1), partial(vigenere, -1)
def find_key(decrypted, encrypted):
"""Find key given a text and its Vigenere ciphered result"""
n, full_key = len(decrypted), decode(encrypted, decrypted)
return next(key for key in accumulate(full_key) if (key * n).startswith(full_key))
def decode_vigenere(old_decrypted, old_encrypted, new_encrypted):
"""Decrypt a text using same key than an old message"""
return decode(new_encrypted, find_key(old_decrypted, old_encrypted))
Sept. 29, 2014
Comments: