Practical 3
Practical 3
:230843116012
PRACTICAL – 3
AIM:-Implement Ceasar and Hill cipher. Both are substitution cipher.
Analyze the strength of the cipher in terms of brute force attack and
cryptanalysis attack. Suggest one way to improve and strengthen the
cipher and analyze with respect to cryptanalysis attack
Ceasar cipher –
You are given plaintext Hello, Welcome. The key used is 3. How
Ceaser cipher will work?
Test case :
ABC
DEF
Hill Cipher -
Key K =[2 2 19, 21 18 21, 17 17 5]
Plaintext = pay
Ciphertext = RRL
CODE:-
Caesar Cipher
#include<stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
9
Enrollment No.:230843116012
void clearInputBuffer() {
int c;
while ((c = getchar()) != '\n' && c != EOF);
}
int main() {
char plaintext[MAX_INPUT];
char ciphertext[MAX_INPUT];
char decrypted[MAX_INPUT];
int key;
return 0;
}
10
Enrollment No.:230843116012
OUTPUT
CODE:-
Hill Cipher
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
11
Enrollment No.:230843116012
int result[MATRIX_SIZE];
void clearInputBuffer() {
int c;
while ((c = getchar()) != '\n' && c != EOF);
}
int main() {
char plaintext[MAX_INPUT];
char ciphertext[MAX_INPUT];
char decrypted[MAX_INPUT];
int key[MATRIX_SIZE][MATRIX_SIZE];
13
Enrollment No.:230843116012
printf("\nKey Matrix:\n");
printMatrix(key);
int c[3];
matrixMultiply(key, p, c);
printf("Ciphertext numbers: %d %d %d\n", c[0], c[1], c[2]);
return 0;
}
OUTPUT
14