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
|
# include <iostream>
# include <cstring>
const char alphabet[] ={'A', 'B', 'C', 'Ç', 'D', 'E', 'F', 'G', 'Ğ', 'H', 'I',
'İ', 'J', 'K', 'L', 'M', 'N', 'O', 'Ö', 'P', 'R', 'S',
'Ş', 'T', 'U', 'Ü', 'V', 'Y', 'Z', '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9', '.', ',', ':', ';', ' '};
const int char_num =44;
void cipher(char word[], int count, int key)
{
int i = 0;
while(i < count) {
int ind = -1;
while(alphabet[++ind] != word[i]) ;
ind += key;
if(ind >= char_num)
ind -= char_num;
word[i] = alphabet[ind];
++i;
}
}
void decipher(char word[], int count, int key)
{
int i = 0;
while(i < count) {
int ind = -1;
while(alphabet[++ind] != word[i]) ;
ind -= key;
if(ind < 0)
ind += char_num;
word[i] = alphabet[ind];
++i;
}
}
int main()
{
char text[] = "ABJT;";
int len = strlen(text);
std::cout << text << std::endl;
cipher(text, len, 2);
std::cout << text << std::endl;
decipher(text, len, 2);
std::cout << text << std::endl;
return 0;
}
|