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
|
#include <iostream>
#include <string>
using namespace std;
int main()
{
string encrypted;
string decrypted;
// Get input from the user
string myArray = "";
cout << "Enter the message you would like to encrypt: ";
getline(cin, myArray);
// Alphabet Array
char arr[30] = { ' ', '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', '.', '?', ',' };
// Encrypt
for (int i = 0; i < myArray.length(); i++)
{
int index = -1;
for (int j = 0; j < 30; j++)
{
if (myArray[i] == arr[j])
{
index = j;
}
index = index + 5;
index = index + (3 * i);
index = index % 30;
encrypted[i] = arr[index];
}
cout << encrypted[i] << endl;
}
|