Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second solution in Creative category for Vigenere Cipher by Sim0000
def decode_vigenere(old_encrypted, old_decrypted, new_encrypted):
key = [(ord(i) - ord(j))%26 for i, j in zip(old_decrypted, old_encrypted)]
n = next(n for n in range(1,len(key)+1) if key == (key[:n]*(len(key)//n+1))[:len(key)])
return ''.join(chr(65+(ord(i)-65-j)%26) for i, j in zip(new_encrypted, key[:n]*(len(new_encrypted)//n + 1)))
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert decode_vigenere('DONTWORRYBEHAPPY',
'FVRVGWFTFFGRIDRF',
'DLLCZXMFVRVGWFTF') == "BEHAPPYDONTWORRY", "CHECKIO"
assert decode_vigenere('HELLO', 'OIWWC', 'ICP') == "BYE", "HELLO"
assert decode_vigenere('LOREMIPSUM',
'OCCSDQJEXA',
'OCCSDQJEXA') == "LOREMIPSUM", "DOLORIUM"
Sept. 18, 2014
Comments: