#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <cctype>
using namespace std;
int main ()
{
const int length = 26;
char readfile[length];
char doagain;
cout << "================================================" << endl;
cout << "Welcome to the Austin Powers Decryption Program!" << endl;
cout << "================================================" << endl;
ifstream inputFile;
do
{
cout << "Please type the name of the file to decrypt:";
cin >> readfile;
inputFile.open(readfile);
while (!inputFile)
{
inputFile.clear();
cout << "\n Invalid File. Enter file name again please--->";
cin >> readfile;
inputFile.open(readfile);
}
cout << "\n File loaded..." << endl << endl;
cout << "Please enter the three encryption codes." << endl << endl;
cout << "Enter integrals 0-26 for each code." << endl << endl;
int entry1;
int entry2;
int entry3;
cout << "\nEnter first integer here--->";
cin >> entry1;
while (entry1 < 0 || entry1 > 26)
{
cout << " ERROR: Invalid Number";
cout << "\n Please enter your first number again--->";
cin >> entry1;
}
cout << "Enter the second integer here--->";
cin >> entry2;
while (entry2 < 0 || entry2 > 26)
{
cout << "\n ERROR: Invalid Number";
cout << "\n Please enter the second integer again--->";
cin >> entry2;
}
cout << "Enter third integer here--->";
cin >> entry3;
while (entry3 < 0 || entry3 > 26)
{
cout << "\n ERROR: Invalid Number";
cout << "\n Please enter the third number again--->";
cin >> entry3;
}
cout << "\n You have inputed the following codes:" << endl << endl;
cout << entry1 << endl << endl;
cout << entry2 << endl << endl;
cout << entry3 << endl << endl;
cout << "Using the keys:";
cout << entry1 << entry2 << entry3;
cout << "\n \n The decrypted message is as follows:";
//Decryption code
char characters;
char conversion1;
while (inputFile.get(characters))
{
if (isupper(characters))
{
conversion1 = static_cast<int>(characters);
}
else if (islower(characters))
{
conversion1 = static_cast<int>(characters);
}
else
{
}
cout << conversion1;
}
cout << "\n \n Would you like to decrypt another message?";
cout << "\n \n Please use Y or y for yes and N or n for no--->";
cin >> doagain;
while ( doagain != 'N' && doagain != 'n' && doagain != 'Y' && doagain != 'y' )
{
cout << "\n Not a valid option, please read the prompt.";
cout << "\n \n Would you like to decrypt another file?--->";
cin >> doagain;
}
} while ( doagain == 'Y' || doagain =='y' );
return 0;
}
Help with Decrypter
Page 1 of 16 Replies - 566 Views - Last Post: 15 February 2011 - 08:48 PM
#1
Help with Decrypter
Posted 15 February 2011 - 06:16 PM
I'm making a decrypter for class. I'm having trouble getting it to decrypt the file. The decrypted file needs to change the code Yw. Bxuxaqwi to Mr. Whiskers. The first integer is 12, second is 5, third is 16. I am so lost! Can someone please help me?
Replies To: Help with Decrypter
#2
Re: Help with Decrypter
Posted 15 February 2011 - 07:01 PM
The ASCII value for capital Y is 89 (decimal), take away 12, and the result is 77 which is the code/value for capital M.
#3
Re: Help with Decrypter
Posted 15 February 2011 - 07:43 PM
But how do I make it so it changes every character. I got it to change every 3rd one that is supposed to subtract 12. This is my new code.
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <cctype>
using namespace std;
int main ()
{
const int length = 26;
char readfile[length];
char doagain;
cout << "================================================" << endl;
cout << "Welcome to the Austin Powers Decryption Program!" << endl;
cout << "================================================" << endl;
ifstream inputFile;
do
{
cout << "Please type the name of the file to decrypt:";
cin >> readfile;
inputFile.open(readfile);
while (!inputFile)
{
inputFile.clear();
cout << "\n Invalid File. Enter file name again please--->";
cin >> readfile;
inputFile.open(readfile);
}
cout << "\n File loaded..." << endl << endl;
cout << "Please enter the three encryption codes." << endl << endl;
cout << "Enter integrals 0-26 for each code." << endl << endl;
int entry1;
int entry2;
int entry3;
cout << "\nEnter first integer here--->";
cin >> entry1;
while (entry1 < 0 || entry1 > 26)
{
cout << " ERROR: Invalid Number";
cout << "\n Please enter your first number again--->";
cin >> entry1;
}
cout << "Enter the second integer here--->";
cin >> entry2;
while (entry2 < 0 || entry2 > 26)
{
cout << "\n ERROR: Invalid Number";
cout << "\n Please enter the second integer again--->";
cin >> entry2;
}
cout << "Enter third integer here--->";
cin >> entry3;
while (entry3 < 0 || entry3 > 26)
{
cout << "\n ERROR: Invalid Number";
cout << "\n Please enter the third number again--->";
cin >> entry3;
}
cout << "\n You have inputed the following codes:" << endl << endl;
cout << entry1 << endl << endl;
cout << entry2 << endl << endl;
cout << entry3 << endl << endl;
cout << "Using the keys:";
cout << entry1 << entry2 << entry3;
cout << "\n \n The decrypted message is as follows:";
//Decryption code
char characters;
int conversion1;
while (inputFile.get(characters))
{
if (isupper(characters))
{
conversion1 = static_cast<int>(characters);
conversion1 = conversion1 - entry1;
characters = static_cast<char>(conversion1);
}
else if (islower(characters))
{
conversion1 = static_cast<int>(characters);
conversion1 = conversion1 - entry1;
characters = static_cast<char>(conversion1);
}
else
{
}
cout << characters;
}
cout << "\n \n Would you like to decrypt another message?";
cout << "\n \n Please use Y or y for yes and N or n for no--->";
cin >> doagain;
while ( doagain != 'N' && doagain != 'n' && doagain != 'Y' && doagain != 'y' )
{
cout << "\n Not a valid option, please read the prompt.";
cout << "\n \n Would you like to decrypt another file?--->";
cin >> doagain;
}
} while ( doagain == 'Y' || doagain =='y' );
return 0;
}
#4
Re: Help with Decrypter
Posted 15 February 2011 - 08:00 PM
lakers4mvp, on 16 February 2011 - 04:43 AM, said:
But how do I make it so it changes every character. I got it to change every 3rd one that is supposed to subtract 12. This is my new code.
One way would be to use a counter, which would increment each time round the loop. So count goes 1, 2, 3 and then back to 1. This would allow you to keep track of the entry value to use.
Another possibility similar to the above is to have an current entry value variable which changes from entry1(12) to entry2(5) to entry3(16) and back to entry1(12) each time round the loop.
#5
Re: Help with Decrypter
Posted 15 February 2011 - 08:03 PM
I'm sorry if this is asking to much, but is there anyway you could provide an example? I'm new to c++.
#6
Re: Help with Decrypter
Posted 15 February 2011 - 08:24 PM
int count = 3;
while (inputFile.get(characters))
{
if(count < 3)
count++;
else
count=1;
// count is now 1, 2 or 3
// corresponding to entry1, entry2 or entry3
#7
Re: Help with Decrypter
Posted 15 February 2011 - 08:48 PM
Is that what I put into my code to get it working?
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|