Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Python and can you please use comments, and answer everything if any questions comment it has everything here! Affine Cipher (4 pts) a=0 b

In Python and can you please use comments, and answer everything if any questions comment it has everything here!

Affine Cipher (4 pts)

a=0 b =1 c=2 d=3 e=4 f=5 g=6 h=7 i=8 j=9 k=10 l=11 m=12 n=13 o=14 p=15 q=16 r=17 s=18 t=19 u=20 v=21 w=22 x=23 y=24 z=25

The Affine cipher is a simple substitution cipher that is similar to the Caesar cipher. The 'key' for the Affine cipher consists of 2 numbers, we'll call them a and b. We assume the use of a 26 character alphabet (m = 26). a should be chosen to be relatively prime to m (i.e.a should have no factors in common with m). The algorithm for computing the Affine cipher is: o For each letter in the plaintext Convert the letter to the corresponding number p (see table above). Compute the cipher number using the formula c = ap + b (mod m) Find the cipher letter in the alphabet that corresponds to the number c. Append the cipher letter to the cipher text you are generating

Practice encrypting with the Affine cipher Given the following plaintext messages, compute the Affine cipher with a = 9 and b = 4. (m is 26 since we have an alphabet of 26 letters)

Plaintext attackatdawn retreatnow

Ciphertext ettewqetfeur botboetrau

Write a function to check for relatively prime numbers in order for the Affine cipher to work, the multiplier a must be relatively prime with the modulus m. This means that the two integers have no common factors. For example, 15 and 26 have no factors in common, so 15 is an acceptable value for a, however 12 and 26 have factors in common (e.g. 2) so 12 cannot be used for a value of a. Write a function that takes as parameters two positive integers (a and m) and returns TRUE if the two numbers are relatively prime and FALSE if they are not relatively prime.

Write a function to compute the Affine cipher. The input parameters for the function will be a, b, m and the plaintext. The function will return the ciphertext. This function should check to make sure that a and m are relatively prime (by calling the function above). If not, it should return a blank string. Test your function using the examples from part b) above.

Decoding the Affine Cipher (4 pts)

To decode an Affine cipher, we need to reverse the process. This is not a simple as reversing a Caesar cipher because it involves multiplication and addition. We need to find a way to reverse the operations in the encryption algorithm. Since we are doing modular multiplication, we need to find the modular inverse of the multiplier a. In other words, we need to find a number x such that:

a*x mod 26 = 1

Once you have determined x, the modular inverse of a, the decryption formula is: p = x * (c b) mod m where c is the numerical value of the ciphertext letter and p is the numerical value of the plaintext. The algorithm to decrypt a ciphertext message given the keys a and b is: Find the modular inverse of a mod m. For each letter in the ciphertext o Convert the letter to the corresponding number c (see table above). o Compute the plaintext number using the formula p = x * (c b) mod m o Find the plaintext letter in the alphabet that corresponds to the number p. o Append the plaintext letter to the plaintext you are generating o

Practice decrypting a message that was encrypted with the Affine cipher Given the following ciphertext messages that were encrypted using the Affine cipher with a = 11 and b = 6. (m is 26 since we have an alphabet of 26 letters) First find the modular inverse of a = 11 mod 26. Remember, this means you want a number x such that a*x mod 26 = 1 ______________________________________ Now use x to decrypt the following ciphertext code:

Ciphertext Plaintext

oqthylqwceiqtu winteriscoming

rlygmhfyceny breakthecode

Write a function to find the modular inverse of a given integer The input parameters to the function will be the number a and the mod m. The function will return the modular inverse of a mod m.

Write a function to decrypt a message that was encrypted using the Affine cipher The input parameters to the function will be the ciphertext, the keys a and b that were used to encode the message and the modulus m. This function should get the modular inverse of a by calling the function above and then compute the plaintext message. Test your function with the examples above.

Breaking Ceasar (2 pts)

In class we looked at the Caesar cipher as a simple encryption algorithm.

Why is the Caesar cipher NOT a good algorithm to use for Internet security?

Given your answer to question a) above, write a function that can break the Caesar cipher. That is, if you are given the ciphertext, see if you can find a way to determine the plaintext. Use a brute force method and assume that a human can look at all of the possible values for the plaintext and decide which one is the most likely. The function signature for this exercise is: def breakCaesar(ciphertext): # Given the ciphertext # Print all of the possible values for the plaintext # so that a human can see what the secret message might be Note: You may use code that already wrote in class this week that you can find on the Sample Code page of the Sakai site. Once you have the function working, use it to crack the following secret message: maxitllphkwbltuktvtwtukt

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

Oracle Autonomous Database In Enterprise Architecture

Authors: Bal Mukund Sharma, Krishnakumar KM, Rashmi Panda

1st Edition

1801072248, 978-1801072243

More Books

Students also viewed these Databases questions

Question

Lo6 Identify several management development methods.

Answered: 1 week ago

Question

LO4 List options for development needs analyses.

Answered: 1 week ago