Question

In: Computer Science

We like to apply text encryption and decryption as follows. In text encryption, for each letter...

We like to apply text encryption and decryption as follows. In text encryption, for each letter and numeric character in the plaintext (i.e., a-z, A-Z and 0-9), it is “shifted” a certain number of places down the alphabet or numbers. For example, assuming a shifted key offset of 3 is used, ‘A’ would be substituted by ‘D’, ‘B’ would become ‘E’, and so on. Similarly, ‘0’ would become ‘3’ and so on. Note that wrap-around will be applied at the end of the alphabet or number. The decryption process works in similar approach but in a reverse order.

Encrypt the text with key offset of 15. Display the encrypted text and save the output as “encrypted_text.txt”.

(Language: PySpark Python)

Solutions

Expert Solution

def encryption(_plaintext, _offset):
    answer = ""

    # Exploring each character and apply shift accordingly
    for i in range(len(_plaintext)):
        char = _plaintext[i]

        # for uppercase
        if char.isupper():
            answer += chr((ord(char) + _offset - 65) % 26 + 65)

        # for lowercase
        elif char.islower():
            answer += chr((ord(char) + _offset - 97) % 26 + 97)

        # for numeric
        elif char.isnumeric():
            answer += str((int(char) + _offset) % 10)

    return answer


plaintext = input("Enter Plain Text: ")

offset = 15

result = encryption(plaintext, offset)

#uncomment to see result in console
'''
print("Plain Text : " + plaintext)
print("Shift pattern : " + str(offset))
print("Cipher Text: " + result)
'''

# write result to file
f = open("encrypted_text.txt", "w")
f.write(result)
f.close()

#uncomment to open and read the file
"""
f = open("encrypted_text.txt", "r")
print(f.read())
""""

Related Solutions

My question below Write a complete program that performs encryption/decryption of a text file. Encryption means...
My question below Write a complete program that performs encryption/decryption of a text file. Encryption means you need to scramble the words of a file to become secure. Decryption means you need to apply some rules to an encrypted file in order to find the original file with its original content. An example of encryption is to replace each letter in a file with its consecutive letter in the alphabet. Therefore, ‘a’ is replaced by ‘b’, ‘b’ is replaced by...
Show that AES decryption is, in fact, the inverse of AES encryption
Show that AES decryption is, in fact, the inverse of AES encryption
write a C program which performs encryption and decryption of a message
write a C program which performs encryption and decryption of a message
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...
Write a program in c++ that can perform encryption/decryption. In the following let the alphabet A...
Write a program in c++ that can perform encryption/decryption. In the following let the alphabet A be A={A, a, B, b, . . ., “ ”, “.”,“’ ”}. The encoding is A→0, a→1, B→2, b→4, . . ., Z→50, z→51, “ ”→52, “.”→53 and “’”→54.
Write a program in java that can perform encryption/decryption. In the following let the alphabet A...
Write a program in java that can perform encryption/decryption. In the following let the alphabet A be A={A, a, B, b, . . ., “ ”, “.”,“’ ”}. The encoding is A→0, a→1, B→2, b→4, . . ., Z→50, z→51, “ ”→52, “.”→53 and “’”→54.
Your task is to write a C program which performs encryption and decryption of a message...
Your task is to write a C program which performs encryption and decryption of a message using the substitution cipher algorithm. Write a C program which performs encryption and decryption using the substitution cipher algorithm. Your program must be fully automated (ie: it does not take any interactive user input) and either encrypt or decrypt depending on the files which exist in the program’s directory. If message.txt exists your program should read that file, encrypt the contents, and write the...
In the caeser cipher encryption and decryption program below, what do the two lines if(ch >...
In the caeser cipher encryption and decryption program below, what do the two lines if(ch > 'z'){ ch = ch - 'z' + 'a' - 1; } if(ch < 'a'){ ch = ch + 'z' - 'a' + 1; } mean??? I understand that it has something to do with ASCII characters and makes sure that if the encryption/decryption character is more than "z", then it would loop back to "a" instead of outputting a charcter like "{" . I...
Alice is sending message “HIDE” to Bob. Perform encryption and decryption using RSA algorithm, with the...
Alice is sending message “HIDE” to Bob. Perform encryption and decryption using RSA algorithm, with the following information: parameters p=11,q=5, e=7 Present all the information that you will need to encrypt and decrypt only the first letter from text
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT