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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
#include <iostream>
using namespace std;
//PrintAlphabet function template
template<class Cypher>
void PrintAlphabet(Cypher array[], int value);
//PrintWord function template
template<class Cypher>
void PrintWord(Cypher word[], int value);
//Encrypt function template
template<class Cypher>
void Encrypt(Cypher array[], int value);
int main()
{
int value;
int length;
int correct;
int i;
int j;
char x;
char array[50];
char word [50];
cout<<"Please enter the number of letters in your alphabet: ";
cin>>value;
do
{
cout<<"Please enter the letters of your alphabet, in order, followed by the enter key.\n";
for( i=0; i < value; i++)
{
cin>> x;
array[i]=x;
}
cout<<"You have entered the following: \n";
PrintAlphabet(array, value);
cout<<"\nIf this is correct press 0, if it's incorrect press 1: ";
cin>> correct;
}while(correct != 0);
do
{
cout<<"Please enter the length of the word you'd like encrypted: ";
cin>> length;
cout<<"Please enter the word to be encrypted followed by the enter key.\n";
for( j=0;j < length; j++)
{
cin>> x;
word[j]=x;
}
cout<<"You have entered the following: \n";
PrintWord(word, length);
cout<<"\nIf this is correct press 0, if it's incorrect press 1.\n";
cin>> correct;
}while(correct != 0);
cout<<"\nEncrypt Message: \n";
Encrypt(word, length);
return 0;
}
template <class Cypher>
void PrintAlphabet(Cypher array[], int value)
{
int i=0;
for(i=0;i<value;i++)
cout<<array[i]<<", ";
}//end PrintAlphabet4
template <class Cypher>
void PrintWord(Cypher word[], int length)
{
int i=0;
for(i=0;i<length;i++)
cout<<word[i];
}
template <class Cypher>
void Encrypt(Cypher array[], int value)
{
int i=0;
for(i=0; i<value; i++)
{
cout<<array[(i + 3) % value];
}
}
//f(p)=(p+3) mod m : m = number of letters in alphabet
|