Skip to main content

Polyalphabetic cipher

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

Popular posts from this blog

Hill Cipher

                                            Hill cipher encryption-decryption. PSEUDOCODE Encryption To encrypt a message using the Hill Cipher we must first turn our keyword into a key matrix (a 2 x 2 matrix for working with digraphs, a 3 x 3 matrix for working with trigraphs, etc). We also turn the plaintext into digraphs (or trigraphs) and each of these into a column vector. We then perform matrix multiplication modulo the length of the alphabet (i.e. 26) on each vector. These vectors are then converted back into letters to produce the ciphertext. Step 1:  We shall encrypt the plaintext message "short example" using the keyword hill and a 2 x 2 matrix. The first step is to turn the keyword into a matrix. If the keyword was longer than the 4 letters needed, we would only take the first 4 letters, and if it was shorter, we would fill it up with the alphabet...

Playfair cipher

                                                          Playfair cipher encryption-decryption Pseudocode: 1.       First, a plaintext message is split into pairs of two letters (digraphs). If there is an odd number of letters, a Z is added to the last letter. Let us say we want to encrypt the message "Programming". It will be written as - Programming 2.       The rules of encryption are - 3.       If both the letters are in the same column, take the letter below each one (going back to the top if at the bottom) 4.       If both letters are in the same row, take the letter to the right of each one (going back to the left if at the farthest right) 5.       If neither of the preceding two rules is true, fo...

Mono alphabetic cipher

                                               Mono alphabetic cipher encryption-decryption A mono-alphabetic cipher is a type of simple substitution cipher. In this cipher technique, each letter of the plaintext is replaced by another letter in the cipher-text. An example of a mono-alphabetic cipher key follows: Plain Text   >>>   a  b  c  d  e  f  g  h  i  j  k  l  m  n  o  p  q  r  s  t  u  v  w  x  y  z Cipher Text >>>  z  w  x  y  o  p  r  q  a  h  c  b  e  s  u  t  v  f  g  j  l  k  m  n  d  i This key means that any ‘a’ in the plaintext will be replaced by a ...