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

USE C++: Encryption and Decryption are two cryptographic techniques. Encryption is used to transform text to...
USE C++: Encryption and Decryption are two cryptographic techniques. Encryption is used to transform text to meaningless characters, and decryption is used to transform meaningless characters into meaningful text. The algorithm that does the encryption is called a cipher. A simple encryption algorithm is Caesar cipher, which works as follows: replace each clear text letter with a letter chosen to be n places later in the alphabet. The number of places, n, is called the cipher key. For example, if...
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...
Describe in detail the encryption and decryption process for Simplified DES by showing your results at...
Describe in detail the encryption and decryption process for Simplified DES by showing your results at each step Details of decryption process: input: 10 bit key = 1 1 1 1 1 1 1 1 1 1 and 8 bit plaintext = 0 0 0 0 0 0 0 0 Output from IP = Output from first Fk using K2 = Output from SW = Output from first Fk using K1 = Output from IP-1 =
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT