PYTHON
CRYPTOGRAPHY – VIGENERE CIPHER

 

 

DESCRIPTION


You will write code related to the Vigenère cipher that can be used in encrypting/decrypting messages.


WEAKNESS OF SUBSTITUTION AND CAESAR

 

The Substitution ciphers (including the Caesar ciphers) have a fundamental weakness.  One can analyze the frequency of symbols to determine which letter they represent.  This type of analysis is called frequency analysis. 

 

For example, if you have a ciphertext where the letter P is the most common, you might be able to figure out that P is really the letter E because E is the most common letter in the english language.

 

THE VIGENERE CIPHER

 

The Vigenère cipher is similar to the Caesar cipher but makes use of different shift values depending on the location of the letter in the document. 

These different shift values are usually expressed as a keyword or sentence.  The letters of the keyword represent the number to shift by with A=0, B=1, C=2 and so on…

 

The keyword is usually shorter than the message and is repeated over and over as much as needed.

 

EXAMPLE

 

Plaintext: CAMPEAU

Vigenère keyword: BAD

 

Plaintext

Keyword

Ciphertext

Explanation

C

B

D

Keyword letter is B, so shift by 1.

A

A

A

Keyword letter is A, so shift by 0.

M

D

P

Keyword letter is D, so shift by 3.

P

B

Q

Keyword letter is B, so shift by 1.

E

A

E

Keyword letter is A, so shift by 0.

A

D

D

Keyword letter is D, so shift by 3.

U

B

V

Keyword letter is B, so shift by 1.

 

Notice that the ciphertext contains the letter D twice.  The first was created by the letter C and the other was created by the letter A.  So this makes the frequence analysis more challenging.

 

WORK

 

QUESTION 1

In a Python file called Vigenere, write the enc and dec functions for Vigenère ciphers.  They only need to work with lowercase letters.

 

enc (word, keyword)

dec (word, keyword)

 

Test your code.

 

Feel free to use any of your past code in here.

 

QUESTION 2

 

The following sentence has been encrypted using the Vigenère cipher with keyword YODA.  Use your program to decrypt it.

 

BCRRBCQORHKEPSLSLCWRW