Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C program to encrypt and decrypt text files. Your program (encrypt decrypt) will take four arguments: a key (key), mode keyword (EN- CRYPT/DECRYPT),

Write a C program to encrypt and decrypt text files. Your program (encrypt decrypt) will take four arguments: a key (key), mode keyword (EN- CRYPT/DECRYPT), and two text files, an and . If the keyword is ENCRYPT the program should read the first text file (plaintext) and produce an encrypted 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).You should use strcmp function to determine the mode string value. To use it you will need to include string.h in your program.

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 encryp- tion 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.

From Wikipedia: In cryptography, the one-time pad (OTP) is an encryption technique that cannot be cracked if used correctly. In this technique, a plaintext is paired with a random secret key (also referred to as a one-time pad). Then, each bit or character of the plaintext is encrypted by combining it with the corresponding bit or character from the pad using modular addition. If the key is truly random, is at least as long as the plaintext, is never reused in whole or in part, and is kept completely secret, then the resulting cyphertext will be impossible to decrypt or break.

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+97r 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;

- seed the random number generator using srandom(key), where key ={6 digit}.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts International Edition

Authors: David M. Kroenke

6th Edition International Edition

0133098222, 978-0133098228

More Books

Students also viewed these Databases questions

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago