Работающая шифровка и дешифровка методом Вернама
#include<iostream>
#include <conio.h>
using namespace std;
char array[26][26];
char text[22],key[22],encrypted_Text[22],decrypted_Text[22];
int findRow(char);
int findColumn(char);
int findDecRow(char,int);
int main()
{
int i=0,j,k,r,c;
k=96;
for (i=0;i<26;i++)
{
k++;
for (j=0;j<26;j++)
{
array[i][j]=k++;
if(k==123)
k=97;
}
}
cout << "Enter text to encrypt it :"<<endl;
cin >> text;
cout << "Enter key for encryption:"<<endl;
cin >> key;
// Encryption
for (i=0;key[i]!=NULL;i++)
{
c=findRow(key[i]);
r=findColumn(text[i]);
encrypted_Text[i]=array[r][c];
}
encrypted_Text[i]='\0';
cout << "Encrypted text is :"<<endl;
cout <<encrypted_Text<<endl;
//decryption
for (i=0;key[i]!=NULL;i++)
{
c=findColumn(key[i]);
r=findDecRow(encrypted_Text[i],c);
decrypted_Text[i]=array[r][0];
}
decrypted_Text[i]='\0';
cout << "Decrypted text is:"<<endl;
cout << decrypted_Text<<endl;
getch();
return(0);
}
int findRow(char c)
{
int i;
for (i=0;i<26;i++)
{
if(array[0][i]==c)
return(i);
}
return 0;
}
int findColumn(char c)
{
int i;
for (i=0;i<26;i++)
{
if(array[i][0]==c)
return(i);
}
return 0;
}
int findDecRow(char c,int j)
{
int i;
for (i=0;i<26;i++)
{
if(array[i][j]==c)
return(i);
}
return 0;
}