/* Program to implement columnar transposition cipher encryption decryption technique.
*/
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
string m,k;
cout<<"\nEnter the Message to Encrypt: ";
getline(cin,m);
int mlen=m.size(),row;
if(mlen%5==0)
row=mlen/5;
else
row = (mlen/5)+1;
char enc[row][5];
int mi=0;
for(int i=0;i<row;i++)
for(int j=0;j<5;j++,mi++)
enc[i][j]=(char)m[mi];
cout<<endl;
for(int i=0;i<row;i++)
{
for(int j=0;j<5;j++)
{
if(!isalpha(enc[i][j]))
cout<<'x';
else
cout<<enc[i][j];
}
cout<<endl;
}
char out[row*5];
int ei=0;
for(int i=0;i<5;i++)
for(int j=0;j<row;j++,ei++)
{
if(!isalpha(enc[j][i]))
out[ei]='x';
else
out[ei]=enc[j][i];
}
cout<<"\nEncrypted Message is: ";
for(int i=0;i<row*5;i++)
cout<<out[i];
cout<<"\n"<<"\n";
return 0;
}
OUTPUT SCREEN:
*/
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
string m,k;
cout<<"\nEnter the Message to Encrypt: ";
getline(cin,m);
int mlen=m.size(),row;
if(mlen%5==0)
row=mlen/5;
else
row = (mlen/5)+1;
char enc[row][5];
int mi=0;
for(int i=0;i<row;i++)
for(int j=0;j<5;j++,mi++)
enc[i][j]=(char)m[mi];
cout<<endl;
for(int i=0;i<row;i++)
{
for(int j=0;j<5;j++)
{
if(!isalpha(enc[i][j]))
cout<<'x';
else
cout<<enc[i][j];
}
cout<<endl;
}
char out[row*5];
int ei=0;
for(int i=0;i<5;i++)
for(int j=0;j<row;j++,ei++)
{
if(!isalpha(enc[j][i]))
out[ei]='x';
else
out[ei]=enc[j][i];
}
cout<<"\nEncrypted Message is: ";
for(int i=0;i<row*5;i++)
cout<<out[i];
cout<<"\n"<<"\n";
return 0;
}
OUTPUT SCREEN:
No comments:
Post a Comment