Question: 1 Affine Cipher (70 points) The Affine cipher is a cryptographic method for encrypting text such that it becomes unreadable to a party without access



1 Affine Cipher (70 points) The Affine cipher is a cryptographic method for encrypting text such that it becomes unreadable to a party without access to the cryptographic key. The encryption and decryption operations are simple shifts of the alphabet letters in a cyclic fashion. Mathematically, for a key k (, ), the encryption and decryption are defined as Encryption: c-a-x + ) mod 26 , 1 a 26 and 1 26 Decryption : x-a-1 . (c-) mod 26 Here, -1 is a illultiplicative inverse Uf li lhe group of illlegers lllodulo 26. Tu find Ihe Illultiplicative inverse Uf one needs to find x such that ar 1 mod 26 A simple way of finding the inverse of is to consider all numbers from 1 to 25 and see which one satisfies equation To illustrate the use of the Affine cipher, consider the encryption of "defend the east wall of the castle" with key k (, )-(5,7). The first letter "d" is mapped to number 3 (alphabet letters are numbered from 0 to 25) Inserting 3 to the encryption functions yields c 53+7 mod 26 22 mod 26 22 which corresponds to letter "w". Applying the same process for ever letter, the plaintext sentence is translated to "wbgbuw yqb bhty nhkk zg yqb rhtykb" . Now to decode, we first need to find the inverse of 5 modulo 26. Scanning every number from 1 to 25, we observe that 5-21 mod 26-1, so the inverse of 5 is 21. Using 21 for decrypting the first letter "w" (or 22) becomes 21 (22- 7) mod 26-3, which reverses back to letter "d" 21 (22- 7) mod 26 3, which reverses back to letter "d". NOTE: The modulo operation for negative numbers is different from the % arithmetic operator in C. Write a C program that decrypts a file named "encrypted.txt" and places the decryption output to a file called "de- crypted. txt". A file encrypted with k (5, 7) is provided with the assignment. You can use it to test your decryption function. You will know when you have succeeded because the text becomes readable. In your program . Ask the user to enter the decryption key. . Repeat the request until the right key is entered. Display a message when file . Ask the user to enter a key to re-encrypt the file . Re-encrypt file "decrypted.txt" and store it at "encrypted.txt" Display a message when fhle encryption is over. decryption is over a m Only alphabet letters (uppercase/lowercase) must be encrypted. The remaining characters (question marks, periods etc. must remain intact) Your code must be modular. Use the following function prototypes for encryption and decryption: char encryptFun(int a, int b, char letter); // This function receives as input the key components (, ) and the Your code must be modular. Use the following function prototypes for encryption and decryption char encryptFun(int a, int b, char letter); // This function receives as input the key components (0,9) and the plaintext letter and returns the encrypted letter char decryptFun(int a, int b, char letter); // This function receives as input the key components (a, ) and an encrypted letter and returns the decrypted letter int inverse(int x); // This function as input receives an int r and returns the multiplicative inverse of r modulo 26 You are also given the following function that correctly implements the modulo operation for both positive and negative numbers int mod (int , int y) while(x
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
