Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment 1 A Caesar cipher is a simple substitution cipher based on the idea of shifting each letter of the plaintext message a fixed number

image text in transcribed
Assignment 1 A Caesar cipher is a simple substitution cipher based on the idea of shifting each letter of the plaintext message a fixed number (called the key) of positions in the alphabet. For example, if the key value is 2, the word "sourpuss would be encoded as "uqwtrwuu" The original message can be recovered by "reencoding" it using the negative of the key. Write a program that can encode and decode Caesar ciphers. If encoding, the input to the program will be a string of plaintext and the value of the key. If decoding, the iput to the program will be encoded text and the key value wl be the negative of the original key. Here are some sample runs of the program: Please enter a string: sourpuss Please enter a key: 2 The encrypted string is: uqutrvuu Please enter a string: uqutrvuu Please enter a key -2 The decrypted string is: sourpuss Please enter a string: zany Please enter a number: 6 The encrypted string is: fgte Here are some hints and notes: You can assume that all the letters used are lower case. if ch is a character in the string and key is the amount to shift, then the character that replaces ch can be caleulated as: chr (ord (chkey). One additional case to worry about is when we "drop off the end" of the alphabet. A true Caesar cipher does the shifting in a circular fashion where the next character after "z" is "a." You can make your solution circular by doing some arithmetic and using the modulus operator %. For the output, you want your message to start with The encrypted string is: "if the key is positive and with The decrypted string is: if the key is negative. One way to this is to use the following snippet: s "The encrypted string is if key>0 else "The decrypted string is

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

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

2nd Edition

0470624701, 978-0470624708

More Books

Students also viewed these Databases questions

Question

What is the focus of behavioral queueing theory?

Answered: 1 week ago