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
|
#include <windows.h>
#include <iostream>
#include <cstdlib>
#include <string>
#include <cmath>
using namespace std;
int main()
{
int ctr; // input array's length
int ctr1; // input counter
int ctr2; // output counter
string output; // output string to display. Arrays for ciphering are as follows:
char cipalp [26] = {'z','y','x','w','v','u','t','s','r','q','p','o','n','m','l','k','j','i','h','g','f','e','d','c','b','a'};
char regalp [26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
string input; // input string initilized
getline(cin, input); // Get user input.
ctr = input.length() + 1; //it includes the null at the end
char *arr = new char[ctr]; // make a new array (dynamic size)
for(int i=0; i < ctr; i++) // FOR loop to create array from input variable.
{
arr[i] = input[i];
}
ctr = input.length();
for (ctr1 = 0; ctr1 < ctr2; ctr1++) { // Add 1 to input variable.
if (ctr1 < ctr2) {
for (ctr2 = 0; ctr2 < input.length(); ctr2++) {
if (arr[ctr1] == regalp[ctr2]) {
output = output + cipalp[ctr2]; // Add the cipherchar to the output variable.
}
}
}
}
cout << output;
delete arr; //free the memory
return 0;
}
| |