




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





Information Security Lab (CSB-372) Worksheet- 3 Submitted by: Name: Samridh Garg Section: 19BCS_IS_7(B) Submitted to: Er. S. Ponmaniraj
Experiment- 3 Hill Cipher Q1. Practical Implementation of Hill Cipher. Aim: To implement a C program for practical implementation of Hill Cipher. Algorithm: ( For encryption) Step1: Reading Plain text. Step 2 : Reading Keywords Step 3 : Matrix construction Step 4 : Matrix Multiplication of plain text and key matrix. Step 5 : Applying Mod 26 operation with resultant Matrix. Step 6 : Replacing the numbers with cypher letters. Algorithm: ( For decryption) Decrypting with the Hill cipher is built on the following operation: D(K, C) = (K-^1 *C) mod 26 Where K is our key matrix and C is the ciphertext in vector form. Matrix multiplying the inverse of the key matrix with the ciphertext produces the decrypted plaintext. Let's do this step by step with our ciphertext, "WWVA":
for(i = 0; i < 3; i++) for(j = 0; j < 1; j++) for(k = 0; k < 3; k++) encrypt[i][j] = encrypt[i][j] + a[i][k] * mes[k][j]; printf("\nEncrypted string is: "); for(i = 0; i < 3; i++) printf("%c", (char)(fmod(encrypt[i][0], 26) + 97)); } void decryption() { int i, j, k; inverse(); for(i = 0; i < 3; i++) for(j = 0; j < 1; j++) for(k = 0; k < 3; k++) decrypt[i][j] = decrypt[i][j] + b[i][k] * encrypt[k][j]; printf("\nDecrypted string is: "); for(i = 0; i < 3; i++) printf("%c", (char)(fmod(decrypt[i][0], 26) + 97)); printf("\n"); } void getKeyMessage() { int i, j; char msg[3]; printf("Enter 3x3 matrix for key (It should be inversible):\n"); for(i = 0; i < 3; i++) for(j = 0; j < 3; j++) {
scanf("%f", &a[i][j]); c[i][j] = a[i][j]; } printf("\nEnter a 3 letter string: "); scanf("%s", msg); for(i = 0; i < 3; i++) mes[i][0] = msg[i] - 97; } void inverse() { int i, j, k; float p, q; for(i = 0; i < 3; i++) for(j = 0; j < 3; j++) { if(i == j) b[i][j]=1; else b[i][j]=0; } for(k = 0; k < 3; k++) { for(i = 0; i < 3; i++) { p = c[i][k]; q = c[k][k]; for(j = 0; j < 3; j++) { if(i != k) { c[i][j] = c[i][j]q - pc[k][j]; b[i][j] = b[i][j]q - pb[k][j]; } } }
The output was verified and result was justified. Output: