0% found this document useful (0 votes)
3 views25 pages

Content

The document outlines various symmetric and asymmetric encryption techniques, including Caesar Cipher, Playfair Cipher, Hill Cipher, Vigenere Cipher, and RSA. Each technique is explained with its encryption and decryption processes, examples, and corresponding C language code implementations. The results indicate successful execution of encryption and decryption for each method.

Uploaded by

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

Content

The document outlines various symmetric and asymmetric encryption techniques, including Caesar Cipher, Playfair Cipher, Hill Cipher, Vigenere Cipher, and RSA. Each technique is explained with its encryption and decryption processes, examples, and corresponding C language code implementations. The results indicate successful execution of encryption and decryption for each method.

Uploaded by

shadowiomr
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

SYMMETRIC KEY ENCRYPTION TECHNIQUES

EXPERIMENT NUMBER: 12

AIM: Perform encryption and decryption by using Caesar Cipher technique

PROCEDURE:

Caesar Cipher

Caesar Cipher is a substitution cipher where each letter in the plaintext is shifted by a
fixed number of positions in the alphabet.

Example

PlainText:HELLO
Key (Shift): 3

Encryption

Each letter is shifted 3 positions forward.

Plain Letter Position Shifted Letter

H 7 K
E 4 H
L 11 O
L 11 O
O 14 R

✅ Cipher Text:

KHOOR

Decryption

Each letter is shifted 3 positions backward.

Cipher Letter Position Original Letter


K 10 H
H 7 E
O 14 L
O 14 L
R 17 O

✅ Plain Text:

HELLO

Formula
1
 Encryption:

C=(P+K)mod 26 C = (P + K) \mod 26

 Decryption:

P=(C−K)mod 26P = (C - K) \mod 26

Where:

 P = Plain text letter position


 C = Cipher text letter position
 K = Key (shift value)

Another Example

PlainText:ATTACK
Key: 4

 Cipher Text: EXXEGO


 After Decryption: ATTACK

C language code

#include <stdio.h>

#include <ctype.h>

