Assignment Overview

(learning objectives)
This assignment will give you more experience on the use of:

1. integers (int)
2. conditionals
3. iteration
4. string

The goal of this project is to implement a different cryptographic technique by combining two cryptographic techniques. I call it dumbcrypt. Dumbcrypt is a combination of Affine Cipher and Caesar Cipher. The user will enter a sentence, a string composed of letters, numbers, and punctuation. Notice that spaces are not allowed in the input string because spaces provide too many clues to someone trying to crack your coded message. Your job is to encrypt the sentence using a combination of Affine and Caesar Cipher. The letters and numbers will be encrypted and decrypted using Affine Cipher; the punctuation using Caesar Cipher.

Assignment Background

Affine Cipher - https://en.wikipedia.org/wiki/Affine_cipher

Affine Cipher is a bit different than Caesar Cipher in that the Affine Cipher uses an encryption function to calculate the integer that corresponds to the cipher text letter. The encryption function for a letter variable named x is

E(x) = (Ax+N) mod M

Where A and N are keys of the cipher and M is size of the alphabet (for example, M=26 for English letters; M = 36 for English letters plus digits). The decryption of Affine Cipher only works when A and M are co-primes of each other.

N will be an input to the program and will be fixed for the whole run of the program. N is sometimes referred to as the "rotation" but is effectively a key.

Co-primes are a pair of numbers whose greatest common divisor (GCD) is 1. Only one co-prime is needed (of possibly many). For this project we choose the smallest greater than one so everyone is using the same onemaking testing feasible.

Algorithm:

1. Calculate M, the number of characters in the alphabet (Hint: use len())

2. Calculate A using get_smallest_co_prime(M)

3. For the character to be encrypted find its index in the alphabet: x in the formula is the index

4. Apply the formula to get the index of the cipher character: E(x) = (Ax+N) mod M

5. Using the index get the cipher character from the alphabet

6. Return the character.

Decryption is a little more complicated than encryption. The decryption function is

D(x) = A -1 (x-N) mod M

Where A-1 is the modular multiplicative inverse (https://en.wikipedia.org/wiki/Modular_multiplicative_inverse). We provide the function multiplicative_inverse(A,M) that calculates the multiplicative inverse, A-1 , for you. The function checks all the numbers x from 1 to M and for every number x checks if (A*x) mod M is 1. Once you have the A-1 , you can use the decryption function to calculate the integer that corresponds to plaintext letter.

The decryption algorithm is the same as encryption with two modifications:

Algorithm:

1. Calculate M, the number of characters in the alphabet (Hint: use len())

2. Calculate A using get_smallest_co_prime(M)

3. Calculate A-1 using the function multiplicative_inverse(A,M) .

4. For the character to be encrypted find its index in the alphabet: x in the formula is the index

5. Apply the formula to get the index of the cipher character: D(x) = A -1 (x-N) mod M Note the formula difference from encryption: the parentheses are different and it has subtraction.

6. Using the index get the cipher character from the alphabet

7. Return the character.

Caesar Cipher - https://en.wikipedia.org/wiki/Caesar_cipher

Caesar Cipher is a simplified form of Affine cipher which follows similar encryption and decryption algorithm. Caesar Cipher uses a single key to calculate the integer that corresponds to the ciphertext letter. The encryption function is

E(x) = (x+N) mod M

The decryption function is

D(x) = (x-N) mod M

The algorithms for Caesar Cipher are similar to the Affine Cipher algorithms

Project Description

Your program must meet the following specifications:

1. You have to use the eight functions in the provided proj04.py skeleton. You have to implement and use the following:

a. check_co_prime(num, M): Takes two numbers as parameters. Returns True if num and M are co-primes, otherwise returns False. (Hint: used GCD)

b. get_smallest_co_prime(M): Takes one number M as a parameter: Returns the smallest coprime of M that is greater than 1. For example, if M = 26, the smallest co- prime greater than one is 3. If M = 210, the smallest co-prime greater than one is 11. (Hint: use check_co_prime)

c. caesar_cipher_encryption(ch,N,alphabet): Takes three inputs: a character to encrypt, the rotation N, and the alphabet. Returns the cipher text character using the Caesar Cipher.

d. caesar_cipher_decryption(ch,N, alphabet): Takes three inputs: a character to encrypt, the rotation N, and the alphabet. Returns the plain text character using the Caesar Cipher.

e. affine_cipher_encryption(ch,N, alphabet): Takes three inputs: a character to encrypt, the rotation N, and the alphabet. Returns the cipher text character using the Affine Cipher.

f. affine_cipher_decryption(ch,N, alphabet): Takes three inputs: a character to encrypt, the rotation N, and the alphabet. Returns the plain text character using the Affine Cipher.

g. main(): Takes no input. Returns nothing. First prompts for rotation, N. Then prompts for a command (d,e,q), prompts for a string, decrypts or encrypts the string depending on the command using the encryption and decryption functions described above. Remember to use a different encryption/decryption algorithm for punctuation.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.