Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 2: Substitution Ciphers # Cant use chr and ord functions You must implement two substitution ciphers, the Atbash cipher and the Caesar cipher, where

Part 2: Substitution Ciphers # Cant use chr and ord functions You must implement two substitution ciphers, the Atbash cipher and the Caesar cipher, where the ciphertext is created by letter substitution. The process of how letters should be substituted for one another is detailed in each function description. (8 points) def atbash_cipher(plaintext): Parameter(s): plaintext ----- a string; the message to be encrypted Return value: A string; the ciphertext after applying the Atbash cipher algorithm Assumptions: o The standard English alphabet is used: "abcdefghijklmnopqrstuvwxyz" o All strings will be non-empty, entirely lowercase, and only contain valid letters in the alphabet. How it works: o Flip the alphabet backwards. o Substitute each letter in the plaintext message with its counterpart in the backwards alphabet. So, the letter "A" in the plaintext becomes "Z" in the ciphertext, the letter "B" becomes "Y," the letter "C" becomes "X," and so on. Notes: o There are no provided tests for this function, you must test it on your own! o Remember, you cannot use .index()!

Examples: o atbash_cipher("abcd") 'zyxw'

atbash_cipher("toocool") 'gllxllo'

atbash_cipher("thismessagewillexplode") 'gsrhnvhhztvdroovckolwv'

(8 points)

def caesar_cipher(plaintext, shift):

Parameter(s): plaintext ----- a string; the message to be encrypted shift ----- an integer; the number used to control the cipher Return value: A string; the ciphertext after applying the caesar cipher algorithm Assumptions: o The standard English alphabet is used: "abcdefghijklmnopqrstuvwxyz" o All strings will be non-empty, entirely lowercase, and only contain valid letters in the alphabet. o shift will be an integer value (could be negative, positive, or zero!) How it works: o The substitution is performed for each character in the plaintext message based on the shift value that is provided to the function o Each letter in the plaintext has a numbered position in the alphabet, add the shift to that position to go to a new letter in the alphabet. o If this addition is larger than the length of the alphabet, loop around to the beginning of the alphabet. If the result of this addition is less than zero, loop around to the end of the alphabet. o Substitute the letter in the plaintext with this new letter. Notes: Same restrictions as everything else.

Examples:

caesar_cipher("quickbrownfox", 5) 'vznhpgwtbsktc'

caesar_cipher("wehavefled", -6) 'qybupyzfyx'

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

Students also viewed these Databases questions

Question

f. Did they change their names? For what reasons?

Answered: 1 week ago