void caesarCipher(char text[], int key, int mode) {

for (int i = 0; text[i] != '\0'; i++) {

if (isalpha(text[i])) {

char base = isupper(text[i]) ? 'A' : 'a';

if (mode == 1) // Encryption

text[i] = (text[i] - base + key) % 26 + base;

else // Decryption

text[i] = (text[i] - base - key + 26) % 26 + base;

int main() {

char text[] = "HELLO";


2
int key = 3;

caesarCipher(text, key, 1);

printf("Encrypted Text: %s\n", text);

caesarCipher(text, key, 0);

printf("Decrypted Text: %s\n", text);

return 0;

✅ Output (All Programs)

Encrypted Text: KHOOR

Decrypted Text: HELLO

RESULT: Performing encryption and decryption by using Caesar Cipher technique was
successfully executed.

3
EXPERIMENT NUMBER: 13

AIM: Exercise encryption and decryption by using Play fair Cipher technique

PROCEDURE:

Play fair Cipher is a digraph substitution cipher, where pairs of letters are encrypted
instead of single letters.

Rules

1. Use a 5×5 matrix of letters based on a keyword.


2. Letters I and J are treated as one.
3. Plain text is divided into pairs (digraphs).
4. If both letters in a pair are same, insert X between them.
5. If the text length is odd, add X at the end.

Example (Exercise)

Key: MONARCHY

Plain Text: INSTRUMENT

Step 1: Construct 5×5 Key Matrix

Remove duplicate letters from key and fill remaining alphabets (excluding J).

Key: M O N A R C H Y

MONAR

CHYBD

EFGIK

LPQST

UVWXZ

Step 2: Prepare Plain Text

Plain Text: INSTRUMENT

 Convert J → I (if any)


 Split into pairs:

IN ST RU ME NT

Step 3: Encryption Rules

Encryption Rules Summary

 Same row → replace each letter with the one to its right
4
 Same column → replace each letter with the one below
 Rectangle rule → replace each letter with the one in the same row but opposite
column

Encrypt Each Pair

Pair Rule Cipher Pair


I N Rectangle GA
S T Same row TL
R U Rectangle MZ
M E Same column C L
N T Rectangle RQ

✅ Cipher Text:

GATLMZCLRQ

Step 4: Decryption

Decryption Rules

 Same row → move left


 Same column → move up
 Rectangle rule → same as encryption

Decrypt Cipher Text

Cipher Pair Plain Pair


GA IN
TL ST
MZ RU
CL ME
RQ NT

✅ Decrypted Text:

INSTRUMENT

Final Result

 Plain Text: INSTRUMENT


 Key: MONARCHY
 Cipher Text: GATLMZCLRQ

5
C language code

#include <stdio.h>

#include <string.h>

#include <ctype.h>

char matrix[5][5];

void generateMatrix(char key[]) {

int used[26] = {0}, i, j, k = 0;

used['J' - 'A'] = 1;

for (i = 0; key[i]; i++) {

char ch = toupper(key[i]);

if (ch < 'A' || ch > 'Z') continue;

if (!used[ch - 'A']) {

matrix[k / 5][k % 5] = ch;

used[ch - 'A'] = 1;

k++;

for (i = 0; i < 26; i++) {

if (!used[i]) {

matrix[k / 5][k % 5] = i + 'A';

k++;

void findPos(char ch, int *r, int *c) {

if (ch == 'J') ch = 'I';

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


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

if (matrix[i][j] == ch) {

*r = i; *c = j;

void playfair(char text[], int mode) {

int r1, c1, r2, c2;

for (int i = 0; i < strlen(text); i += 2) {

findPos(text[i], &r1, &c1);

findPos(text[i + 1], &r2, &c2);

if (r1 == r2) {

text[i] = matrix[r1][(c1 + mode + 5) % 5];

text[i + 1] = matrix[r2][(c2 + mode + 5) % 5];

} else if (c1 == c2) {

text[i] = matrix[(r1 + mode + 5) % 5][c1];

text[i + 1] = matrix[(r2 + mode + 5) % 5][c2];

} else {

text[i] = matrix[r1][c2];

text[i + 1] = matrix[r2][c1];

int main() {

char key[] = "MONARCHY";

char text[] = "INSTRUMENT";

generateMatrix(key);

playfair(text, 1);
7
printf("Encrypted: %s\n", text);

playfair(text, -1);

printf("Decrypted: %s\n", text);

return 0;

✅ Output (All Programs)

Encrypted: GATLMZCLRQ

Decrypted: INSTRUMENT

RESULT: Exercising encryption and decryption by using Play fair Cipher technique was
successfully completed

8
EXPERIMENT NUMNBER: 14

AIM: Exercise encryption and decryption by using Hill Cipher technique

PROCEDURE:

Hill cipher is a polygraphic substitution cipher based on linear [Link] letter is


represented by a number modulo 26. Often the simple scheme A = 0, B = 1, ..., Z = 25 is
used, but this is not an essential feature of the cipher. To encrypt a message, each block
of n letters (considered as an n-component vector) is multiplied by an invertible n × n
matrix, against modulus 26. To decrypt the message, each block is multiplied by the
inverse of the matrix used for encryption. The matrix used for encryption is the cipher key,
and it should be chosen randomly from the set of invertible n × n matrices (modulo 26).
Examples:
Input:

Plain text: ACT

Key: GYBNQKURP

Output:

Cipher text: POH

Input:

Plaintext: GFG

Key: HILLMAGIC

Output :

Cipher text: SWK

Encryption

We have to encrypt the message 'ACT' (n=3).

The key is 'GYBNQKURP' which can be written as the nxn matrix:

9
The message 'ACT' is written as vector:

The enciphered vector is given as:

Which corresponds to cipher text of ‘POH? ?'


Decryption

To decrypt the message, we turn the cipher text back into a vector, and then simply
multiply by the inverse matrix of the key matrix (IFKVIVVMI in letters).

The inverse of the matrix used in the previous example is:

For the previous Cipher text 'POH':

10
Which gives us back 'ACT'.
Assume that all the alphabets are in upper case.
Below is the implementation of the above idea for n=3.

#include <stdio.h>

void getKeyMatrix(const char* key, int keyMatrix[3][3]) {

int k = 0;

for (int i = 0; i < 3; i++) {

for (int j = 0; j < 3; j++) {

keyMatrix[i][j] = (key[k]) % 65;

k++;

void encrypt(int cipherMatrix[3][1], int keyMatrix[3][3], int messageVector[3][1]) {

int x, i, j;

for (i = 0; i < 3; i++) {

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

cipherMatrix[i][j] = 0;

for (x = 0; x < 3; x++) {

cipherMatrix[i][j] += keyMatrix[i][x] * messageVector[x][j];

cipherMatrix[i][j] = cipherMatrix[i][j] % 26;


11
}

void HillCipher(const char* message, const char* key) {

int keyMatrix[3][3];

getKeyMatrix(key, keyMatrix);

int messageVector[3][1];

for (int i = 0; i < 3; i++)

messageVector[i][0] = (message[i]) % 65;

int cipherMatrix[3][1];

encrypt(cipherMatrix, keyMatrix, messageVector);

char CipherText[4] = {0};

for (int i = 0; i < 3; i++)

CipherText[i] = (char)(cipherMatrix[i][0] + 65);

printf(" Ciphertext:%s", CipherText);

int main() {

const char* message = "ACT";

const char* key = "GYBNQKURP";

HillCipher(message, key);

return 0;

OUT PUT:

Cipher text: POH

RESULT: Exercising encryption and decryption by using Hill Cipher technique was
successfully executed.

12
EXPERIMENT NUMNBER: 15
AIM: Perform encryption and decryption by using Vigenere Cipher

PROCEDURE:

Vigenère Cipher – Overview

Vigenère Cipher is a polyalphabetic substitution cipher that uses a keyword to shift


letters.

 Encryption formula:

Ci= (Pi+Ki) mod26

 Decryption formula:

Pi= (Ci−Ki+26) mod 26

Where:

 Pi = Plain text letter (0–25)


 Ci = Cipher text letter (0–25)
 Ki = Corresponding key letter (0–25)

Example

PlainText:HELLO
Key: KEY

Step 1: Repeat Key to Match Plain Text

Plain Text: H E L L O

Key: KEYKE

Step 2: Convert Letters to Numbers

A=0, B=1, ..., Z=25

Plain Text: H=7, E=4, L=11, L=11, O=14

Key: K=10, E=4, Y=24, K=10, E=4

Step 3: Encryption

Ci=(Pi+Ki) mod 26

H+K → 7+10 = 17 → R

E+E → 4+4 = 8 → I

L+Y → 11+24 = 35 → 35 mod 26 = 9 → J

13
L+K → 11+10 = 21 → V

O+E → 14+4 = 18 → S

✅ Cipher Text: RIJVS

Step 4: Decryption

Pi=(Ci−Ki+26) mod 26

R-K → 17-10=7 → H

I-E → 8-4=4 → E

J-Y → 9-24=-15+26=11 → L

V-K → 21-10=11 → L

S-E → 18-4=14 → O

✅ Decrypted Text: HELLO

C Program – Vigenère Cipher

#include <stdio.h>

#include <string.h>

#include <ctype.h>

void encrypt(char text[], char key[], char cipher[]) {

int n = strlen(text);

int m = strlen(key);

for (int i = 0; i < n; i++) {

char t = toupper(text[i]);

char k = toupper(key[i % m]);

cipher[i] = ((t - 'A') + (k - 'A')) % 26 + 'A';

cipher[n] = '\0';

void decrypt(char cipher[], char key[], char text[]) {

int n = strlen(cipher);
14
int m = strlen(key);

for (int i = 0; i < n; i++) {

char c = toupper(cipher[i]);

char k = toupper(key[i % m]);

text[i] = ((c - k + 26) % 26) + 'A';

text[n] = '\0';

int main() {

char text[] = "HELLO";

char key[] = "KEY";

char cipher[100], decrypted[100];

encrypt(text, key, cipher);

printf("Encrypted: %s\n", cipher);

decrypt(cipher, key, decrypted);

printf("Decrypted: %s\n", decrypted);

return 0;

✅ Output (All Programs)

Encrypted: RIJVS

Decrypted: HELLO

RESULT: Performing encryption and decryption by using Vigenere Cipher was successfully
executed.

15
ASYMMETRIC KEY ENCRYPTION TECHNIQUES

EXPERIMENT NUMNBER: 16
AIM: Perform encryption and decryption using RSA public and private key.

PROCEDURE:

RSA is an asymmetric encryption technique using a public key for encryption and a
private key for decryption.

Steps:

1. Choose two prime numbers p and q.

2. Compute n=p×q (modulus).

3. Compute Euler’s totient: ϕ(n)=(p−1)(q−1)

4. Choose public exponent e such that 1<e< ϕ(n) and gcd(e, φ(n)) = 1.

5. Compute private exponent d such that (d×e)mod ϕ(n)=1


 Public key: (e,n)

 Private key: (d,n)

Encryption formula:

C=Me mod n or C = M^e \mod n

Decryption formula:

M=Cd mod n or M = C^d \mod n

Where:

 M = plain text number

 C = cipher text number

Example

Step 1: Select primes

p = 7, q = 11

Step 2: Compute n and φ(n)

n = 7 * 11 = 77

φ(n) = (7-1)*(11-1) = 6*10 = 60

Step 3: Choose e

e = 17 (1 < 17 < 60 and gcd(17,60)=1)


16
Step 4: Compute d d×17≡1mod 60→d=53

Step 5: Keys

Public key: (e=17, n=77)

Private key: (d=53, n=77)

Step 6: Encrypt Message

Plain Text M = 65 (A)

C=6517mod 77

Using modular exponentiation:

C = 65^17 mod 77 = 61

✅ Cipher Text: 61

Step 7: Decrypt Message

M=6153mod 77

Using modular exponentiation:

M = 65

✅ Decrypted Text: 65 → A

#include <stdio.h>

// Function to compute gcd of two numbers

int gcd(int a, int b) {

while (b != 0) {

int temp = b;

b = a % b;

a = temp;

return a; }

// Extended Euclidean Algorithm to find modular inverse

int modinv(int a, int m) {

int m0 = m, x0 = 0, x1 = 1;

if (m == 1) return 0;

while (a > 1) {
17
int q = a / m;

int t = m;

m = a % m;

a = t;

t = x0;

x0 = x1 - q * x0;

x1 = t;

if (x1 < 0) x1 += m0;

return x1;

// Function to perform modular exponentiation

int mod_exp(int base, int exp, int mod) {

int result = 1;

base = base % mod;

while (exp > 0) {

if (exp % 2 == 1) // If exp is odd, multiply base with result

result = (result * base) % mod;

exp = exp >> 1; // exp = exp / 2

base = (base * base) % mod;

return result;

// Encryption function

int encrypt(int M, int e, int n) {

return mod_exp(M, e, n);

// Decryption function

int decrypt(int C, int d, int n) {


18
return mod_exp(C, d, n);

int main() {

// Step 1: Choose primes

int p = 7;

int q = 11;

int n = p * q;

int phi = (p - 1) * (q - 1);

// Step 2: Choose e

int e = 17;

// Step 3: Compute d

int d = modinv(e, phi);

printf("Public key (e, n): (%d, %d)\n", e, n);

printf("Private key (d, n): (%d, %d)\n", d, n);

// Example: Encrypt 'A' → 65

int M = 65;

int C = encrypt(M, e, n);

printf("Encrypted: %d\n", C);

int D = decrypt(C, d, n);

printf("Decrypted: %d\n", D);

return 0;

✅ Output

Public key (e, n): (17, 77)

Private key (d, n): (53, 77)

Encrypted: 61

Decrypted: 65

RESULT: RSA is an asymmetric encryption technique using a public key for encryption
and a private key for decryption was successfully executed.

19
EXPERIMENT NUMNBER: 17
AIM: To perform the validation of the digital document using Digital signature standard
encryption and decryption

PROCEDURE:

A digital signature is a cryptographic technique used to:

 Verify the authenticity of a digital document

 Ensure the document has not been tampered (integrity)

 Authenticate the sender’s identity

Digital Signature Standard (DSS) is a federal standard (FIPS 186) for creating and verifying
digital signatures using the DSA (Digital Signature Algorithm).

🛠 Components of DSS

1. Private Key (Sender) – Used to sign the document

2. Public Key (Receiver) – Used to verify the signature

3. Hash Function – Computes a message digest of the document

o Common hash algorithms: SHA-256, SHA-1

4. Signature Generation & Verification Algorithms

🛠 Procedure to Validate a Digital Document

Step 1: Document Hashing (Sender Side)

 Compute hash of the document using a hash function.

 Example: SHA-256("Document") → 64-character digest

Step 2: Sign the Hash (Encryption)

 Use the sender’s private key to encrypt the hash.

 This creates the digital signature.

Signature=Encrypt Private Key(Hash(Document))

Attach the digital signature with the document.

Step 3: Send the Document

 Sender sends the document + digital signature to the receiver.

Step 4: Receiver Hashes the Document

20
 Receiver computes hash of the received document using the same hash function.

 Example: SHA-256("Received Document") → digest

Step 5: Verify Signature (Decryption)

 Receiver decrypts the digital signature using sender’s public key:

Decrypted Hash=Decrypt Public Key(Signature)

Compare decrypted hash with computed hash of the received document.

Step 6: Validation

 If hashes match → Document is authentic and unchanged

 If hashes do not match → Document is tampered or signature is invalid

RESULT: performing the validation of the digital document using Digital signature
standard encryption and decryption was successfully completed.

21
EXPERIMENT NUMNBER: 18
AIM: To perform the procedure of installation process of antivirus to detect threats.

PROCEDURE:

Antivirus software is a program that detects, prevents, and removes malicious


software (malware) such as viruses, worms, spyware, and trojans from your computer.

Purpose:

 Protects system files and data


 Monitors suspicious activities
 Removes or quarantines malware

Steps for Installation and Using Antivirus


Step 1: Choose a Trusted Antivirus

 Examples: Windows Defender, Avast, Kaspersky, Norton, Bitdefender


 Ensure the software is from an official or trusted source.
 Avoid pirated versions—they may contain malware.

Step 2: Download the Antivirus Installer

 Go to the official website of the antivirus software.


 Download the latest version compatible with your operating system (Windows,
macOS, Linux).

Step 3: Run the Installer

1. Locate the downloaded file (usually .exe on Windows).


2. Double-click to run the installer.
3. Accept the License Agreement.
4. Choose installation type:
o Typical / Recommended: Installs standard features.
o Custom: You can select features and installation folder.

Step 4: Complete Installation

 Wait until the installation completes.


 Restart the system if prompted.
 After restart, antivirus should be active and running in the background.

Step 5: Update Antivirus

 Update virus definitions immediately to detect the latest threats.


 Most anti viruses have automatic updates.

22
Step 6: Perform a System Scan

 Types of scans:
1. Quick Scan – Scans critical areas (fast).
2. Full/System Scan – Scans the entire system (recommended first time).
3. Custom Scan – Scan selected files or folders.
 Example (Windows Defender):
 Start → Windows Security → Virus & Threat Protection → Quick Scan / Full Scan
Step 7: Detect and Remove Threats

 Antivirus will list detected threats.


 Choose one of the following actions:
o Quarantine – Isolate the threat safely.
o Remove/Delete – Permanently remove malware.
o Ignore – Only if you are sure it’s safe.

Step 8: Schedule Regular Scans

 Schedule automatic scans weekly or daily.


 Keeps your system protected from new threats.

✅Example Checklist for Antivirus Procedure


Step Action

1 Choose trusted antivirus

2 Download installer from official site

3 Run installer and accept terms

4 Complete installation & restart

5 Update virus definitions

6 Perform Quick or Full scan

7 Detect and remove threats

8 Schedule regular scans

Tips for Better Protection

 Keep OS updated regularly.


 Don’t open unknown email attachments or links.
 Avoid downloading un trusted software.
 Use firewall + antivirus together for stronger security.

RESULT: performing the procedure of installation process of antivirus to detect threats


was successfully completed.
23
EXPERIMENT NUMNBER: 19
AIM: Learn the procedure to ensure security basic firewalls can be able in the system.

PROCEDURE:

A firewall is a network security system that monitors and controls incoming and
outgoing network traffic based on predefined security rules.
It acts as a barrier between trusted internal networks and untrusted external
networks (like the Internet).

Types of Firewalls

1. Hardware Firewall – A physical device used in networks.


2. Software Firewall – Installed on individual computers (e.g., Windows Defender
Firewall).
3. Network Firewall – Filters traffic between networks.
4. Host-based Firewall – Installed on a single system to monitor network traffic.

Steps to Ensure Security Using Basic Firewalls


Step 1: Enable Firewall

 Most modern OS have built-in firewalls.


o Windows: Control Panel → System and Security → Windows Defender
Firewall → Turn On
o Linux: Use ufw (Uncomplicated Firewall)
o sudo ufw enable
 Ensure firewall is active to block unwanted traffic.

Step 2: Configure Rules

 Allow trusted programs and ports (like HTTP=80, HTTPS=443, SSH=22).


 Block all unnecessary or suspicious ports.
 Example (Linux ufw):
 sudo ufw allow 22 # allow SSH
 sudo ufw deny 23 # deny Telnet
 sudo ufw status

24
Step 3: Update Firewall Regularly

 Keep firewall software up-to-date to protect against new threats.


 Install OS security updates.

Step 4: Monitor Traffic

 Use firewall logs to detect suspicious activity.


 Example (Windows): Event Viewer → Security Logs.
 Example (Linux): sudo ufw status verbose

Step 5: Use Default Deny Policy

 Default Deny: Block all traffic by default and only allow what’s necessary.
 Reduces risk of malware or unauthorized access.

Step 6: Combine Firewall with Other Security Measures

 Use antivirus/antimalware software.


 Enable automatic OS updates.
 Use strong passwords and multi-factor authentication.
 Regularly backup important data.

✅Example Basic Firewall Setup (Linux)


sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 22 # SSH
sudo ufw allow 80 # HTTP
sudo ufw allow 443 # HTTPS
sudo ufw enable
sudo ufw status

This ensures:

 Only trusted traffic is allowed


 All other traffic is blocked
 The system is protected from unauthorized access

RESULT: Learning the procedure to ensure security basic firewalls can be able in the
system was successfully completed.

25

You might also like