Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

To write a c program for Implementation of Playfair Cipher., Schemes and Mind Maps of Information Security and Markup Languages

To write a c program for Implementation of Playfair Cipher. 2. Algorithm: Playfair cipher for encryption The Algorithm consists of 2 steps: 1. Generate the key Square(5×5): • The key square is a 5×5 grid of alphabets that acts as the key for encrypting the plaintext. Each of the 25 alphabets must be unique and one letter of the alphabet (usually J) is omitted from the table (as the table can hold only 25 alphabets). If the plaintext contains J, then it is replaced by I. • The initial alphabets

Typology: Schemes and Mind Maps

2021/2022

Uploaded on 03/29/2023

samridh-garg
samridh-garg 🇮🇳

4 documents

1 / 12

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Worksheet- 1.4
(Playfair Cipher)
Student Name: Samridh Garg UID: 19BCS1815
Branch: BE CSE Section/Group: 19BCS_IS_7B
Semester: 6 Date of Performance:18-03-22
Subject Name: IS LAB Subject Code: CSP-356
1. Aim/Overview of the practical:
To write a c program for Implementation of Playfair Cipher.
2. Algorithm:
Playfair cipher for encryption
The Algorithm consists of 2 steps:
1. Generate the key Square(5×5):
The key square is a 5×5 grid of alphabets that acts as the key for encrypting the plaintext. Each of
the 25 alphabets must be unique and one letter of the alphabet (usually J) is omitted from the table
(as the table can hold only 25 alphabets). If the plaintext contains J, then it is replaced by I.
The initial alphabets in the key square are the unique alphabets of the key in the order in which
they appear followed by the remaining letters of the alphabet in order.
2. Algorithm to encrypt the plain text: The plaintext is split into pairs of two letters (digraphs). If there is
an odd number of letters, a Z is added to the last letter.
For example:
PlainText: "instruments"
After Split: 'in' 'st' 'ru' 'me' 'nt' 'sz'
Pair cannot be made with same letter. Break the letter in single and add a bogus letter to the previous letter.
Plain Text: “hello”
After Split: ‘he’ ‘lx’ ‘lo’
Here ‘x’ is the bogus letter.
2. If the letter is standing alone in the process of pairing, then add an extra bogus letter with the alone letter
Plain Text: “helloe”
AfterSplit: ‘he’ ‘lx’ ‘lo’ ‘ez’
Here ‘z’ is the bogus letter.
Rules for Encryption:
If both the letters are in the same column: Take the letter below each one (going back to the top if
at the bottom).
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download To write a c program for Implementation of Playfair Cipher. and more Schemes and Mind Maps Information Security and Markup Languages in PDF only on Docsity!

Worksheet- 1.

(Playfair Cipher) Student Name: Samridh Garg UID: 19BCS1 815 Branch: BE CSE Section/Group: 19 BCS_IS_7B Semester: 6 Date of Performance: 18 - 03 - 22 Subject Name: IS LAB Subject Code: CSP- 356

  1. Aim/Overview of the practical: To write a c program for Implementation of Playfair Cipher.
  2. Algorithm: Playfair cipher for encryption The Algorithm consists of 2 steps:
  3. Generate the key Square(5×5):
  • The key square is a 5×5 grid of alphabets that acts as the key for encrypting the plaintext. Each of the 25 alphabets must be unique and one letter of the alphabet (usually J) is omitted from the table (as the table can hold only 25 alphabets). If the plaintext contains J, then it is replaced by I.
  • The initial alphabets in the key square are the unique alphabets of the key in the order in which they appear followed by the remaining letters of the alphabet in order.
  1. Algorithm to encrypt the plain text: The plaintext is split into pairs of two letters (digraphs). If there is an odd number of letters, a Z is added to the last letter. For example: PlainText: "instruments" After Split: 'in' 'st' 'ru' 'me' 'nt' 'sz' Pair cannot be made with same letter. Break the letter in single and add a bogus letter to the previous letter. Plain Text: “hello” After Split: ‘he’ ‘lx’ ‘lo’ Here ‘x’ is the bogus letter.
  2. If the letter is standing alone in the process of pairing, then add an extra bogus letter with the alone letter Plain Text: “helloe” AfterSplit: ‘he’ ‘lx’ ‘lo’ ‘ez’ Here ‘z’ is the bogus letter. Rules for Encryption:
  • If both the letters are in the same column: Take the letter below each one (going back to the top if at the bottom).

