0% found this document useful (0 votes)
3 views2 pages

C Program for Columnar Transposition Encryption

The document outlines a C program for encryption and decryption using the columnar transposition technique. It includes code snippets for creating a matrix from plaintext, encrypting the text, and then decrypting it back to the original form. The program prompts the user for input and displays both the encrypted and decrypted text.

Uploaded by

rajesh30tiwary
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

C Program for Columnar Transposition Encryption

The document outlines a C program for encryption and decryption using the columnar transposition technique. It includes code snippets for creating a matrix from plaintext, encrypting the text, and then decrypting it back to the original form. The program prompts the user for input and displays both the encrypted and decrypted text.

Uploaded by

rajesh30tiwary
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Practical No:09 Date:

Aim: Write a c program for encryption and decryption using columnar


transposition technique.

#include<conio.h> { mat[i][j] = 32;


#include<stdio.h> }
void main() }
{ printf("\n\t\t\t ");
char pt[60]; char }
newpt[60]={"\0"}; char }
et[60]={"\0"}; char //Encryption start here
newet [60] ={"\0"} ; k=0;
char dt[60] = {"\0"} ; for(m=0;m<column;m+=2)
char mat[12] [5]; {
int row,column=5,len,i,j,newlen,k=0,m; for(i=0;i<row;i++)
printf("\n\n\tEnter plain text: "); {
gets(pt); len=strlen(pt); et[k]=mat[i][m];
for(i=0;i<len;i++) k++;
{ }
if(pt[i] != 32) }
30; { for(m=1;m<column;m+=2)
newlen=strlen(newpt); {
newpt[newlen] = pt[i]; for(i=0;i<row;i++)
} {
} et[k]=mat[i][m];
//get size of row newlen k++;
= strlen(newpt); row = }
newlen / column; 31;
if(newlen % column > }
0) row = row + 1; //blank space remove
//create matrix from plaintext newlen=strlen(et);
printf("\n\tColumner matrix is:"); for(i=0;i<newlen;i++)
for(i=0;i<row;i++) {
{ if(et[i] != 32)
for(j=0;j<column;j++) {
{ len=strlen(newet);
if(k<newlen) newet[len]=et[i];
{ }
mat[i][j] = newpt[k]; }
printf (" %2c", newpt[k]); printf("\n\n\tEncrypted text is: %s", newet);
k ++; } else //Dycription start here
k=0;
for(i=0;i<row;i++)
{ m=i;
for(j=0;j<column;j++) O/P:
{
if(j%2 == 0)
{ dt[k]=et[m];
m=m+(row*3);
k++; } else {
dt[k]=et[m];
m=m-
(row*2);
k++;
}
}}
printf("\n\n\tDecrypted text is: %s", dt);
getch();
}

You might also like