Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write the code in python that implements the Caesar Encryption algorithm according to the following specs: 1. The algorithm is implemented in a class called

Write the code in python that implements the Caesar Encryption algorithm according to the following specs: 1. The algorithm is implemented in a class called CaesarEncriptor 2. This class has two methods: a. Constructor: takes the shift value b. encode: a method that takes a text message and returns an encrypted message c. decode: a method that takes an encrypted message and returns a readable message. d. set_shift: a method that takes a shift value e. create_shift_substitutions: this is a private method that returns a tuple of 2 dictionaries (one for encryption and other for decryption)

3. The encoding handles both UPPER and lower case letter sets.

A sample of test code that your code should be able to run is: caesar = CaesarEncryptor(4) enc_msg = caesar.encode(Lets meet!) print( enc_msg) # send this message to your friend to decrypt # -- supposed you received a message from your friend, write the code that tries to crack it here?

*NOTE:* modify the code below to satisfy the requirements.

import string

def encode(message, subst): cipher = "" for letter in message: if letter in subst: cipher += subst[letter] else: cipher += letter return cipher

# Begin auto test

def create_shift_substitutions(n): encoding = {} decoding = {} alphabet_size = len(string.ascii_uppercase) for i in range(alphabet_size): letter = string.ascii_uppercase[i] subst_letter = string.ascii_uppercase[(i+n)%alphabet_size]

encoding[letter] = subst_letter decoding[subst_letter] = letter return encoding, decoding

test_message = "TEST" subst, unsubst = create_shift_substitutions(10)

print( encode(test_message)

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

Graph Databases

Authors: Ian Robinson, Jim Webber, Emil Eifrem

1st Edition

1449356265, 978-1449356262

More Books

Students also viewed these Databases questions

Question

Describe new developments in the design of pay structures. page 475

Answered: 1 week ago