Week 3 Homework: Vigenère Cipher

advertisement
Week 3 Homework: Vigenère Cipher
The Vigenère Cipher
• A polyalphabetic substitution cipher
•The rule to substitute characters changes with each
character in the input text
• Originally described in 1553 by Giovan Battista Bellaso,
but mistakenly attributed to Blaise de Vigenère (1586)
by 19th Century cryptographers.
• Though occasionally broken before the 19th century, no
published formal attack until Kasiski and Babbage in the
mid 1800s.
Vigenère Cipher Encryption Substitution Rule
• Choose a Keyword W [1, N] characters long.
• Pair each character in Keyword with character in
Plaintext, repeating/truncating Keyword if it is shorter/
longer than Plaintext.
• Replace each character in Plaintext by encrypting it
with a CaesarCipher of Shift equal to the position in
the alphabet of the Keyword character that is paired
with the Plaintext character
Encrypting With the Vigenère Cipher, W=KEY
Plaintext
Keyword
HELLOWORLD
KEYKEYKEYK
CaesarEncrypt(‘H’,10)
Ciphertext
CaesarEncrypt(‘O’,4)
RIJVSUYVJN
Vigenère Cipher Decryption Substitution Rule
• Choose a Keyword W [1, N] characters long.
• Pair each character in Keyword with character in
CipherText, repeating/truncating Keyword if it is
shorter/longer than CipherText.
• Replace each character in Plaintext by decrypting it
with a CaesarCipher of Shift equal to the position in
the alphabet of the Keyword character that is paired
with the CipherText character.
Decrypting With the Vigenère Cipher, W=KEY
Ciphertext
Keyword
RIJVSUYVJN
KEYKEYKEYK
CaesarDecrypt(‘R’,10)
Ciphertext
CaesarDecrypt(‘S’,4)
HELLOWORLD
C++ Implementation : First Steps
1. A new command line argument is needed to allow
the user to select the cipher to use.
2. mpags-cipher should fail with a suitable error
message if an unknown cipher is supplied.
3. Think about how to structure the code that creates
and uses the chosen cipher - we may want to add
further ciphers in the future.
C++ Implementation : Vigenère Cipher
1. Implement it as a class, like we’ve done for the
Caesar cipher.
2. An invalid keyword (zero characters or nonalphabetical characters) should be a failure condition.
3. As it uses the Caesar Cipher, think about how to reuse
your CaesarCipher class.
4. Think about the member functions the CaesarCipher
class could have to help with this reuse.
Download