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
|
#include <iostream>
#include <string>
using namespace std;
void begde();
void begen();
string encrypt(char s[], int n, string code, int m);
string decrypt(char t[], int n, string code, int m);
int main()
{
cout << "\t\tVigenere's Cipher Encoder/Decoder\n\
created by QWERTYman (c) 2008\n\
1. Encrypt\n\
2. Decrypt\n\
3. Exit\n";
int choose;
cin >> choose;
switch(choose)
{
case 1:
begen();
break;
case 2:
begde();
break;
default:
return 0;
}
}
void begen()
{
cout << "Text to encode (all caps, please): ";
char tov[500];
for(int i = 0; i < 500; i++)
tov[i] = '\0';
cin.getline(tov, 500);
cin.get();
cout << "Code word: ";
char c[500];
for(int i = 0; i < 500; i++)
c[i] = '\0';
cin.getline(c, 500);
cout << "The encoded string is: " << encrypt(tov, 500, c, 500);
cin.get();
exit(0);
}
string encrypt(char s[], int n, char code[], int m)
{
const int t = sizeof(s);
char mod_s;
for(int i = 0; i < ( sizeof(s) ); i += ( sizeof(code) )){ //to set the modified 's' string to repeated code word
for(int j = 0; j < sizeof(code); j++){
int u = sizeof(mod_s) + 1;
mod_s[u] = code[j];}}
for(int i = ( sizeof(mod_s) - sizeof(s) ); i < sizeof(mod_s); i++)
mod_s[i] = '\0';//erases extra letters
char encoded[500];
for(int i = 0; i < sizeof(mod_s); i++){
if(mod_s[i] == ' ' || mod_s[i] == '\n')
for(int j = 0; j < sizeof(s); j++)
encoded[j] = ( mod_s[j] + (int(s[j]) - 65) );}
return encoded;
}
|