Question
text file (cyphertext). Conversely, if the keyword is DECRYPT, the first file is an encrypted file (cyphertext), and the output should be a decrypted text
text file (cyphertext). Conversely, if the keyword is DECRYPT, the first file is an encrypted file (cyphertext), and the output should be a decrypted text file (plaintext). From Wikipedia: In cryptography, encryption is the process of encoding messages or information in such a way that only authorized parties can read it. Encryption does not of itself prevent interception, but denies the message content to the interceptor. In an encryption scheme, the intended communication information or message, referred to as plaintext, is encrypted using an encryption algorithm, generating cyphertext that can only be read if decrypted. In your project you will simulate a technique called One-time Pad. Since it is not practical to use true one-time pads we will simulate them using a random number generator. Note that this technique is not necessarily very secure, but it will serve to illustrate the approach. In our case we are interested in characters \t, (numerical codes 9 and 10) and Space through (numerical codes 32 through 126). Therefore, there are 97 displayable characters (if we count white space characters as displayable). If you use 0 to represent \t, 1 to represent and 2 through 96 to represent ascii codes 32 through 126 a simple encryption and decryption methods can be designed. Seed a random number generator using the key. You should use srandom()/random() functions in your code. For each plaintext character p use the method below to generate a cyphertext character c: r = random() % 97; // change all displayable characters to range [0. . . 96] if (p==\t) p1 = 0; else if (p== ) p1 = 1; else p1 = p-30; c1 = (p1 + r) % 97 ; // modular addition // turn all output values into displayable characters if (c1==0) c = \t; else if (c1 == 1) c= ; else c = c1 + 30; To decrypt you need to replace p1 + r by p1 + 97 - r to obtain: r = random() % 97; // change all displayable characters to range [0. . . 96] if (p==\t) p1 = 0; else if (p== ) p1 = 1; else p1 = p-30; c1 = (p1 + 97 - r) % 97 ; // modular addition // turn all output values into displayable characters if (c1==0) c = \t; else if (c1 == 1) c= ; else c = c1 + 30; Detailed requirements:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started