I need some help asap because my assignment is due tomorrow. Please help me out.
Write a text‐based program that can encrypt or decrypt a text file
using the “unbreakable” One‐Time Pad cryptosystem. The program should read
a text file that contains only English characters (upper and lower case) and blank
spaces, and generate an encrypted or decrypted file following these rules:
(1) For encryption: For each character p in the unencrypted file, generate a
random number r between 1 and 53. The encrypted character C will be
computed by the formula C = p + r. To do this you will need to enccrypt
characters and blank spaces following exactly this mapping:
‘a’ ‘b’ … ‘z’ ‘A’ ‘B’ … ‘Z’ [blank space]
1 2 … 26 27 28 … 52 53
Example: if your random number r is equal to 7, the unencrypted
character ‘z’ will be encrypted to character C = ‘z’ + 7 = 33 = ‘H’. Note
that this formula should wrap around; for example, for r = 6 and p = ‘Y’, C
= ‘Y’ + 6 = 51 + 6 = 4 = ‘d’.
The generated sequence of random numbers r should be stored in a
separate file which is the secret key to decrypt the encrypted file.
Also, of course, you need to generate an encrypted file containing the
encrypted characters.
To run the program the user should type otp -e <unencrypted_file>
<output_file> <secret_file>, where unencrypted_file is the name of the file
you want to encrypt, output_file is the name of the file you want to give to
the encrypted file, and secret_file is the name of the file that will contain the
generated random numbers which are the key to decrypt output_file at a
later time.
(2) For decryption: For each character C in the encrypted file, read the
corresponding number r from the secret key file generated during
encryption, and compute the unencrypted character p using the formula
p = C – r.
Example: if your secret key number for a particular character C is r = 7,
the unencrypted character ‘H’ will be computed using the formula p = 33
– 7 = 26 = ‘z’. Note again that this formula should wrap around; for
example, for r = 6 and C = ‘d’, p = ‘d’ ‐ 6 = 4 ‐ 6 = 51 = ‘Y’.
To run the program the user should type otp -d <encrypted_file>
<output_file> <secret_file>, where encrypted_file is the name of the file
you want to decrypt, output_file is the name of the file you want to give to
the unencrypted file, and secret_file is the name of the file that contains the
generated random numbers which are the key to decrypt the output_file.