Question

In: Computer Science

A Caesar cipher encrypts a message by shifting letters in the alphabet. For example, a shift...

A Caesar cipher encrypts a message by shifting letters in the alphabet. For example, a

shift of 4 maps 'a' to 'e' and maps 'p' to 't' Here is a famous line from Shakespeare

encrypted with a shift of 4: 'vq dg qt pqv vq dg: vjcv ku vjg swguvkqp.'

(a) Write a program that takes as input a string to be encrypted and an integer encrpytion

shift (such as 4 mentioned earlier), and prints the encrypted string. [Hint: zip()

is helpful in building a dictionary. Also, remember to handle space–it doesn’t shift].

(b) Extend your program to take an additional input that indicates if your program is

to encrypt or decrypt the string.

Please write a python program

Solutions

Expert Solution

PLEASE GIVE IT A THUMBS UP, I SERIOUSLY NEED ONE, IF YOU NEED ANY MODIFICATION THEN LET ME KNOW, I WILL DO IT FOR YOU

import string


def cesar_cipher(msg, n, decrypt=False):
    if decrypt:
        n = -n
    shifted = string.ascii_lowercase[n:] + string.ascii_lowercase[:n]
    char_map = dict(zip(string.ascii_lowercase, shifted))
    return ''.join((char_map[c] if c in char_map else c) for c in msg.lower())


if __name__ == '__main__':
    msg = 'To be or not to be: that is the question.'
    e = cesar_cipher(msg, 2)
    d = cesar_cipher(e, 2, True)
    print(e)
    print(d)

Related Solutions

1 Introduction A cipher is an algorithm which encrypts a message into cipher text so that...
1 Introduction A cipher is an algorithm which encrypts a message into cipher text so that it can be safely transmitted without an eavesdropper being able to (easily) read it. For the purposes of this assignment the message and ciphertext will be stored as strings of ASCII characters. Cipher algorithms always perform two tasks: encryption and decryption. The encryption process takes a “message” and “key” as inputs and produces cipher text. The decryption process performs the reverse: it turns cipher...
In cryptography, a Caesar cipher, also known as Caesar's cipher, the shift cipher, Caesar's code or...
In cryptography, a Caesar cipher, also known as Caesar's cipher, the shift cipher, Caesar's code or Caesar shift, is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. Given an arbitrary cipher text file, you need to write a C++ program to find out the value of the shift going down the...
One can encrypt numbers as strings of letters by applying a substitution cipher. For example, the...
One can encrypt numbers as strings of letters by applying a substitution cipher. For example, the substitution 0 <-> F, 1 <-> G, 2 <-> D, 3 <-> Z, would encrypt the number 30231 as the string of letters ZFDZG. Decipher the following encrypted equation involving three numbers: AB + BC + ACA = BCB. (You may need to use the fact that our usual numbers are represented in base 10, for example, the number 838 is represented with digits...
Create a Columnar Transposition Cipher in Python that encrypts/decrypts the word "Crypt".
Create a Columnar Transposition Cipher in Python that encrypts/decrypts the word "Crypt".
In C++, write a program to implement the Caesar Cipher for both encryption and decryption. The...
In C++, write a program to implement the Caesar Cipher for both encryption and decryption. The program should be able to handle different keys by deciding the key at run time. Thank you :)
The mathematical expression of the encryption and decryption process of a Caesar cipher algorithm is expressed...
The mathematical expression of the encryption and decryption process of a Caesar cipher algorithm is expressed respectively as: c=Ep, k=p+k%26                                                                                                                         (1) p=Dc,k=c-k%26                                                                                                                         (2) Please do the following: Write at least two paragraphs to explain the principle of operation of the algorithm. For a full credit, your explanation must show the architectural diagram of the encryption and decryption process. Write a program to implement the Caesar algorithm Code must have two functions; encryption and decryption Test your codes with p as...
In the game of ScrabbleTM, the letters of the English alphabet are inscribed on tiles
In the game of ScrabbleTM, the letters of the English alphabet are inscribed on tiles and a prescribed number of tiles are provided for each letter. Consider an ensemble of ScrabbleTM tiles with a probability distribution defined by the frequency of tiles in the box. Explain how to calculate the information entropy of this ensemble. It is not necessary to actually Compute the entropy, but you can if you wish.    
You are writing a program that encrypts or decrypts messages using a simple substitution cipher. Your...
You are writing a program that encrypts or decrypts messages using a simple substitution cipher. Your program will use two constant strings. One will represent the code for encryption: going from the original message (called the plaintext) to the encrypted version of the message. The other will be “abcdefghijklmnopqrstuvwxyz” (the lowercase alphabet. Your program will ask the user whether they want to 1) encrypt a message, 2) decrypt a message, or 3) quit. If they choose encrypt or decrypt, you...
Suppose you want to form words with 3 letters and all letters in the alphabet can...
Suppose you want to form words with 3 letters and all letters in the alphabet can be used except A and B (so, XYZ would be a word for example even though it does not make sense). a) How many possibilities do you have if repetition is permitted and ordering is relevant, how many possibilities do you have if repetition is not permitted and ordering is relevant; how many possibilities do you have if repetition is not permitted and ordering...
research the Caesar Cipher, and document your research in 2-3 pages in a Word document with...
research the Caesar Cipher, and document your research in 2-3 pages in a Word document with illustrations in your document and provide an example of how the Caesar Cipher works while encrypting and decrypting a sample message. Also, add its history and its internal workings. Summary of the areas to complete: - Research the Caesar Cipher. - Show its Encryption Method in details. - Show its Decryption Method in details. - Describe its History and what it was used for....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT