Polyalphabetic cipher encryption-
decryption.
PSEDOCODE:
Encryption
Ci=(Ti +Ki)modn
Ci - i-th character of the
ciphertext
Ti - i-th character of the open
text
Ki - i-th character of the key
phrase (if the key phrase is shorter than the open text, which is usual, than
the keyphrase is reapeated to math the length of the open text)
m - length of the alphabet
1.
To
encrypt the open text, we have to sum together the first letters of the open
text and key phrase, the second letters, third and so on.
2.
To
encrypt the n-th letter of the open text (assume “L“) using the Vigenère square
3.
we find
the letter on the horizontal axis of the table and we find n-th letter of the key
phase on the vertical axis (assume “T“)
4.
At the intersection of the given row and
column the resulting n-th letter of the ciphertext is located (“E“).
Decryption
Ti=(Ci-Ki)modn
Ci - i-th
character of the ciphertext
Ti - i-th
character of the open text
Ki - i-th
character of the key phrase (if the key phrase is shorter than the open text,
which is usual, than the keyphrase is reapeated to math the length of the open
text)
m - length of
the alphabet
1.
The
decryption works the other way around.
2.
We find
in the row corresponding to the n-th letter of the key phrase (“T”) a cell in
which the n-th letter of the ciphertext (“E”) resides.
3. Its column is denoted by the n-th letter of
the open text (“L“).
//Program:
#include<stdio.h>
void main()
{
int i, kl,pl;
char p[50],k[50],cipher[50];
printf("Enter the length of the key stream. ");
scanf("%d",&kl);
printf("Enter the length of the plain text stream.(Without spaces) ");
scanf("%d",&pl);
printf("\nEnter the Key. ");
for(i=-1;i<kl;++i)
scanf("%c",&k[i]);
printf("\nEnter the Plain text. ");
for(i=-1;i<pl;++i)
scanf("%c",&p[i]);
int s[3][pl];
for(i=0;i<pl;++i)
{
if(65<=p[i] && p[i]<=91)
s[0][i]=p[i]%65;
else
s[0][i]=p[i]%97;
}
for(i=0;i<pl;++i)
printf("%d ",s[0][i]);
int count=0;
while(count<pl)
{
for(i=0;i<kl;++i)
{
if(65<=k[i] && k[i]<=91)
s[1][count+i]=k[i]%65;
else
s[1][count+i]=k[i]%97;
}
count=count+kl;
}
printf("\n");
for(i=0;i<pl;++i)
printf("%d ",s[1][i]);
//printf("\n");
//for(i=0;i<pl;++i)
//printf("%d ",s[2][i]);
printf("\n\nThe cipher text is: ");
for(i=0;i<pl;++i)
{
s[2][i]=(s[0][i]+s[1][i])%26;
cipher[i]=(char)(s[2][i]+65);
printf("%c ",cipher[i]);
}
}VIVA Questions:
1. Explain monoalphabetic cipher and
polyalphabetic cipher by giving an example
2. What is Vigenere
3. How to
attack Polyaphabetic Cipher.
4. What is
vernam Cipher.
5. Explain
One Time Pad in detail and write an algorithm for it.
6. What
are the problems with one-time pad?
7.
What is the objective of attacking an encryption
system? Write the two approaches to attack a conventional encryption scheme.
8.
What is the difference between an
unconditionally secure cipher and a computationally secure cipher?
9.
Define the terms threat and attack. List and
briefly define categories of security attacks.
Comments
Post a Comment