Answer to Question #277613 in Python for AYUSH PATIL

Question #277613

python program to decrypt the ciphertext into plain text. This scheme of cipher uses a text string (say, a word) as a key, which is then used for doing a number of shifts on the plaintext. For example, let’s assume the key is ‘point’. Each alphabet of the key is converted to its respective numeric value: In this case

p→16,o→15,i→9, n→14, and t→20.

Thus, the key is: 16 15 9 14 20

The sender and the receiver decide on a key. Say ‘point’ is the key. Numeric representation of this key is [16, 15, 9, 14, 20]

The sender wants to decrypt the message, say ‘pHBNVI’.arrange cipher test and numeric key to get the plain text as "Attack" (Toggle Case of each letter)

p H B N V I

p-16 o-14 i-9 n-14 t-20 p-16

a t t a c k

now left shifts each ciphertext by alphabet by the number written below it to create plain text as shown below

Input format

pHBNVZ

point

Output Format

[16, 15, 9, 14, 20, 16]

Attack


1
Expert's answer
2021-12-10T00:36:52-0500
from string import ascii_lowercase as ALPHABET


def shift(message, offset):
    trans = str.maketrans(ALPHABET, ALPHABET[offset:] + ALPHABET[:offset])
    return message.lower().translate(trans)


def decrypt(cipher):
    key = "point"
    numbers = []
    for letter in key:
        number = ord(letter) - 96
        numbers.append(number)

    print(numbers)

    x = shift(cipher, -1)
    return x


cipher = "pHBNVI"

print(decrypt(cipher))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS