Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

text file (cyphertext). Conversely, if the keyword is DECRYPT, the first file is

ID: 3750803 • Letter: T

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 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 ‘ ’, ‘ ’ (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 ‘ ’, 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==‘ ’) 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 = ‘ ’;
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==‘ ’) 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 = ‘ ’;
else if (c1 == 1) c=‘ ’;
else c = c1 + 30;
Detailed requirements:

Explanation / Answer

Program for Random Number Seeder.

#include<stdio.h>

#include<stdlib.h>

#include<time.h>

void main()

{

int l;

printf("Enter A limit of outputs:");

// Instead of giving some inputs the user is able to chooe

scanf("%d",&l);

for(int i=0;i<l;i++)

{ printf("%d",rand()); } //This Loop could give same sequence of random numbers on every run.

srand(time(0));

for(int i=0;i<l;i++)

{ printf("%d",rand()); } //This loop is able to print different sequce of ranodm numbers on eachand evey run.

}

The above program is Random generator program which take an input from user and give correspoding output in both different cases.