Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hacking Ciphers The Caesar Cipher Algorithm was introduced in Week #1. Encryption is the act of encoding a message with the intent of allowing only

Hacking Ciphers

The Caesar Cipher Algorithm was introduced in Week #1. Encryption is the act of encoding a message with the intent of allowing only authorized people the knowledge of how to read that message. An encrypted message can be decoded, allowing the secured content to be read after decryption.

Recall that the Caesar Cipher uses alphabets as the primary source of information but shifted a certain number of letters to the left or right as a key to create the encrypted data. The Caesar Cipher is easily hacked because of the simple technique used to build the key that encrypts and decrypts the data.

In this lab, the key is the number of alphabets shifted, and the direction is always toward the increasing alphabetical order. This provides 26 ways of encrypting a message and therefore makes it easier to be hacked by guessing the key within the range of 0 - 25.

Write the function caesar_hack( ) that takes three parameters: a Caesar Cipher encrypted message, an alphabet list, and the original message. Function caesar_hack( ) uses a Brute Force Attack to find the key that decrypts the encrypted message correctly. This would typically be a technique used by an unauthorized user.

Use a nested for loop in the function caesar_hack( ) to try all the possible keys. For each key, check the encrypted letter position based on the alphabet letter and attempt to decrypt the message. If the decrypted message is the same as the original message, return the key value and the decrypted message. If a key is not found, return 99 as the key and "Error: Key not found!" as the message. Note: The decrypted message is always in the upper case due to the uppercase letters in the alphabet list. Convert the original message to the upper case before being compared.

In main: Add a call to the caesar_hack() function. Make sure you capture both of your returned variables. Then add control structures that output the returned error message if the returned key is 99, or output "Successful attempt found! Key = the returned key" followed by "Secret message: the returned message" in a new line.

Ex: If the input is:

4 

then the output is:

Brute Force Hack Attempt: Encrypted Message: XLMW MW E WIGVIX QIWWEKI Successful Attempt found! Key = 4 Secret message: THIS IS A SECRET MESSAGE 

Ex: If the input is:

22 

then the output is:

Brute Force Hack Attempt: Encrypted Message: PDEO EO W OAYNAP IAOOWCA Successful Attempt found! Key = 22 Secret message: THIS IS A SECRET MESSAGE

Existing Code

#Caesar Cipher Encryption function def caesar_cipher_encrypt(text, key, a): text = text.upper() encrypted_Text = "" for i in text: if i in a: index = (a.find(i) + key) % len(a) encrypted_Text = encrypted_Text + a[index] else: encrypted_Text = encrypted_Text + i return encrypted_Text

#Caesar Cipher Decrypt function def caesar_cipher_decrypt(text, key, a): text = text.upper() decrypted_Text = "" for i in text: if i in a: index = (a.find(i) - key) % len(a) decrypted_Text = decrypted_Text + a[index] else: decrypted_Text = decrypted_Text + i return decrypted_Text

# TODO Create a function called caesar_hack( text, a, check ) that takes a Caesar Cipher encrypted message, an alphabet list, and the original message in main. # This function will attempt to hack an encrypted message. Use a nested for loop to find the key between 0 & 25. # Check where the letter is found in the alphabet list based on the encrypted text letter sent to this function. # Check if the decrypted message is the same as the original message. # If a key is found, return the key value and the decrypted message. # If not found return 99 as the key and "Error: Key not found!" as the message.

def caesar_hack(text, a, check):

if __name__ == "__main__": alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" text = "This is a secret message" shift = int(input()) #Number between 1 & 25 encrypted_data = caesar_cipher_encrypt(text, shift, alphabet) print('Brute Force Hack Attempt: ') print ('Encrypted Message: ', encrypted_data) # TODO: Add a call to caesar_hack (encrypted_data, alphabet, text) return it to two variables k (key) & h (hacked message) # TODO: If k == 99 print the returned message # Else - print 'Successful Attempt found! Key =' k variable # Add a print 'Secret message:' h variable

Please show indentations and provide a brief explanation as to how the code works. Thank you!

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 10g SQL

Authors: Joan Casteel, Lannes Morris Murphy

1st Edition

141883629X, 9781418836290

More Books

Students also viewed these Databases questions

Question

=+ Will it stimulate consumption, as the traditional view holds?

Answered: 1 week ago

Question

=+how will the policy affect the economy?

Answered: 1 week ago