0% found this document useful (0 votes)
27 views

Encryption: Practical:-5 AIM:-Implement Playfair Cipher Encryption-Decryption

The document describes an implementation of the Playfair cipher for encryption and decryption of plaintext using a 5x5 key matrix. It includes code to: 1) print the key matrix; 2) get plaintext/ciphertext from the user; 3) find the row and column positions of each plaintext/ciphertext character in the matrix; and 4) use those positions to encrypt/decrypt the text by printing the ciphertext/plaintext pairs according to the Playfair cipher rules. The code provides encryption and decryption functionality with sample outputs.

Uploaded by

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

Encryption: Practical:-5 AIM:-Implement Playfair Cipher Encryption-Decryption

The document describes an implementation of the Playfair cipher for encryption and decryption of plaintext using a 5x5 key matrix. It includes code to: 1) print the key matrix; 2) get plaintext/ciphertext from the user; 3) find the row and column positions of each plaintext/ciphertext character in the matrix; and 4) use those positions to encrypt/decrypt the text by printing the ciphertext/plaintext pairs according to the Playfair cipher rules. The code provides encryption and decryption functionality with sample outputs.

Uploaded by

jhyter54rd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Practical:-5

AIM:-Implement Playfair cipher encryption-decryption.

Encryption
#include<stdio.h>

#include<conio.h>

int main()

char arr[5][5]={"MONAR","CHYBD","EFGIK","LPQST","UVWXZ"};

char pt[10];

int i, j, r1=0, r2=0, c1=0, c2=0;

printf("Playfair Keymatrix\n==================\n");

for(i=0; i<5; i++)

for(j=0; j<5; j++)

printf("%c ", arr[i][j]);

printf("\n");

}
printf("Enter your plain text:");

scanf("%s",pt);

printf("Your plain text = %s", pt);

for(i=0; i<5; i++)

for(j=0; j<5; j++)

if(arr[i][j] == pt[0])

r1=i; c1=j;

if(arr[i][j] == pt[1])

r2=i; c2=j;

if(r1==r2)
{

if(c2==4)

printf("Ciphertext = %c%c \n", arr[r1][c1+1], arr[r2][0]);

else

printf("Ciphertext = %c%c \n", arr[r1][c1+1], arr[r2][c2+1]);

if(c1==c2)

if(r2==4)

printf("Ciphertext = %c%c \n", arr[r1+1][c1], arr[0][c2]);

else

printf("Ciphertext = %c%c \n", arr[r1+1][c1], arr[r2+1][c2]);

if(r1 != r2 && c1 != c2)

printf("\nCiphertext = %c%c \n", arr[r1][c2], arr[r2][c1]);

getch();

return 0;

}
Output:-

DECRYPTION
#include<stdio.h>

#include<conio.h>

int main()

char arr[5][5]={"MONAR","CHYBD","EFGIK","LPQST","UVWXZ"};

char ct[10];

int i, j, r1=0, r2=0, c1=0, c2=0;

printf("Plaifair Keymatrix\n=================\n");

for(i=0; i<5; i++)

{
for(j=0; j<5; j++)

printf("%c ", arr[i][j]);

printf("\n");

printf("Enter your cipher text:");

scanf("%s",ct);

printf("Your cipher text is %s\n", ct);

for(i=0; i<5; i++)

for(j=0; j<5; j++)

if(arr[i][j] == ct[0])

r1=i; c1=j;

if(arr[i][j] == ct[1])

r2=i; c2=j;
}

if(r1==r2)

if(c2==0)

printf("Plaintext = %c%c \n", arr[r1][c1-1], arr[r2][4]);

else

printf("Plaintext = %c%c \n", arr[r1][c1-1], arr[r2][c2-1]);

if(c1==c2)

if(r2==0)

printf("Plaintext = %c%c \n", arr[r1-1][c1], arr[4][c2]);

else

printf("Plaintext = %c%c \n", arr[r1-1][c1], arr[r2-1][c2]);

if(r1 != r2 && c1 != c2)

printf("Plaintext = %c%c \n", arr[r1][c2], arr[r2][c1]);


}

getch();

return 0;

Output:-

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy