Write a cryptographic program that works similarly to my crypto program: • Pro
ID: 3536129 • Letter: W
Question
Write a cryptographic program that works similarly to my crypto program:
• Prompt the user to enter a secret key and use it to compute the seed of a random
number generator
• Prompt the user to give the names of an input file and the output coded/decoded
file
• Create the sequence of random bytes from a random number generator with the
seed obtained from user’s secret key.
• Perform the coding of bit x using a random bit r as follows: x⊕ = r
• Since ∀r ∈{0,1}, r ⊕r = 0, perform decoding using the same sequence of
random bytes and the same operation x⊕ = r . Decoding is based on the
operation x⊕r ⊕r = x⊕(r ⊕r) = x⊕0 = x
Explanation / Answer
#include<iostream> #include<conio.h> #include<math.h> #include<stdlib.h> #include<fstream> using namespace std; int main() { char n, line[1024], keystring[100]; char FitoEncr[100], NewFiCrypt[100]; char FiletobeDecrypted[100]; ifstream IS ("FitoEncr.txt", ios::in); ofstream OS ("NewFiCrypt.txt", ios::out); unsigned int psswd=0, number; cout<<"Please, enter a secret key :"; cin.getline(keystring, 100); for( int i=0;keystring[i]!=''; i++) psswd=(psswd+3)*keystring[i]; cout<<"initial password: "<<keystring<<endl; cout<<"encrypted password: "<<psswd<<endl; cout<<"please, enter the name of the input file: "; cin.getline(FitoEncr,20); cout<<"please, enter the name of the output file: "; cin.getline(NewFiCrypt,20); srand(psswd); //not sure about creating the sequence of random bytes from a... number=rand() % 255; //random number generator with the seed obtained from user's secret key //ENCRYPTION while(IS.get(n)) { if(IS.get(n)) { n^=rand(); OS<<n; cout<<"character coded:"<<n; } } IS.close(); OS.close(); //DECRYPTION ifstream IS1; ofstream OS1; IS1.open("NewFiCrypt.txt", ios::in); OS1.open("FilDecr.txt", ios::out); while(IS1.get(n)) { if(IS1.get(n)) { n^=rand(); //I think the problem starts on this line... OS1<<n; cout<<"character coded:"<<n; } } IS1.close(); OS1.close(); getch(); return 0; }Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.