IS Krishna (4-10)
IS Krishna (4-10)
IS Krishna (4-10)
Experiment No: 4
To implement Simple DES encryption-decryption.
Date:
Relevant CO: Implement and analyze various symmetric key cryptography algorithms
and their application in different context
Example:
3170720 INFORMATION SECURITY 210170107518
Algorithm:
STEP-5: Thus the encrypted 64-bit cipher text is obtained in this way. Repeat the same
process for the remaining plain text characters.
Program:
#include <iostream>
//Functions
void printArray(int arr[],int n)
{
for (int i = 0; i < n; i++)
cout << arr[i] << " ";
cout << endl;
}
opSn = opSn/2;
}
}
//S1
int rowS1bin[2] = {b[0],b[3]}, colS1bin[2] = {b[1],b[2]};
int rowS1dec = bin2dec(rowS1bin,2), colS1dec = bin2dec(colS1bin,2);
int opS1dec = S1[rowS1dec][colS1dec];
int opS1bin[2]={};
dec2bin(opS1dec, opS1bin);
class KeyGeneration {
private:
int P10_rule[10] = {3,5,2,7,4,10,1,9,8,6};
int P8_rule[8] = {6,3,7,4,8,5,10,9};
int temp_left[5]={}, temp_right[5]={};
public:
KeyGeneration(){
cout<<endl;
cout<<"KEY GENERATION.."<<endl;
cout<<endl;
}
void key(int master_key[], int *k1, int *k2){
//P10
Permutation(master_key,P10_rule,10);
cout<<"After P10 Permutation: ";
printArray(master_key,10);
cout<<endl;
//Split
Split(master_key,10,temp_left,temp_right);
cout<<"After split, "<<endl;
cout<<"l = ";
printArray(temp_left,5);
cout<<"r = " ;
printArray(temp_right,5);
cout<<endl;
//LS-1
leftRotate(temp_left,1,5);
leftRotate(temp_right,1,5);
cout<<"After LeftShift-1, "<<endl;
cout<<"l = ";
printArray(temp_left,5);
cout<<"r = ";
printArray(temp_right,5);
cout<<endl;
//P-8
combine(temp_left,temp_right,master_key,10);
Permutation(master_key,P8_rule,10);
cout<<"After P8, Key-1: ";
for(int i=0;i<8;i++)
k1[i]=master_key[i];
printArray(k1,8);
cout<<endl;
//LS-2
leftRotate(temp_left,2,5);
leftRotate(temp_right,2,5);
cout<<"After LeftShift-2, "<<endl;
cout<<"l = ";
printArray(temp_left,5);
cout<<"r = ";
printArray(temp_right,5);
cout<<endl;
//P-8
3170720 INFORMATION SECURITY 210170107518
combine(temp_left,temp_right,master_key,10);
Permutation(master_key,P8_rule,10);
cout<<"After P8, Key-2: ";
for(int i=0;i<8;i++)
k2[i]=master_key[i];
printArray(k2,8);
}
};
class Roundfunction{
private:
int Expanrule[8] = {4,1,2,3,2,3,4,1};
int P4_rule[4] = {2,4,3,1};
int r_arr2[8]={},a[4]={},b[4]={};
int opS0S1[4]={};
public:
void roundfun(int *k1,int *l_arr, int *r_arr, int *fk1){
ExPermutation(r_arr, Expanrule, r_arr2,8);
cout<<"After EP: ";
printArray(r_arr2,8);
cout<<endl;
//XOR with K1
XOR(k1,r_arr2,8);
cout<<"XOR with key"<<endl;
printArray(r_arr2,8);
cout<<endl;
//Split
Split(r_arr2,8,a,b);
cout<<"After Split"<<endl;
cout<<"l = ";
printArray(a,4);
cout<<"r = ";
printArray(b,4);
cout<<endl;
//Sbox
S_box(a,b,opS0S1);
//P4
Permutation(opS0S1,P4_rule,4);
cout<<"After P4"<<endl;
printArray(opS0S1,4);
cout<<endl;
//XOR with left array
XOR(opS0S1,l_arr,4);
cout<<"XOR with leftarray"<<endl;
printArray(l_arr,4);
cout<<endl;
//combine
combine(l_arr,r_arr,fk1,8);
cout<<"After combine"<<endl;
printArray(fk1,8);
cout<<endl;
}
};
public:
encrypt(){
cout<<endl;
cout<<"ENCRYPTING.."<<endl;
cout<<endl;
}
int l_arr[4]={},r_arr[4]={};
//IP
void enc(int arr[], int *key1, int *key2, int *fk1){
public:
int l_arr[4]={},r_arr[4]={};
//IP
void decryp(int arr[], int *key1, int *key2, int *fk1){
cout<<"Split"<<endl;
printArray(l_arr,4);
printArray(r_arr,4);
//fk1
Roundfunction::roundfun(key2,l_arr,r_arr,fk1);
//Swap
Swap(l_arr,r_arr,4);
cout<<"swap"<<endl;
printArray(l_arr,4);
printArray(r_arr,4);
//fk2
Roundfunction::roundfun(key1,l_arr,r_arr,fk1);
//ipinv
Permutation(fk1,IP_inv_rule,8);
cout<<"After IP-Inverse, 8-bit Plain Text is: "<<endl;
printArray(fk1,8);
}
};
int main()
{
char input;
int arr[8]={};
int master_key[10]={};
int k1[8]={},k2[8]={};
int fk1[8] = {};
//Key
cout<<"Enter 10-bit Master Key (using space)"<<endl;
for(int i=0;i<10;i++){
cin>>master_key[i];
}
if((sizeof(master_key)/sizeof(master_key[0]))!=10)
throw "Error. Enter 10-bits";
KeyGeneration k;
k.key(master_key,k1,k2);
cout<<"_____________________________________________________________________________"<<e
ndl;
cout<<endl;
cout<<"Enter e for Encryption | Enter d for Decryption | Enter b for Both"<<endl;
cin>>input;
}
if((sizeof(arr)/sizeof(arr[0]))!=8)
throw "Error. Enter 8-bits";
encrypt e;
e.enc(arr,k1,k2,fk1);
}
else if (input == 'd'||input == 'D'){
cout<<"Enter 8-bit Cipher Text (using space)"<<endl;
for(int i=0;i<8;i++){
cin>>arr[i];
}
if((sizeof(arr)/sizeof(arr[0]))!=8)
throw "Error. Enter 8-bits";
decrypt d;
d.decryp(arr,k1,k2,fk1);
}
else
throw "Error, Choose correct option";
return 0;
}
Output:
3170720 INFORMATION SECURITY 210170107518
Conclusion:
The provided program is intended to demonstrate Simplified DES (S-DES) encryption and decryption in C++.
However, the program contained errors in its initial implementation, and after correction, it successfully
encrypts and decrypts 8-bit plaintext with a 10-bit key using the S-DES algorithm, providing the expected
ciphertext and plaintext results.
Quiz:
1. DES works on 64-bits size of blocks ?
Suggested Reference:
1. https://www.tutorialspoint.com/cryptography/data_encryption_standard.htm
References used by the students:
https://www.geeksforgeeks.org/simplified-data-encryption-standard-key-generation/
Rubrics 1 2 3 4 5 Total
Marks
3170720 INFORMATION SECURITY 210170107518
Experiment No: 5
To implement Simple AES encryption-decryption.
Date:
Relevant CO: Implement and analyze various symmetric key cryptography algorithms
and their application in different context
Example:
Algorithm:
Program:
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Scanner;
while (!exit) {
System.out.println("\n=== Enhanced AES Encryption and Decryption ===");
System.out.println("1. Encrypt");
System.out.println("2. Decrypt");
System.out.println("3. Exit");
System.out.print("Enter your choice (1/2/3): ");
int choice = scanner.nextInt();
scanner.nextLine(); // Consume the newline
switch (choice) {
case 1:
System.out.print("Enter a 16-byte encryption key (e.g., 16 characters): ");
String keyString = scanner.nextLine();
SecretKey secretKey = new SecretKeySpec(keyString.getBytes(StandardCharsets.UTF_8), "AES");
case 2:
System.out.print("Enter a 16-byte encryption key (e.g., 16 characters): ");
keyString = scanner.nextLine();
secretKey = new SecretKeySpec(keyString.getBytes(StandardCharsets.UTF_8), "AES");
case 3:
exit = true;
3170720 INFORMATION SECURITY 210170107518
default:
System.out.println("Invalid choice. Please enter 1, 2, or 3.");
break;
}
}
}
Output:
3170720 INFORMATION SECURITY 210170107518
Conclusion:
The provided Java program offers a simple demonstration of AES encryption and decryption using a fixed 128-
bit key and block size. It allows users to choose between encryption and decryption, providing a basic example
of these operations while emphasizing the importance of using the correct key for decryption to avoid
"BadPaddingException" errors.
Quiz:
Suggested Reference:
1. https://www.geeksforgeeks.org/advanced-encryption-standard-aes/
Rubrics 1 2 3 4 5 Total
Marks
3170720 INFORMATION SECURITY 210170107518
Experiment No: 6
To implement Simple RSA encryption-decryption.
Date:
Relevant CO: Compare public key cryptography with private key cryptography and
Implement various asymmetric key cryptography algorithms
(me)d = m (mod n)
The public key is represented by the integers n and e; and, the private key, by the integer d. m represents
the message. RSA involves a public key and a private key. The public key can be known by everyone
and is used for encrypting messages. The intention is that messages encrypted with the public key can
only be decrypted in a reasonable amount of time using the private key.
Example:
3170720 INFORMATION SECURITY 210170107518
Algorithm:
Program:
import java.math.BigInteger;
import java.util.Scanner;
while (true) {
System.out.println("1. Encrypt");
System.out.println("2. Decrypt");
System.out.println("3. Exit");
System.out.print("Enter your choice (1/2/3): ");
int choice = scanner.nextInt();
if (choice == 3) {
System.out.println("Exiting the program. Farewell!");
break;
}
switch (choice) {
case 1:
performEncryption(scanner);
break;
case 2:
performDecryption(scanner);
break;
default:
System.out.println("Invalid choice. Please try again.");
}
}
}
Output:
Conclusion:
The provided Java program demonstrates a simplified version of RSA encryption and decryption using small
values for educational purposes. Users can choose between encryption and decryption, entering plaintext,
ciphertext, and key values. In a real-world context, RSA encryption involves large prime numbers and security
considerations, which are not addressed in this simplified example.
3170720 INFORMATION SECURITY 210170107518
Quiz:
Suggested Reference:
1. https://www.cemc.uwaterloo.ca/resources/real-world/RSA.pdf
https://cppsecrets.com/users/1004910997104971161111071171109710849496410310997105108469
9111109/C00-RSA-Cryptography-Algorithm-Implementation.php
Rubrics 1 2 3 4 5 Total
Marks
3170720 INFORMATION SECURITY 210170107518
Experiment No: 7
Implement the Diffi-Hellman Key Exchange Method.
Date:
Relevant CO: Compare public key cryptography with private key cryptography and
Implement various asymmetric key cryptography algorithms
Example:
Algorithm:
STEP-1: Both Alice and Bob shares the same public keys g and p.
STEP-2: Alice selects a random public key a.
STEP-3: Alice computes his secret key A as ga mod p.
STEP-4: Then Alice sends A to Bob.
STEP-5: Similarly Bob also selects a public key b and computes his secret key as Band
sends the same back to Alice.
STEP-6: Now both of them compute their common secret key as the other one’s secretkey
power of a mod p.
3170720 INFORMATION SECURITY 210170107518
Program:
import java.util.Scanner;
import java.math.BigInteger;
while (!exit) {
System.out.println("== Diffie-Hellman Key Exchange ==");
System.out.println("1. Generate Public Key");
System.out.println("2. Compute Shared Secret Key");
System.out.println("3. Exit");
System.out.print("Enter your choice (1/2/3): ");
switch (choice) {
case 1:
generatePublicKey(scanner);
break;
case 2:
computeSharedSecret(scanner);
break;
case 3:
exit = true;
System.out.println("Exiting...");
break;
default:
System.out.println("Invalid choice. Please enter 1, 2, or 3.");
}
}
}
Output:
Conclusion:
The provided Java program demonstrates a simplified version of the Diffie-Hellman key exchange method.
Users can choose to generate public keys or compute a shared secret key. Proper initialization of variables is
crucial, and in real-world applications, larger prime numbers and security considerations would be necessary.
Quiz:
1. Suppose that two parties A and B wish to set up a common secret key (D-H key) between
3170720 INFORMATION SECURITY 210170107518
themselves using the Diffie Hellman key exchange technique. They agree on 7 as the modulus
and 3 as the primitive root. Party A chooses 2 and party B chooses 5 as their respective secrets.
Their D-H key is ?
If Party A chooses 2 and Party B chooses 5 as their respective secret values, and they are using a modulus
of 7 and a primitive root of 3 in the Diffie-Hellman key exchange, their shared secret key can be computed
as follows: Party A computes: 25 mod 7 = 32 mod 7 = 4 Party B computes: 52 mod 7 = 25 mod 7 = 4 Both
parties will have the shared secret key of 4.
Suggested Reference:
1. https://www.techtarget.com/searchsecurity/definition/Diffie-Hellman-key-exchange
Rubrics 1 2 3 4 5 Total
Marks
3170720 INFORMATION SECURITY 210170107518
Experiment No: 8
Write a program to generate MD5 hash.
Date:
Relevant CO: Explore the concept of hashing and implement various hashing
algorithms for message integrity
Example:
3170720 INFORMATION SECURITY 210170107518
Algorithm:
STEP-3: Compute the functions f, g, h and i with operations such as, rotations,
permutations, etc,.
STEP-4: The output of these functions are combined together as F and performed
circular shifting and then given to key round.
STEP-5: Finally, right shift of ‘s’ times are performed and the results are combinedtogether to
produce the final output.
Program:
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Scanner;
return uniqueHexString.toString();
} catch (NoSuchAlgorithmException e) {
// Handle the exception appropriately (e.g., log or print an error message)
e.printStackTrace();
return null;
}
}
}
3170720 INFORMATION SECURITY 210170107518
Output:
Conclusion:
The Java program provided allows for user interaction to generate MD5 hashes of input strings. It utilizes the
`MessageDigest` class to compute the MD5 hash and then presents the hash as a hexadecimal string. This
program can be useful for generating MD5 hashes for various purposes, such as verifying the integrity of data
or storing hashed passwords securely.
Quiz:
Suggested Reference:
1. https://www.simplilearn.com/tutorials/cyber-security-tutorial/md5-algorithm
Rubrics 1 2 3 4 5 Total
Marks
3170720 INFORMATION SECURITY 210170107518
Experiment No: 9
Write a program to generate SHA-1 hash.
Date:
Relevant CO: Explore the concept of hashing and implement various hashing
algorithms for message integrity
Example:
Algorithm:
STEP-5: The block A is shifted right by ‘s’ times and permuted with the result of step-4.
STEP-6: Then it is permuted with a weight value and then with some other key pair and
taken as the first block.
STEP-7: Block A is taken as the second block and the block B is shifted by ‘s’ times and
taken as the third block.
STEP-8: The blocks C and D are taken as the block D and E for the final output.
Program:
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Scanner;
return hexString.toString();
} catch (NoSuchAlgorithmException e) {
// Handle the exception appropriately (e.g., log or print an error message)
e.printStackTrace();
return null;
}
}
}
Output:
3170720 INFORMATION SECURITY 210170107518
Conclusion:
The Java program provided enables user interaction to generate SHA-1 hashes for input strings. It employs the
`MessageDigest` class to compute the SHA-1 hash and displays the hash as a hexadecimal string. This program
can be useful for various security and data integrity applications.
Quiz:
Suggested Reference:
1. https://www.geeksforgeeks.org/sha-1-hash-in-java/.
Rubrics 1 2 3 4 5 Total
Marks
3170720 INFORMATION SECURITY 210170107518
Experiment No: 10
Implement a digital signature algorithm.
Date:
Relevant CO: Explore and use the techniques and standards of digital signature, key
management and authentication
Example:
Algorithm:
Program:
import java.security.*;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.Signature;
import java.util.Base64;
import java.util.Scanner;
public static boolean verifySignature(String message, byte[] signature, PublicKey publicKey) throws
Exception {
Signature verifySignature = Signature.getInstance("SHA256withRSA");
verifySignature.initVerify(publicKey);
verifySignature.update(message.getBytes());
return verifySignature.verify(signature);
}
}
3170720 INFORMATION SECURITY 210170107518
Output:
Conclusion:
The Java program provides a basic demonstration of digital signature generation and verification using RSA
with SHA-256. It allows users to input a message, sign it, and then verify the signature's authenticity. In a real-
world application, secure key management and additional security measures would be necessary.
Quiz:
These two sub-algorithms work together to ensure the security and trustworthiness of digital
signatures
Suggested Reference:
1. https://www.geeksforgeeks.org/digital-signature-standard-dss/
Rubrics 1 2 3 4 5 Total
Marks
3170720 INFORMATION SECURITY 210170107518
Introduction:
The CrypTool installation is simple: download and extract the zip archive, launch the main
program and get started.
Encryption
1. Open the Cryptool UI and the document that needs to be encrypted.
3. Select Caesar mode and the “alphabet character” is “N.” That means that the text will have
characters replaced starting with N. So A >N, B>M, and so on. Click on “encrypt.”
4. The document is encrypted as per the configured policy. This is a very basic example of how
symmetric encryption works.
3170720 INFORMATION SECURITY 210170107518
Decryption process
Conclusion:
In this study, we explored the fundamental concepts of cryptography and cryptanalysis using CrypTool. We
learned how to use the CrypTool software to perform encryption and decryption, with a specific demonstration
of the Caesar encryption algorithm. This hands-on experience provided insights into the basics of symmetric
3170720 INFORMATION SECURITY 210170107518
encryption and decryption, emphasizing the importance of a shared secret (the alphabet character 'N') for secure
communication. Overall, the exercise helped to gain a practical understanding of cryptographic techniques and
tools.
Suggested Reference:
1. https://www.c-sharpcorner.com/article/encryption-decryption-using-cryptool/