Well your in my neck of the woods, i personally love Encryption and Ciphers. Now i have moved on to Windows Programming (i am learning now) but i spent a long time writing some basic encryption schemes. I understand what you are trying to do but i have a question for you. Firstly the algorithm you are implementing, are you trying to make it secure or just for fun? Because this algorithm (if you can call it that) that i have shown here is not very secure but fun.
Have you tried an XOR program yet? If you are interested read up on One-Time Pads, they are the only Encryption Schemes that can NEVER be broken, and the programming is quite simple. However if you would like to keep at your current project heres how i would do it. Its a bit more complicated than you may be able to understand now but soon if you look into each aspect of it it shouldn't be too difficult to comprehend. You may want to add/take away from it what you like. I just whipped it up but it should work well. You should be able to make a more efficient/less memory consuming version soon, i could have but i was rushing to complete it . Before you start using it though try to understand it. What it does is take all of the letters of the alphabet, turns them into their ASCII values then multiplies that number by a random one. The only thing you need to decrypt is to know the random number. Once again this isnt very secure, but it is fun . Next you could try to add a function that lets someone type and message and then encrypt the message, after that you could add a function that converts all the encrypted numbers back to letters of the alphabet. There are a lot of way to manipulate the program so have fun!
Code:
#include <iostream>
#include <ctime>
using namespace std;
void encrypt(int randomnumber, int numarray[30], char alphabet[30]);
int main()
{
char alphabet[]="abcdefghijklmnopqrstuvwxyz";
int numarray[30];
int randomnumber;
int mchoice;
//infinite loop
while(1)
{
//clearscreen
system("cls");
//title
cout<<"Random Number Encryption Scheme\n";
cout<<"===============================\n\n";
//menu
cout<<"(1) Encrypt\n";
cout<<"(2) Decrypt\n";
cout<<"(3) Exit\n\n";
//get choice
cout<<"Choice: ";
cin>>mchoice;
cin.ignore();
//evaluate
if(mchoice==1)
{
//ENCRYPT
srand(time(0));
randomnumber=(rand() % 100);
encrypt(randomnumber, numarray, alphabet);
cout<<"Encrypted numbers:\n";
cout<<"Random Number is "<<randomnumber<<"\n";
for(int i=0; i<26; i++)
{
cout<<alphabet[i]<<" - "<<numarray[i]<<"\n";
}
cout<<"\n\nPress Enter to Continue...";
cin.ignore();
continue;
}
else if(mchoice==2)
{
//DECRYPT
cout<<"Enter Number: ";
cin>>randomnumber;
cin.ignore();
encrypt(randomnumber, numarray, alphabet);
for(int j=0; j<26; j++)
{
cout<<numarray[j]<<" - "<<alphabet[j]<<"\n";
}
cin.ignore();
continue;
}
else if(mchoice==3)
{
//Exit
cout<<"Press Enter To Exit...";
cin.ignore();
break;
}
else{
cout<<"Incorrect Choice!";
cin.ignore();
continue;
}
}
return 0;
}
void encrypt(int randomnumber, int numarray[27], char alphabet[27])
{
for(int i=0; i<26; i++)
{
if(alphabet[i]=='\0')
{
break;
}
numarray[i]=((int)alphabet[i] * randomnumber);
}
}
Good luck to you!