[Encrypting/Decrypting Files - 12 marks] Encryption and Decryption are two crypt
ID: 3531329 • Letter: #
Question
[Encrypting/Decrypting Files - 12 marks] Encryption and Decryption are two cryptographic techniques. Encryption is used to transform text to meaningless characters, and decryption is used to transform meaningless characters into meaningful text. The algorithm that does the encryption is called a cipher. A simple encryption algorithm is Caesar cipher, which works as follows: replace each clear text letter by a letter chosen to be n places later in the alphabet. The number of places, n, is called the cipher key. For example, if the cipher key is 3, the clear text "HELLO THERE" becomes "KHOOR WKHUH". Here, we restrict ourselves to encrypting/decrypting uppercase alphabetic character. As you know from the ASCII table, the set of characters 'A' to 'Z' correspond to the integers 65 to 90. Hint: The following formula can be used to encrypt a character C using the Caesar cipher algorithm: E = (C - 'A' + k) % 26 + 'A' [where k is the cipher key] Write a C++ program for encrypting and decrypting files. Since this program performs two different functionalities (encryption and decryption), prompt the user to select the type of cryptographic technique as shown below: Welcome to ENGR1200U Cryptographic Techniques Program Please enter your selection: Encrypt Decrypt When the user selects 1 or 2, s/she will be asked to specify the input and output files. NOTE: you must use the file "hello.txt" to test your encryption/decryption program. The file can be downloaded from Blackboard (Content rightarrow Assignments rightarrow Assignment 3). Here is an example: Assume we have the file "hello.txt" with the following content: HELLO THERE HOW ARE YOU DOING? BYE BYE;=FOR NOW OK; BYE! If the user selects to encrypt the file (i.e. option 1), then the program will encrypt the original text in "hello.txt" and outputs the encrypted text to a new file (i.e. "hello.out"). The encrypted file contains the encrypted text that looks as follows: MJQQT YMJWJ MTB FWJ DTZ ITNSL? GDJ GDJ; =KTW STB TP; GDJ! If the user selects to decrypt the file (i.e. option 2), then the program will decrypt the encrypted text (i.e. in "hello.out") and outputs the decrypted text to a new file (i.e. "new_hello.text"). The program should give the user the option whether to continue with encrypting/decrypting files (i.e. entering letter 'C') or exit the program (i.e. entering the letter 'E').Explanation / Answer
To perform the write operation with in a file.
ALGORITHM:
STEP 1: Start the program.
STEP 2: Declare the variables.
STEP 3: Read the file name.
STEP 4: open the file to write the contents.
STEP 5: writing the file contents up to reach a particular condition.
STEP 6: Stop the program.
PROGRAM:
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<fstream.h>
void main()
{
char c,fname[10];
ofstream out;
cout<<"Enter File name:";
cin>>fname;
out.open(fname);
cout<<"Enter contents to store in file (Enter # at end): ";
while((c=getchar())!='#')
{
out<<c;
}
out.close();
getch();
}
Output:
Enter File name: one.txt
Enter contents to store in file (enter # at end)
Master of Computer Applications#
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.