I tried this out and I\'m so confused I can\'t figure out the rest of the code a
ID: 3592089 • Letter: I
Question
I tried this out and I'm so confused I can't figure out the rest of the code after Initialize encrypted message string to an empty string
Decrypt: Clear screen Get cipher key (assume user enters integer when prompted for key request) Check that value entered is between 0 and 127 inclusive Convert cipher key to binary string and strip off "Ob" . *Check for 7-character length (pad beginning with zeros if necessary) . Get message to be encrypted from file Initialize decrypted message string to an empty string Perform XOR operation on each character of cipher key and message . o o o Initialize decrypted_bin_char string to an empty string Slice out each successive 7-bit portion of encrypted message Perform XOR operation and append binary result to decrypted string Convert each binary bit of message character and key to an integer Perform XOR operation on these two bits Convert literal True and False to binary bit & append to output - - Append "Ob" of decrypted _bin_ char and get ASCIl integer value o Convert ASCIl integer value to character o Append character to decrypted message string o Clear screen Print decrypted message to standard output Pause screen clearing . The final option allows the user to exit from the application.Explanation / Answer
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
int main()
{
system("CLS");
int k,i,j,n=0,ar[7],x=6;
string bin="",decrypt_message="",decrypt_bin_char="",str="";
cout<<"Enter cipher key from 0 to 127 : ";
cin>>k;
if(k>=0 && k<=127)
{
while(k>0)
{
ar[x]=k%2;
k=k/2;
x--;
}
while(x>=0)
{
ar[x]=0;
x--;
}
for(i=0;i<7;i++)
bin+=(char)ar[i];
ifstream infile;
infile.open("message.dat");
if(infile.is_open())
{
while(!infile.eof())
{
char b[7] = "";
infile.read(b, sizeof(b) - 1);
for(i=0;i<7;i++)
decrypt_bin_char+=((int)b[i] xor (int)bin[i]);
j=0;
for(i=6;i>=0;i--)
{
n+=(((int)decrypt_bin_char[i])*pow(2,j));
j++;
}
decrypt_message+=(char)n;
n=0;
infile>>b;
}
system("CLS");
cout<<decrypt_message<<endl;
exit(1);
}
else
cout<<"Error!!! File in not being opened"<<endl;
}
else
cout<<"Error!!!!!"<<endl;
return 0;
}