5.15 LAB: 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 upper case due to the uppercase letters in the alphabet list. Convert the original message to 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 my code so far:   #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 def caesar_hack(text, a, check):     for i in range(26):         decrypted_text = caesar_cipher_decrypt(text, i, a)         if decrypted_text.lower() == check.lower():             return i, decrypted_text         return 99, 'Error: Key not found!'    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)      k, h = caesar_hack(encrypted_data, alphabet, text)      if k == 99:       print(h)   else:         print('Successful Attempt found! Key = '+str(k))         print('Secret message: '+str(h))   I get a 2/10 see errors attached.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

5.15 LAB: 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 upper case due to the uppercase letters in the alphabet list. Convert the original message to 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

my code so far:
 

#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

def caesar_hack(text, a, check):
    for i in range(26):
        decrypted_text = caesar_cipher_decrypt(text, i, a)
        if decrypted_text.lower() == check.lower():
            return i, decrypted_text
        return 99, 'Error: Key not found!'
  
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)
  
  k, h = caesar_hack(encrypted_data, alphabet, text)
  
  if k == 99:
      print(h)
  else:
        print('Successful Attempt found! Key = '+str(k))
        print('Secret message: '+str(h))

 

I get a 2/10 see errors attached.

 
2:Compare output
Output differs. See highlights below. Special character legend
Input
Your output
Expected output
21
Brute Force Hack Attempt:
Encrypted Message: OCDN DN V NZXMZO HZNNVBZ
Error: Key not found!
Brute Force Hack Attempt:
Encrypted Message: OCDN DN V NZXMZO HZNNVBZ
Successful Attempt found! Key = 21
Secret message: THIS IS A SECRET MESSAGE
0/2
Transcribed Image Text:2:Compare output Output differs. See highlights below. Special character legend Input Your output Expected output 21 Brute Force Hack Attempt: Encrypted Message: OCDN DN V NZXMZO HZNNVBZ Error: Key not found! Brute Force Hack Attempt: Encrypted Message: OCDN DN V NZXMZO HZNNVBZ Successful Attempt found! Key = 21 Secret message: THIS IS A SECRET MESSAGE 0/2
Latest submission - 5:29 PM EST on 11/17/22
Only show failing tests
1:Compare output
Output differs. See highlights below. Special character legend
Input
Your output
Expected output
Brute Force Hack Attempt:
Encrypted Message: XLMW MW E WIGVIX QIWWEKI
Error: Key not found!
Brute Force Hack Attempt:
Encrypted Message: XLMW MW E WIGVIX QIWWEKI
Successful Attempt found! Key = 4
Secret message: THIS IS A SECRET MESSAGE
Total score: 2/10
Download this submission
0/1
Transcribed Image Text:Latest submission - 5:29 PM EST on 11/17/22 Only show failing tests 1:Compare output Output differs. See highlights below. Special character legend Input Your output Expected output Brute Force Hack Attempt: Encrypted Message: XLMW MW E WIGVIX QIWWEKI Error: Key not found! Brute Force Hack Attempt: Encrypted Message: XLMW MW E WIGVIX QIWWEKI Successful Attempt found! Key = 4 Secret message: THIS IS A SECRET MESSAGE Total score: 2/10 Download this submission 0/1
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Fundamentals of Multithreaded Algorithms
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education