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...
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 :)
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.
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...
An encryption-decryption system consists of three elements: encode, transmit, and decode. A faulty encode occurs in...
An encryption-decryption system consists of three elements: encode, transmit, and decode. A faulty encode occurs in 0.7% of the messages processed, transmission errors occur in 1% of the messages, and a decode error occurs in 0.1% of the messages. Assume the errors are independent. Round your answers to four decimal places (e.g. 98.7654). (a) What is the probability of a completely defect-free message? (b) What is the probability of a message that has either an encode or a decode error?
The prompt is using Python:  Write a 3 rail transposition encryption algorithm, and a corresponding decryption algorithm....
The prompt is using Python:  Write a 3 rail transposition encryption algorithm, and a corresponding decryption algorithm. Implement these two algorithms in their own function. Now write a testing function that demonstrates your algorithms work for all interesting cases!
Given two prime numbers 17 and 19. Compute the encryption and the decryption keys using RSA...
Given two prime numbers 17 and 19. Compute the encryption and the decryption keys using RSA algorithm.
(Elgamal encryption): given elgamal encryption ciphersystem: a)show how can we create a new legal encryption from...
(Elgamal encryption): given elgamal encryption ciphersystem: a)show how can we create a new legal encryption from two different encryptions that we don't know their decryptions b)how can an adversary take advantage of the scheme at a) (what's written above), in order to attack a preknown encrypted text? elaborate
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT