Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Caesar and Vigenre Encryption *You may not use the Python ord() or chr() function. For this assignment, you will always leave all characters that are

Caesar and Vigenre Encryption

*You may not use the Python ord() or chr() function.

For this assignment, you will always leave all characters that are not letters unchanged.

Plaintext message letters may be either upper or lower case, but you should output only upper case ciphertext.

Remember that the string function upper() gives back a version of its string that has all alphabet characters converted to upper case.

I.e.,

name = "Caesar" print (name.upper()) 

will print out CAESAR

Note that you are writing two functions for each cryptosystem, an encrypt and a decrypt, so one partial test of the correctness of your work is whether first encrypting and then decrypting returns the original string (except that you may have converted some lower case letters to upper case).

Overview of the assignment

You will write a total of four functions, each of which will take two inputs and return a string:

c_encrypt()

c_decrypt()

vig_encrypt()

vig_decrypt()

The first argument will be a string containing the plaintext (or clear text) message to be encrypted for the two encrypt functions, and a string containing a ciphertext to be decrypted. The second argument will be the key.

For this assignment, you will always leave all characters in plaintext or ciphertext that are not letters (i.e., spaces and punctuation marks) unchanged.

Plaintext message letters may be either upper or lower case, but you should output only upper case ciphertext.

Remember the string function upper() you used in lab.

Note that you are writing two functions for each cryptosystem, an encrypt and a decrypt, so one partial test of the correctness of your work is whether first encrypting and then decrypting returns the original string (except that you may have converted some lower case letters to upper case).

Caesar Cipher

Caesar part of the homework: Write c_encrypt() and c_decrypt(), both of which take two arguments, the first one a string and the second one an integer key.

Both should return a string.

This will be much easier if both functions use the shift() function you wrote for the lab.

Vigenre Cipher

The Vigenre Cipher was more or less completely unbreakable from its introduction sometime in the 1500s until well into the 1800s.

The key in Vigenre is a key word that is used over and over again to give a different key to the Caesar cipher for each letter of the encryption (and decryption), with 'A', in good Python form, representing a rotation of 0. (We Pythonistas start at 0, not 1!)

So if the key is ABACUS, then we encrypt:

the first letter of our message with a Caesar cipher with a key/rotation of 0, because A is the first letter of the alphabet,

the second letter with a key/rotation of 1 (for the 'B'),

the third letter with a rotation of 0 (for the second 'A' of ABACUS),

the fourth letter with a key/rotation of 2 for the 'C',

the fifth letter with a key/rotation of 20 for the 'U',

the sixth letter with a key/rotation of 18 for the 'S',

and wrap back to the start of our keyword ABACUS and encrypt the seventh letter with a key/rotation of 0 for the first 'A' in ABACUS

Back in the 1800s people wanting to use this system would make use of a Vigenre square, also known as the tabula recta, shown in the middle of the Wikipedia entry for the Vigenre cipher, but we can use Python.

Vigenre part of the homework: Write vig_encrypt() and vig_decrypt() functions. Each takes two strings as inputs, with the first being the plaintext/ciphertext, and the second being the key. Both should be calling functions you wrote earlier to help make the work easier. One check on your work: vig_encrypt("ATTACKATDAWN", "LEMON") should return the string LXFOPVEFRNHR

shift function:

def cencrypt(WORD, shift): alpha= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' letters= alpha.upper(); encryption= '' for ch in WORD: if ch in alpha: num= letters.find(ch) num= shift+ num if num < 0: num= num + len(letters) elif num> 26: num= num - len(letters) encryption= encryption + ch else: encryption= encryption + letters[num] return encryption

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2014 Integration Services

Authors: Brian Knight, Devin Knight

1st Edition

1118850904, 9781118850909

More Books

Students also viewed these Databases questions