Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

1. To find out the corresponding double Transposition Cipher of a given plaintext.

Then
perform
the reverse operation to get original plaintext.

(In C)

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<ctype.h>

char *transposition(char*) ;

char *revTransposition(char*);

int n,hold,width;

main ({)

char *plainText, *cipherText, *cipherText2, *revPlainText, *revPlainText2;


printf("\nEnter the plaintext:");
gets (plainText);
printf("\nEnteryour the width:");
scanf("%d",4&width];

n=strlen(plainText);

Lf (width>=n)

stropy (cipherText,plainText);

strcpy (cipherText?, plainText);

strcepy (revPlainText,plainText);

strcpy (revPlainText?,plainText) ;

else

stropy (cipherText, transposition (plainText));

strcepy (cipherText?, transposition (cipherText) );


strepy (revPlainText, revTransposition(cipherText2)};
strcpy (revPlainText?,revTransposition (revPlainText));
}

printi("\nAfter Single Transposition: %s",cipherText);


printfi("\nAafter double Transposition: 4s",cipherText2) ;
getch();

printf("\nAfter Single reverse: 4s5",revElainText);


printi("\nAfter double reverse: 4s5",revPlainText2};
getch();

return OQ;

char *transposition(char *plainText)


{

int i,j7

char *“cipherText;
j=0;
hold=-1;
while (j<n)
{
for (i=++hold;i<n;it=width)
cipherText [j++]=plainText [i];
}
cipherText[n]J="\0';
réturn cipherText;
}
char *revTransposition(char® plainText}
{
int i,j?
char *cipherText;
3=0;
hold=-1;
while (j<n)
{
for (i=++hold;i<n;i+t=width)
cipherText [i]=plainText [j++];
}
cipherText[n]="\0';
return ciphertext;
}
2. To encrypt a given message using ONE TIME PAD technique. Then perform the reverse
operation to set original plaintext,

(In C)

#include<stdio.h>
#include<conic.h>
#include<string.h>
#finclude<ctype.h>
main()
{
int i,n;
char *plainText, *cipherText, *revPlainText;
char *oneTimePadUpper="ABCDEFGHIJKLMNOPORSTUVWKYE";
char *oneTimePadLower="abcdefghijkimnoparstuvwxyz";
char tmp;
printi(™\nEnter the plaintext (Alphabet onlyj:");
gets (plaintext);
n=strlen(plainText);
for (i=O;i<n;it++t)
{
if {islower (plainText[i]))
{
tmp=plainText [i] +oneTimePadLower [i]-192;
cipherText [i]=96+ (tmp%26) ;
}
else if(isupper (plainText[i]})
{
tmp=plainText [i] toneTimePadUpper [i]-128;
cipherText [i]=64+ (tmp%26) ;
}
else cipherText[i]=plainText[il];
}
cipherText[n]="\O';
printfi("\nAfter using one time pad: %s",cipherText);
getch();

For (i=O;i<n;it+)
{
if (islower (cipherText[ij]))
{
tmp=96+cipherText [i] -oneTimerPadLower [il];
if(tmp<37) revPlainText [i)=tmp+26;
else revPlainText[i)=tmp;
}
else if(lsupper (cipherText[1i]})
{
tmp=64+cipherText [i] -oneTimePadUpper[il;
if({tmp<65) revPlainText [i)=tmp+26;
else revPlainText[i]=tmp;
}
else revPlainText [i] =cipherText [i];
}
revPlainText(n]="\0';
printf("\nAfter reverse original text is: %s",revwPlainText);
getch();
return 0;
}

You might also like