1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
#include <string>
#include <sstream>
#include <iostream>
using namespace std;
//global variables
string stringHolder = "";
string arr[4];
double option;
class Ascii {
public:
//outputs the options
void output() {
cout<< "1Encrypt-2Decrypt-3Both" << endl;
cin >> option;
cout << endl << "Enter String(Dont make it longer than four words):";
cin.ignore();
getline(cin,stringHolder);
}
//breaks string into words
void stringBreaker() {
int i = 0;
stringstream ssin(stringHolder);
while (ssin.good() && i < 4){
ssin >> arr[i];
++i;
}
for(i = 0; i < 4; i++) {
cout << arr[i] << endl;
}
}
//breaks string into char array
void charBreaker() {
}
//will output both encrypted and decrypted versions
string all() {
stringBreaker();
return (arr[1], " ", arr[2], " ", arr[3], " ", arr[4]);
}
//encrypts to ascii
string encyrpt() {
stringBreaker();
return (arr[1], " ", arr[2], " ", arr[3], " ", arr[4]);
}
//decrypts from ascii
string decrypt() {
stringBreaker();
return (arr[1], " ", arr[2], " ", arr[3], " ", arr[4]);
}
private:
//you dont have privates
};
int main() {
//local variables
string result;
string output;
Ascii ascii;
//output
ascii.output();
if (option == 1) {
result = ascii.encyrpt();
} else if(option == 2) {
result = ascii.decrypt();
} else {
result = ascii.all();
}
cout << "Result " << result;
system("Pause");
return 0;
}
|