For example: Diagraph: "me" Encrypted Text: cl Encryption: m - > c e - > l

If both the letters are in the same row: Take the letter to the right of each one (going back to the leftmost if at the rightmost position). For example: Diagraph: "st" Encrypted Text: tl Encryption: s - > t t - > l

  • If neither of the above rules is true: Form a rectangle with the two letters and take the letters on the horizontal opposite corner of the rectangle. For example: Diagraph: "nt" Encrypted Text: rq Encryption: n - > r t - > q

str[j]='\0'; printf("Entered String is %s\n",str); //Storing string in terms of ascii and to restore spaces I used - 20 size=strlen(str); for(i=0;i<size;i++) { if(str[i]!=' ') numstr[i]=str[i]-'A'; } lennumstr=i; //Key processing printf("Enter the key (Non repeated elements if possible)\n"); gets(key); //converting entered key to Capital letters for(i=0,j=0;i<strlen(key);i++) { if(key[i]!=' ') { key[j]=toupper(key[i]); j++; } } key[j]='\0'; printf("%s\n",key); //Storing key in terms of ascii k=0; for(i=0;i<strlen(key)+26;i++) { if(i<strlen(key)) { if(key[i]=='J') { flag=8; printf("%d",flag);

numkey[i]=key[i]-'A'; } else { if(k!=9 && k!=flag)//Considering I=J and taking I in place of J except when J is there in key ignoring I { numkey[i]=k; } k++; } } templen=i; lenkey=removerepeated(templen,numkey); printf("Entered key converted according to Play Fair Cipher rule\n"); for(i=0;i<lenkey;i++) { printf("%c",numkey[i]+'A'); } printf("\n"); //Arranging the key in 5x5 grid k=0; for(i=0;i<5;i++) { for(j=0;j<5;j++) { cipherkey[i][j]=numkey[k]; k++; } } printf("Arranged key\n"); for(i=0;i<5;i++) { for(j=0;j<5;j++) {

row2=i; col2=j; } } } //Only change between Ecryption to decryption is changing + to - //If negative add 5 to that row or column if(row1==row2) { col1=(col1-1)%5; col2=(col2-1)%5; if(col1<0) { col1=5+col1; } if(col2<0) { col2=5+col2; } numcipher[k]=cipherkey[row1][col1]; numcipher[k+1]=cipherkey[row2][col2]; } if(col1==col2) { row1=(row1-1)%5; row2=(row2-1)%5; if(row1<0) { row1=5+row1; } if(row2<0) { row2=5+row2; } numcipher[k]=cipherkey[row1][col1];

numcipher[k+1]=cipherkey[row2][col2]; } if(row1!=row2&&col1!=col2) { numcipher[k]=cipherkey[row1][col2]; numcipher[k+1]=cipherkey[row2][col1]; } } printf("\nCipher Text is\n"); for(i=0;i<lennumstr;i++) { if((numcipher[i]+'A')!='X')//Should remove extra 'X' which were created during Encryption printf("%c",numcipher[i]+'A'); } printf("\n"); } int removerepeated(int size,int a[]) { int i,j,k; for(i=0;i<size;i++) { for(j=i+1;j<size;) { if(a[i]==a[j]) { for(k=j;k<size;k++) { a[k]=a[k+1]; } size--; } else { j++; }

  1. Result/Output/Writing Summary:

Evaluation Grid: Sr. No. Parameters Marks Obtained Maximum Marks