A question from computer security, Substitution Ciphers: Decrypt the following m
ID: 664960 • Letter: A
Question
A question from computer security, Substitution Ciphers:
Decrypt the following message.
message:
agipnnw, cei ifckdxw afxvc tdvng epsi uvnn ifckdxw; edtisik, cei gkhm oiqepfaror epsi hiif
rxiqauaig rd cepc afxvc tace uvnn ifckdxw ar fdc kijvakig. cear ar pqqdoodgpcig hw pnndtafm cei
nifmce du cei ifckdxw afxvc cd hi ndfmik cepf cei kijvakig ifckdxw (izxkirrig af hacr), pr ndfm pr
cei cdcpn ifckdxw oiicr cei kijvakioifcr du cei gkhm oiqepfaro. cei ifckdxw afxvc qpf hi
giuafig cd hi du spkaphni nifmce (taceaf rxiqauaig naoacr), pr tinn pr uazig nifmce. af pnn qprir, cei
gkhm oiqepfaro izxiqcr cepc teif ifckdxw afxvc ar kijvircig, cei kicvkfig hacrckafm tann
qdfcpaf pc niprc cei kijvircig podvfc du ifckdxw. pggacadfpn ifckdxw hiwdfg cei podvfc kijvircig
ar fdc kijvakig, hvc ar girakphni.
Explanation / Answer
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector.h>
#include <string>
#include <time.h>
#include <fstream.h>
using namespace::std;
void encrypt (void);
void decrypt (void);
int main()
{
int choice;
while (choice != 3)
{
cout<<"What operation would you like to perform? ";
cout<<"1 - Encrypt ";
cout<<"2 - Decrypt ";
cout<<"3 - Quit ";
cin>>choice;
system("CLS");
switch (choice)
{
case 1:
encrypt();
break;
case 2:
decrypt();
break;
case 3:
break;
default: cout<<"Please enter a valid response. ";
break;
}
}
return 0;
}
void encrypt ()
{
ofstream fout;
string plaintext;
string ciphertext;
string cipherletter;
string shift_string_1;
string shift_string_2;
char shift_letter;
signed int cipher_num;
signed int cipher_num_2;
signed int shifter;
signed int shift_num;
char letter;
cout<<"Enter your word here: ";
cin>>plaintext;
signed int slength = plaintext.size();
signed int loops = 0;
signed int seed;
fout.open("key.txt");
fout.close();
fout.open("key.txt",ios::app);
fout<< "PLAINTEXT: " << plaintext << endl;
fout<<"KEY:";
while (loops < slength)
{
shifter = loops;
if (loops == 0)
{
shifter = slength;
}
if (loops % 2 < 1)
{
shifter = shifter * -1;
}
else
{
shifter = loops;
}
fout<<shifter;
cipher_num = int(plaintext[loops]);
cipher_num_2 = cipher_num + shifter;
letter = char(cipher_num_2);
cipherletter = letter;
ciphertext.append(cipherletter);
loops++;
}
fout<< endl <<"CIPHERTEXT: " << ciphertext <<endl;
fout.close();
system("PAUSE");
}
void decrypt ()
{
string encrypted;
string key;
cout<<"Please enter the encrypted text: ";
cin>> encrypted;
system("CLS");
cout<<"Please enter the key, without signs: ";
cin>>key;
signed short int shifter;
char letter;
char new_letter;
int cipher_num;
int new_num;
string deciphered;
string holder;
int slength;
int shifted_letter_num;
slength = encrypted.size();
int loops = 0;
int temp_num;
while (loops < slength)
{
temp_num = key[loops];
cipher_num = temp_num-48;
cout<<cipher_num;
if (loops % 2 < 1)
{
cipher_num = cipher_num * -1;
}
shifted_letter_num = int(encrypted[loops]);
cout<<"ASCII of the encrypted text: " << shifted_letter_num << endl;
new_num =shifted_letter_num - cipher_num;
letter = char(new_num);
holder = letter;
cout<<"Decrypted letter: " << holder << endl;
deciphered.append(holder);
loops++;
}
cout<<"Decrytpion done. Decrypted text: " << deciphered << endl;
system("PAUSE");
}