kapil
kapil
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)
Department of AI & ML
Practical no:- 01
Name of the practical:- XOR Each Character of a String in C.
Student Roll no:- 2101611530028
Student Name:- Kapil Sharma
#include <stdio.h>
#include <string.h>
int main() {
char str[] = "Hello world";
int i;
for(i = 0; i < strlen(str); i++) {
str[i] = str[i] ^ 0; // XOR with 0
}
printf("Resultant String: %s\n", str);
return 0;
}
Department of AI & ML
Practical no:- 02
Name of the practical:- AND & XOR Each Character of a String in C
Student Roll no:- 2101611530028
Student Name:- Kapil Sharma
#include <stdio.h>
#include <string.h>
int main() {
char str[] = "Hello world";
int i;
for(i = 0; i < strlen(str); i++) {
str[i] = (str[i] & 127) ^ 127; // AND with 127 and XOR with 127
}
printf("Resultant String: %s\n", str);
return 0;
}
Department of AI & ML
Practical no:- 03
Name of the practical:- Java Program for Caesar, Substitution, and Hill Cipher.
Student Roll no:- 2101611530028
Student Name:- Kapil Sharma
a. Caesar Cipher
b. Substitution Cipher
Department of AI & ML
}
return result.toString();
}
import java.util.Scanner;
Department of AI & ML
}
}
N = 2; // Matrix dimension
getKeyMatrix(key, N);
encrypt(message, N);
• Input:
• Key: GYBN
• Message: HI
• Output:
Encrypted Message: FN
Department of AI & ML
Practical no:- 04
Name of the practical:- DES Algorithm Logic (Java)
Student Roll no:- 2101611530028
Student Name:- Kapil Sharma
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
Department of AI & ML
Practical no:- 05
Name of the practical:- Blowfish Algorithm Logic (C/Java)
Student Roll no:- 2101611530028
Student Name:- Kapil Sharma
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
Department of AI & ML
Practical no:- 06
Name of the practical:- Rijndael Algorithm (AES) Logic in Java.
Student Roll no:- 2101611530028
Student Name:- Kapil Sharma
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
Department of AI & ML
Practical no:- 07
Name of the practical:- RC4 Logic in Java
Student Roll no:- 2101611530028
Student Name:- Kapil Sharma
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
Department of AI & ML
Practical no:- 08
Name of the practical:- RSA Algorithm (Java)
Student Roll no:- 2101611530028
Student Name:- Kapil Sharma
import java.security.*;
import javax.crypto.Cipher;
Department of AI & ML
Practical no:- 09
Name of the practical:- Diffie-Hellman Key Exchange (HTML/JS)
Student Roll no:- 2101611530028
Student Name:- Kapil Sharma
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Diffie-Hellman Key Exchange</title>
</head>
<body>
<h1>Diffie-Hellman Key Exchange</h1>
<div>
<label for="prime">Prime number (p): </label>
<input type="number" id="prime" value="23">
</div>
<div>
<label for="base">Base (g): </label>
<input type="number" id="base" value="5">
</div>
<div>
<label for="private-key">Your private key (a/b): </label>
<input type="number" id="private-key" value="6">
</div>
<div>
<button onclick="performKeyExchange()">Compute Shared Key</button>
</div>
<div>
<h2>Results:</h2>
<p id="shared-key"></p>
</div>
<script>
function performKeyExchange() {
// Getting values from the inputs
const p = parseInt(document.getElementById("prime").value); // prime number
const g = parseInt(document.getElementById("base").value); // base
const privateKey = parseInt(document.getElementById("private-key").value); //
private key
// Step 2: Compute public key for B (Bob) with different private key
KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)
Department of AI & ML
const privateKeyB = 15; // You can set this manually or as a random number
const publicKeyB = Math.pow(g, privateKeyB) % p;
// Step 3: Compute shared keys using the other's public key and private key
const sharedKeyA = Math.pow(publicKeyB, privateKey) % p; // Alice computes using
Bob's public key
const sharedKeyB = Math.pow(publicKeyA, privateKeyB) % p; // Bob computes using
Alice's public key
Input:
Output:
Department of AI & ML
Practical no:- 10
Name of the practical:- SHA-1 Message Digest in Java
Student Roll no:- 2101611530028
Student Name:- Kapil Sharma
import java.security.MessageDigest;
Department of AI & ML
Practical no:- 11
Name of the practical:- MD5 Message Digest in Java
Student Roll no:- 2101611530028
Student Name:- Kapil Sharma
import java.security.MessageDigest;