Question

In: Computer Science

COP2271 MATLAB HW9 Homework: Modified Vigenere Cipher Implement a decryption cipher to decode messages using a...

COP2271 MATLAB HW9 Homework: Modified Vigenere Cipher Implement a decryption cipher to decode messages using a secret key. You are required to submit the solution and screenshots for this question. Key programming concepts: if statements, loops, strings Approximate lines of code: 27 (does not include comments or white space) Commands you can’t use: None... Program Inputs • Enter message to decrypt: • Enter secret key: – The user will always enter text for all prompts, no error checking needed. The secret key will always be lower case to start. Program Outputs • Updated key: XXX – Replace XXX with the adjusted secret key • Decrypted msg: YYY – Replace YYY with the deciphered message Assignment Details This assignment will give you a brief introduction into cryptography using a modified Vigenere Cipher! Cryptography allows us to encode and decode messages that are difficult to decipher without knowledge of a secret key/table/rules. Cryptography is a rich subject in its own right, and we will not have time to cover it in detail. Please check out the numerous online resources if you want more information: http://www.braingle.com/brainteasers/codes/index.php This particular cipher depends upon a secret key (a single word) selected by the user that only contains letters which is paired with a phrase. For example, given the phrase: Attack Now! the user could choose the secret key: woot The first step to encryption is to repeat the letters in secret key until it has the same amount of letters as the message, skipping any spaces or punctuation! So with woot as the key, repeat the letters w, o, o, t for each letter in Attack Now!. Note that you must also change the letters in the key to upper case if the letters in phrase are upper case. COP2271 MATLAB HW9 A t t a c k N o w ! W o o t w o O t w ! Now each letter in the secret message determines how far to shift the corresponding letter in the updated key. Essentially, take the position in the alphabet (starting from 0) of the letters in message and then shift key by that amount (like a Caesar Cipher). Also, treat upper case and lower case letters as two different alphabets. Here is a detailed breakdown: Letter in message Alphabet position Letter in key Decrypted letter A 0 W W t 19 o h t 19 o h a 0 t t c 2 w y k 10 o y N 13 O B o 14 t h w 22 w s ! ! Following this table, Attack Now! becomes Whhtyy Bhs!. To decode this message for the homework, do the reverse of this process! Sample Output The following test cases do not cover all possible scenarios (develop your own!) but should indicate if your code is on the right track. To guarantee full credit, your program’s output should exactly match the output below. Test Case 1: Enter message to decrypt: Whhtyy Bhs! Enter secret key: woot Updated key: Wootwo Otw! Decrypted msg: Attack Now! COP2271 MATLAB HW9 Test Case 2: Enter message to decrypt: Rr pathf! Enter secret key: edna Updated key: Ed naedn! Decrypted msg: No capes! Test Case 3: Enter message to decrypt: Qmh frisll kr pfbapgehleu! Enter secret key: syndrome Updated key: Syn dromes yn dromesyndro! Decrypted msg: You caught me monologuing! Test Case 4: Enter message to decrypt: Kbsm urm lhrrfdr uzwcxb! Enter secret key: rusty Updated key: Rust yru styrust yrusty! Decrypted msg: That was totally wicked! Test Case 5: Enter message to decrypt: Hbgzy’k xs ucjwc mwqn? Enter secret key: lucius Updated key: Luciu’s lu ciusl uciu? Decrypted msg: Where’s my super suit?

Solutions

Expert Solution

PYTHON code given below :-

LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
letters = 'abcdefghijklmnopqrstuvwxyz'
ciphertext = str(input("Enter message to decrypt:")) # get ciphertext from user
key = str(input("Enter secret key:")) # get secret key from user
Updated_key=""
result = ""
count=0
for i in ciphertext: #in each character in ciphertext do
if i.isupper()==True and i != ' ': # when character is Capital letter in ciphertext and not space then
Updated_key +=key[count].upper()
j = (LETTERS.index(i) -(ord(key[count].upper())-65)) % 26 # decrytion
count=count+1
result += LETTERS[j]
elif i.islower()==True and i!=' ': # when character is small letter in ciphertext and not space then
Updated_key +=key[count].lower()
j = (letters.index(i) -(ord(key[count].lower())-97)) % 26 # decrytion
count=count+1
result += letters[j]
if count ==len(key): # to made Updated key length and ciphertext length same
count=0   
if(i.isalpha()!=True) and i!=' ' : # if ciphertext contain any symbols then
Updated_key += i # add symbol to Updated key
result += i # add symbol to decrypted message
if i == ' ': # if ciphertext has a space then
Updated_key += ' '
result += ' '
print ("Updated key:",Updated_key,"\nDecrypted msg :",result) # print Updated key and decrypted message


Related Solutions

!) Vigenere cipher Encode the text manybooksoninformationsecurity using the Vigenere cipher with the keyword fun
!) Vigenere cipher Encode the text manybooksoninformationsecurity using the Vigenere cipher with the keyword fun
In C++, write a program to implement the Caesar Cipher for both encryption and decryption. The...
In C++, write a program to implement the Caesar Cipher for both encryption and decryption. The program should be able to handle different keys by deciding the key at run time. Thank you :)
(a) Use Vigenere cipher to encrypt the message “United States Constitution” using the keyword      “covid” Given...
(a) Use Vigenere cipher to encrypt the message “United States Constitution” using the keyword      “covid” Given that the Vigenere cipher of part (a) with the same keyword was used to produce the ciphertext: VFPUSVSNBVRCNQW Find the plaintext message.        
You are writing a program that encrypts or decrypts messages using a simple substitution cipher. Your...
You are writing a program that encrypts or decrypts messages using a simple substitution cipher. Your program will use two constant strings. One will represent the code for encryption: going from the original message (called the plaintext) to the encrypted version of the message. The other will be “abcdefghijklmnopqrstuvwxyz” (the lowercase alphabet. Your program will ask the user whether they want to 1) encrypt a message, 2) decrypt a message, or 3) quit. If they choose encrypt or decrypt, you...
Matlab Implement Fading Channel Simulation: Jakes Model with using Matlab
Matlab Implement Fading Channel Simulation: Jakes Model with using Matlab
USING MATLAB Part 2: Insert coins For this part, you are going implement the code that...
USING MATLAB Part 2: Insert coins For this part, you are going implement the code that asks the user to enter coins until they have entered enough for the NAU power juice. Open the insert_coins.m file. Initialize total to 0. We do this because initially, no coins have been entered. Using a loop, ask the user to enter a coin until the total matches or exceeds 115 cents. The input should be a char or string, so make sure that...
           Homework: Polynomial Using Array Description: Implement a polynomial class (1) Name your class...
           Homework: Polynomial Using Array Description: Implement a polynomial class (1) Name your class Polynomial (2) Use array of doubles to store the coefficients so that the coefficient for x^k is stored in the location [k] of the array. (3) define the following methods: a. public Polynomial()    POSTCONDITION: Creates a polynomial represents 0 b. public Polynomial(double a0)    POSTCONDITION: Creates a polynomial has a single x^0 term with coefficient a0 c. public Polynomial(Polynomial p)    POSTCONDITION: Creates...
Implement the Lorenz-63 model in MATLAB, and solve numerically (using MATLAB’s ode45 or other built-in solver)...
Implement the Lorenz-63 model in MATLAB, and solve numerically (using MATLAB’s ode45 or other built-in solver) for any random, non-zero initial conditions to reproduce, qualitatively, Figures 3 and 4. Note that, as usual, you should label your axes and make the plots as “pretty” as possible. The model equations are dx/ dt = σ(y − x), dy /dt= x(ρ−z)−y, dz/dt = xy − βz. Use parameter values σ = 10, ρ = 28, and β = 8/3.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT