Bhairahawa Multiple Campus
Lab Report Cover Page
● Title: Cryptography Lab Report
● Course Name & Code: * Student Name: * Roll No / ID: Instructor’s Name:
Table of Content
● Title * Date of Performance: * Date of Submission: * Signature:
Date of Performance: Consult during regular class
Lab Title
1. To encrypt and decrypt the user input message and key using Caesar cipher.
2. To encrypt and decrypt the user input message and key using Play fair cipher.
3. To encrypt and decrypt the user input message and rails using Rail-fence cipher.
4. To simulate the generation of sub keys for the DES algorithm. (Hint: use 10 bits )
5. To test the prime numbers using Fermat’s theorem.
6. To test the prime number using Miller -Rabin algorithm.
7. To find the Euler totient function of the user input integer.
8. To test if a user input two integers is a primitive root or not.
9. To find the multiplicative inverse using Extended Euclidean algorithm.
10.To simulate the Diffie-Hellman key exchange algorithm.
11.To implement key exchange and encryption-decryption using RSA algorithm
You are required to submit the report in handwritten form
Sample
1. Title
Implementation of the Shift Cipher (Caesar Cipher)
2. Objectives
● To understand the working mechanism of Monoalphabetic Substitution Ciphers.
● To implement encryption and decryption functions using modular arithmetic.
● To verify the process by recovering the original plaintext from the ciphertext.
3. Theory
The Shift Cipher is one of the simplest encryption techniques. It works by replacing each
letter in the plaintext with a letter a fixed number of positions down the alphabet.
Let P be the numerical value of a plaintext letter (A=0,B=1,…,Z=25) and k be the key (shift
value). The mathematical functions are defined as:
● Encryption: E(P)=(P+k)(mod26)
● Decryption: D(C)=(C−k)(mod26)
If the result of (C−k) is negative, we add 26 to bring it back into the positive range [0,25].
4. Source Code (C++)
You must use the c/c++ for implementation. Also use modular (functional) approach for code
#include <iostream>
#include <string>
using namespace std;
// Function to encrypt the text
string encrypt(string text, int key) {
string result = "";
// Traverse the text
for (int i = 0; i < [Link](); i++) {
char ch = text[i];
// Encrypt Uppercase letters
if (isupper(ch)) {
result += char(int(ch + key - 65) % 26 + 65);
// Encrypt Lowercase letters
else if (islower(ch)) {
result += char(int(ch + key - 97) % 26 + 97);
// If it's not a letter, leave it as is
else {
result += ch;
return result;
}
// Function to decrypt the text
string decrypt(string text, int key) {
// Decryption is encryption with (26 - key)
return encrypt(text, 26 - (key % 26));
int main() {
string message;
int key;
cout << "--- Shift Cipher Program ---" << endl;
cout << "Enter a message: ";
getline(cin, message);
cout << "Enter shift key (0-25): ";
cin >> key;
string encrypted = encrypt(message, key);
string decrypted = decrypt(encrypted, key);
cout << "\nResults:" << endl;
cout << "Original: " << message << endl;
cout << "Encrypted: " << encrypted << endl;
cout << "Decrypted: " << decrypted << endl;
return 0;
5. Output
You are required to keep the screenshot of the output. Disclaimer: don’t use online compiler
--- Shift Cipher Program ---
Enter a message: Hello World!
Enter shift key (0-25): 4
Results:
Original: Hello World!
Encrypted: Lipps Asvph!
Decrypted: Hello World!
6. Conclusion
The Shift Cipher was successfully implemented. The experiment confirmed that modular
arithmetic effectively handles the "wrap-around" effect when a shift goes past the letter
'Z'.