#311 · Codes and ciphers · Intermediate · 70 XP · about 14 min
A Caesar cipher shifts every letter by the same amount, which makes it easy to break. The Vigenere cipher shifts each letter by a different amount, taken from a keyword: key letter A shifts by 0, B by 1, C by 2, and so on up to Z, which shifts by 25. The keyword is repeated as many times as needed.
Write vigenere(text, key, decrypt=False) that returns the encrypted text, or the decrypted text when decrypt is True. The rules:
a gives the same shift as A.vigenere("MEET ME AT NOON", "CODE") # returns 'OSHX OS DX PCRR' vigenere("OSHX OS DX PCRR", "CODE", decrypt=True) # returns 'MEET ME AT NOON' vigenere("Bring 3 apples.", "pie") # returns 'Qzmco 3 eexpta.'
In the first example the key letters line up with the letters of the message as C O D E, C O, D E, C O D E: M shifted by 2 (C) is O, the first E shifted by 14 (O) is S, and so on. The spaces do not use up key letters.
text has 0 to 20,000 characters.key has 1 to 100 letters.First solves only, ranked by stars and then time.