Crypto Lab
Crypto Lab
Tribhuwan University
Institute of Science and Technology
Lab Report Of
Cryptography
Submitted To:
Department of Computer Science and Information Technology
Birat Multiple College
Submitted By:
Anuj Dhungana
April 2025
Contents
1. WAP to implement Caesar Cipher. .......................................................................................................... 4
2. WAP to implement Hill Cipher. ................................................................................................................ 4
3. WAP to implement Playfair Cipher. ......................................................................................................... 5
4. WAP to implement Vigenere Cipher. ....................................................................................................... 8
5. WAP to implement Rail Fence Cipher. ................................................................................................... 10
6. WAP to implement DES Algorithm. ....................................................................................................... 11
7. WAP to implement RSA Algorithm. ....................................................................................................... 12
8. WAP to implement Diffie-Hellman Key Exchange Algorithm. .............................................................. 14
9. WAP to implement MD5 Hashing Algorithm......................................................................................... 15
10. WAP to implement AES Algorithm .................................................................................................... 17
1. WAP to implement Caesar Cipher.
#include<stdio.h>
#include<string.h>
#include<ctype.h>
void main() {
char plain[100], cipher[100];
int key, i, length;
int result;
printf("Enter the plain text : ");
scanf("%s", plain);
printf("Enter the key value : ");
scanf("%d", &key);
printf("PLAIN TEXT : %s \n", plain);
printf("CIPHER TEXT : ");
for(i = 0, length = strlen(plain); i < length; i++) {
cipher[i] = plain[i] + key;
if (isupper(plain[i]) && (cipher[i] > 'Z'))
cipher[i] = cipher[i] - 26;
if (islower(plain[i]) && (cipher[i] > 'z'))
cipher[i] = cipher[i] - 26;
printf("%c", cipher[i]);
}
printf("\nAFTER DECRYPTION: ");
for(i = 0; i < length; i++) {
plain[i] = cipher[i] - key;
if (isupper(cipher[i]) && (plain[i] < 'A'))
plain[i] = plain[i] + 26;
if (islower(cipher[i]) && (plain[i] < 'a'))
plain[i] = plain[i] + 26;
printf("%c", plain[i]);
}
printf("\n");
}
Output:
Output:
A N U I B
C D E F G
H K L M O
P Q R S T
V W X Y Z
Output:
1. Encrypt Text
2. Decrypt Text
3. Exit
Enter Your Choice: 1
Enter Plaintext: computer
Enter Key: cab
Encrypted Text: eonruugr
1. Encrypt Text
2. Decrypt Text
3. Exit
Enter Your Choice: 2
Enter Ciphertext: eonruugr
Enter Key: cab
Decrypted Text: computer
1. Encrypt Text
2. Decrypt Text
3. Exit
Enter Your Choice: 3
Output:
Output:
do {
printf("Enter public component (e): ");
scanf("%d", &e);
if (e <= 1 || e >= f || gcd(e, f) != 1) {
printf("Invalid public component. Try again.\n");
}
} while (e <= 1 || e >= f || gcd(e, f) != 1);
while ((e * d) % f != 1) {
d++;
}
printf("Computed private component (d): %d\n", d);
printf("Enter message to encrypt: ");
scanf("%s", m);
printf("Encrypted message:\n");
int encrypted[100];
for (i = 0; m[i] != '\0'; i++) {
encrypted[i] = modexp(m[i], e, n);
printf("%c -> %d\n", m[i], encrypted[i]);
}
encrypted[i] = -1;
printf("\nDecrypted message:\n");
for (i = 0; encrypted[i] != -1; i++) {
char decrypted_char = modexp(encrypted[i], d, n);
printf("%d -> %c\n", encrypted[i], decrypted_char);
}
return 0;
}}
Output:
n = 143
f = 120
Enter public component (e): 19
Computed private component (d): 19
Enter message to encrypt: ANUJDHUNGANA
Encrypted message:
A -> 65
N -> 78
U -> 84
J -> 139
D -> 94
H -> 123
U -> 84
N -> 78
G -> 20
A -> 65
N -> 78
A -> 65
Decypted message:
65 -> A
78 -> N
84 -> U
139 -> J
94 -> D
123 -> H
84 -> U
78 -> N
20 -> G
65 -> A
78 -> N
65 -> A
Output:
Output:
Output:
Encrypted Output: E7 3B 63 BD FA CE B0 1E C7 01 80 8E FE 2A 2B D0