06.0 Python‎ > ‎Python Projects‎ > ‎

Vigenère Cipher Problem

Objectives

The student will:
  • structure their own program (set their own algorithm)
  • use modular arthimatic - this will be needed for the "wrap around"
  • process a list (an array) - this maybe the easiest way to find the first word of length 5 or longer
  • parse text into words and place them into a list
  • process words in a list

Project Overview

This problem is originally from: http://www.simpson.edu/~cs/problems.html

In a Vignère cipher, each letter of the alphabet corresponds to a number using the scheme: A=0, B=1, C=2, ... Y=24, Z=25. To encode a message, an encryption key word is "added" to the message. For example, if the message were IDES OF MARCH, and the key DAGGER used, the encryption would be:

Message: IDESOFMARCH Key: DAGGERDAGGE Encryption: LDKYSWPAXIL

Note that spaces are not encrypted and sums greater than 25 wrap back around to the beginning of the alphabet again. For example, L + W yields H. The ASCII code for the letter A is 65.

Create a program that would encrypt and decrypt messages based upon the following scheme: 
When encrypting, the Vignère method is used. The key is the first word of the message that is at least five letters or longer. For example, in the message "IDES OF MARCH", "MARCH" would be chosen as the key. If the message contains only four letter or shorter words, such as "WILL THIS BE ON THE TEST", then the first five letters of the message ("WILLT") become the key. You may assume that punctuation will not be entered, uppercase letters will be used, and that messages shorter than five letters will not be encoded.

Have your program ask its user if it is to encode or decode a message. When encoding, it should take in the message and give both the key and the encrypted message. When decoding, it should take in the encrypted message and the key, and give the decoded message.

To make this program easier:
  • do not include punctuation
  • do not include numbers
  • use only upper case letters

Project Road Map

  1. By hand, determine how the encryption/decryption process works. Manually encrypt then decrypt the phrase  IDESOFMARCH
    If do not understand how this works, you will not be able to program it!
  2. Create a method to encrypt one letter
  3. Use your encrypt one letter method to encrypt the phrase.

Hints

  1. alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    Use alphabet.find(ltrToEncrypt) to find the position of the letter to encrypt. 
    Do the same for the letter of the key.
    Add them together.
    Now find the  letter -- you may need to do some modular arithmetic to keep the value in range (0 to 25) 
Comments