New Crypto Lab File
New Crypto Lab File
I. Caesar Cipher:
Encryption:
1. Choose a shift value, for example, 3.
2. Shift each letter in the plaintext by the chosen value.
3. Wrap around the alphabet if necessary (e.g., shifting 'z' by 3 becomes 'c').
Example:
Decryption:
1. Shift each letter in the encrypted text back by the same value.
Example:
Key: KEYWORD
Plain text: HELLO
Encrypted text: RIJVS
Decryption:
1. Apply the reverse Playfair rules to each pair of letters in the ciphertext to get the original
plaintext.
Decryption:
1. Calculate the modular inverse of the key matrix.
3. Add the corresponding letters of the keyword and plaintext, modulo 26.
Example:
Keyword: KEYKEY
Plain text: HELLO
Encrypted text: RIJVS
Decryption:
1. Subtract the corresponding letters of the repeated keyword from the ciphertext, modulo
26.
Please note that these are simplified explanations. In real-world scenarios, additional steps
might be necessary for security purposes, such as handling spaces, special characters, or
implementing padding.
Experiment 2
AIM - Perform Encryption, decryption using transposition techniques.
Example:
Plain text: "HELLO WORLD"
Number of Rails: 3
Arranging on Rails:
Decryption:
1. Write the ciphertext diagonally on the same number of rails.
2. Read off the plaintext from the rows.
Keyword: "KEY"
Arranging in Columns:
Decryption:
1. Arrange the columns based on the keyword.
2. Read off the plaintext from the rows.
Please note that in real-world applications, additional steps might be needed for security
purposes, such as handling spaces, special characters, or padding. The choice of the number
of rails or the keyword for columnar transposition significantly affects the resulting
ciphertext.
Experiment 3
Apply- DES algorithm for practical application.
Implementing the Data Encryption Standard (DES) algorithm from scratch requires a deep
understanding of cryptography and programming. DES involves a series of complex steps,
including permutation, substitution, and bitwise operations. Here, I'll outline the general
steps involved in DES encryption and decryption for a practical application. Keep in mind that
DES is no longer considered secure for most applications due to its short key length (56 bits).
Key Generation:
Encryption:
1. Initial Permutation (IP): The 64-bit plaintext is permuted.
2. Rounds (16 Rounds): The data undergoes a series of substitutions, permutations, and XOR
operations using the subkeys generated in the key generation step.
3. Final Permutation (FP): After the rounds, the 64-bit data is permuted again.
Decryption:
1. Initial Permutation (IP): Same as in encryption, the ciphertext undergoes an initial
permutation.
2. Rounds (16 Rounds, but in reverse order): The subkeys are used in reverse order in
decryption.
3. Final Permutation (FP): Same as in encryption, the result is permuted to get the
original plaintext.
Practical Implementation:
Implementing DES from scratch requires programming skills and a good understanding of
bitwise operations. You can use programming languages like Python, Java, or C++ for this
task. For Python, you might use bit manipulation and permutation techniques to perform the
necessary operations.
In this example, the `Crypto.Cipher` library provides an easy way to use DES encryption and
decryption. Note that using libraries is advisable for production applications, as they are
optimized and secure. This example uses Electronic CodeBook (ECB) mode, but for secure
applications, you should consider using other modes like Cipher Block Chaining (CBC) along
with proper initialization vectors. Always handle keys and sensitive data securely.
Experiment 4
AIM - Apply AES algorithm for practical application.
Implementing the Advanced Encryption Standard (AES) algorithm for practical applications
involves using established libraries and frameworks due to the complexity of the algorithm.
Here's how you can use the PyCryptodome library in Python, which provides a simple and
secure way to implement AES encryption and decryption.
First, you need to install the PyCryptodome library if you haven't already. You can install it
using pip:
2. Encryption: The data is encrypted using AES in CBC (Cipher Block Chaining) mode. The
`pad()` function is used to ensure that the data length is a multiple of the block size. The
ciphertext is printed in hexadecimal format.
3. Decryption: The ciphertext is decrypted using the same key and initialization vector (iv)
used in encryption. The `unpad()` function is used to remove the padding, and the
decrypted plaintext is printed.
Experiment 5
//
//Javascript code for this approach
function gcd(a, h) {
/*
* This function returns the gcd or greatest common
* divisor
*/
let temp;
while (true) {
temp = a % h;
if (temp == 0) return h;
a = h;
h = temp;
}
}
let p = 3;
let q = 7;
// Message to be encrypted
let msg = 12;
// Encryption c = (msg ^ e) % n
let c = Math.pow(msg, e);
c = c % n;
console.log("Encrypted data = " + c);
// Decryption m = (c ^ d) % n
let m = Math.pow(c, d);
m = m % n;
console.log("Original Message Sent = " + m);
Here is the code of RSA In HTML -
<html>
<head>
<title>RSA Encryption</title>
<meta name="viewport" content="width=device-width, initialscale=1.0">
</head>
<body>
<h1 style="text-align: center;">RSA Algorithm</h1>
<h2 style="text-align: center;">Implemented Using HTML & Javascript</h2>
<hr>
<table class="center">
<tr>
<td>Enter P:</td>
<td><input type="number" value="53" id="p"></td>
</tr>
<tr>
<td>Enter Q :</td>
<td><input type="number" value="59" id="q"></p>
</td>
</tr>
<tr>
<td>Enter the Message:<br>[A=1, B=2,...]</td>
<td><input type="number" value="89" id="msg"></p>
</td>
</tr>
<tr>
<td>Public Key(N):</td>
<td>
<p id="publickey(N)"></p>
</td>
</tr>
<tr>
<td>Exponent(e):</td>
<td>
<p id="exponent(e)"></p>
</td>
</tr>
<tr>
<td>Private Key(d):</td>
<td>
<p id="privatekey(d)"></p>
</td>
</tr>
<tr>
<td>Cipher Text(c):</td>
<td>
<p id="ciphertext(ct)"></p>
</td>
</tr>
<tr>
<td><button onclick="RSA();">Apply RSA</button></td>
</tr>
</table>
</body>
<style>
.center {
margin-left: auto;
margin-right: auto;
}
</style>
<script type="text/javascript">
function RSA() {
var gcd, p, q, no, n, t, e, i, x;
gcd = function (a, b) { return (!b) ? a : gcd(b, a % b); };
p = document.getElementById('p').value;
q = document.getElementById('q').value;
no = document.getElementById('msg').value;
n = p * q;
t = (p - 1) * (q - 1);
for (e = 2; e < t; e++) {
if (gcd(e, t) == 1) {
break;
}
}
for (i = 0; i < 10; i++) {
x = 1 + i * t
if (x % e == 0) {
d = x / e;
break;
}
}
ctt = Math.pow(no, e).toFixed(0);
ct = ctt % n;
dtt = Math.pow(ct, d).toFixed(0);
dt = dtt % n;
document.getElementById('publickey(N)').innerHTML = n;
document.getElementById('exponent(e)').innerHTML = e;
document.getElementById('privatekey(d)').innerHTML = d;
document.getElementById('ciphertext(ct)').innerHTML = ct;
}
</script>
</html>
Experiment 6
AIM - Implement the diffie-hellman key Exchange algorithm for
given problem.
Implementation -:
1. We will take four variables, i.e., P (prime), G (the primitive root of P), and a
and b (private values).
2. The variables P and G both are publicly available. The sender selects a private
value, either a or b, for generating a key to exchange publicly. The receiver
receives the key, and that generates a secret key, after which the sender and
receiver both have the same secret key to encrypt.
Let's understand the process step by step for user1 (sender) and user2 (receiver):
Now, let's implement the Java code for the Diffie-Hellman algorithm:
DiffieHellmanAlgorithmExample.java
1. import java.util.*;
2. // create class DiffieHellmanAlgorithmExample to calculate the key for two per
sons
3. class DiffieHellmanAlgorithmExample {
4. // main() method start
5. public static void main(String[] args)
6. {
7. long P, G, x, a, y, b, ka, kb;
8. // create Scanner class object to take input from user
9. Scanner sc = new Scanner(System.in);
10. System.out.println("Both the users should be agreed upon the public keys
G and P");
11. // take inputs for public keys from the user
12. System.out.println("Enter value for public key G:");
13. G = sc.nextLong();
14. System.out.println("Enter value for public key P:");
15. P = sc.nextLong();
16. // get input from user for private keys a and b selected by User1 and User
2
17. System.out.println("Enter value for private key a selected by user1:");
18. a = sc.nextLong();
19. System.out.println("Enter value for private key b selected by user2:");
20. b = sc.nextLong();
21.
22. // call calculatePower() method to generate x and y keys
23. x = calculatePower(G, a, P);
24. y = calculatePower(G, b, P);
25. // call calculatePower() method to generate ka and kb secret keys after th
e exchange of x and y keys
26. // calculate secret key for User1
27. ka = calculatePower(y, a, P);
28. // calculate secret key for User2
29. kb = calculatePower(x, b, P);
30. // print secret keys of user1 and user2
31. System.out.println("Secret key for User1 is:" + ka);
32. System.out.println("Secret key for User2 is:" + kb);
33. }
34. // create calculatePower() method to find the value of x ^ y mod P
35. private static long calculatePower(long x, long y, long P)
36. {
37. long result = 0;
38. if (y == 1){
39. return x;
40. }
41. else{
42. result = ((long)Math.pow(x, y)) % P;
43. return result;
44. }
45. }
46. }
47.
Experiment 7
AIM - calculate the message digest of a text using the SHA-1 Algorithm.
<!DOCTYPE html>
<html>
<head>
<script src=
"https://cdnjs.cloudflare.com/ajax/libs/js-
sha1/0.6.0/sha1.min.js">
</script>
</head>
<body>
<h1>GeeksforGeeks</h1>
<p id="pId"></p>
<p id="pId2"></p>
<script>
</script>
</body>
</html>
Output -
GeeksforGeeks
JavaScript sha1 Hash function
hello world : 2aae6c35c94fcfb415dbe95f408b9ce91ee846ed
GeeksForGeeks : addf120b430021c36c232c99ef8d926aea2acd6b
Experiment 8
AIM - Implement the SIGNATURE schme- digital signature standard.
snort is one of the best known and widely used network intrusion
detection systems (NIDS). It has been called one of the most important
open-source projects of all time. Originally developed by Sourcefire, it has
been maintained by Cisco's Talos Security Intelligence and Research
Group since Cisco acquired Sourcefire in 2013.
• Community Rules: These are freely available rule sets, created by the Snort
user community.
• Registered Rules: These rule sets are provided by Talos. They are freely
available also, but you must register to obtain them. Registration is free and
only takes a moment. You'll receive a personal oinkcode that you need to
include in the download request.
• Subscription Rules: These are the same rules as the registered rules.
However, subscribers receive the rules about a month before they're released
as free rule sets for registered users. At the time of writing, 12-month
subscriptions start at USD $29 for personal use and USD $399 for business
use.
Then for ip
Press "Tab" to highlight the "OK" button, and press "Enter."
Experiment 10
AIM - Automated Attack and penetration tool Exploring N-stalker,a
vulnerability Assessment tool