Professional Documents
Culture Documents
Information Security
(3170720)
B.E. Semester 7
(Computer Engineering)
Directorate of Technical
Education,Gandhinagar,Gujarat
Government Engineering College, Modasa
CERTIFICATE
This is to certify that Mr. Sonagara Jigna Jayanatibhai Enrollment No. 200160107075
of B.E. Semester 7th Computer Engineering Department of this Institute (GTU Code:
016) has satisfactorily completed the Practical / Tutorial work for the subject Artificial
Intelligence (3170716) for the academic year 2023-24.
Date:
Main motto of any laboratory/practical/field work is for enhancing required skills as well as creating
ability amongst students to solve real time problem by developing relevant competencies in
psychomotor domain.By keeping in view, GTU has designed competency focused outcome-based
curriculum for engineering degree programs where sufficient weightage is given to practical work. It
shows importance of enhancement of skills amongst the students and it pays attention to utilize every
second of time allotted for practical amongst students, instructors and faculty members to achieve
relevant outcomes by performing the experiments rather than having merely study type experiments.
It is must for effective implementation of competency focused outcome-basedcurriculum that every
practical is keenly designed to serve as a tool to develop and enhance relevant competency required
by the various industry among every student. These psychomotor skills are very difficult to develop
through traditional chalk and board content delivery method in the classroom. Accordingly, this lab
manual is designed to focus on the industry defined relevant outcomes, rather than old practice of
conducting practical to prove concept and theory.
By using this lab manual students can go through the relevant theory and procedure in advance before
the actual performance which creates an interest and students can have basic idea prior to performance.
This in turn enhances pre-determined outcomes amongst students. Each experiment in this manual
begins with competency, industry relevant skills, course outcomes as well as practical outcomes
(objectives). The students will also achieve safety and necessary precautions to be taken while
performing practical.
This manual also provides guidelines to faculty members to facilitate student centric lab activities
through each experiment by arranging and managing necessary resources in order that the students
follow the procedures with required safety and necessary precautions to achieve the outcomes. It also
gives an idea that how students will be assessed by providing rubrics.
Information security is the subject that helps students to understand various aspects of data security. It
provides a way to know various kinds of breaches that happen with data and how to eliminate them
using various techniques. The student is also able to learn various methodologies which used by current
used by developers to achieve the security of information.
Practical – Course Outcome matrix
The following industry relevant competency are expected to be developed in the student by
undertaking the practical work of this laboratory.
1. Able to think about information security scenario and make solution
2. Able to develop and algorithms which helps to secure data
Total
OBJECTIVES:
The student should be made to:
OUTCOMES:
At the end of the course, the student should be able to:
SOFTWARE REQUIREMENTS
HARDWARE REQUIREMENTS
➢ Standalone desktops
Information Security (3170720)
Experiment No: 1
Implementation of caesar cipher
Date:
Relevant CO: Explore the basic principles of the symmetric cryptography and techniques with their
strengths and weaknesses from perspective of cryptanalysis
Example:
Algorithm:
1
Information Security (3170720)
Program:
#include <stdio.h>
#include <string.h>
int main(void) {
char plain_text[] = "helloworld";
printf("plaintext : %s\n", plain_text);
encrypt_text(plain_text, 1);
printf("encrypted : %s\n", plain_text);
decrypt_text(plain_text, 1);
printf("decrypted : %s\n", plain_text);
return 0;
}
Output:
Conclusion:
Caesar cipher algorithm can be implemented in many encryption projects to make data secure and
better. Security is one of the important aspects in computing.
Quiz:
2
Information Security (3170720)
Suggested Reference:
1. https://www.geeksforgeeks.org/caesar-cipher-in-cryptography/
Rubrics 1 2 3 4 5 Total
Marks
3
Information Security (3170720)
Experiment No: 2
Implementation of Playfair cipher
Date:
Relevant CO: Explore the basic principles of the symmetric cryptography and techniques with their
strengths and weaknesses from perspective of cryptanalysis
1. If both letters are the same (or only one letter is left), add an "X" after the first letter
2. If the letters appear on the same row of your table, replace them with the letters to
their immediate right respectively
3. If the letters appear on the same column of your table, replace them with the letters
immediately below respectively
If the letters are not on the same row or column, replace them with the letters on the same row
respectively but at the other pair of corners of the rectangle defined by the original pair.
Example:
4
Information Security (3170720)
Algorithm:
Program:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 30
// a 26 character hashmap
// to store count of the alphabet
dicty = (int *)calloc(26, sizeof(int));
for (i = 0; i < ks; i++) {
if (key[i] != 'j')
dicty[key[i] - 97] = 2;
}
5
Information Security (3170720)
dicty['j' - 97] = 1;
i = 0;
j = 0;
if (a == 'j')
a = 'i';
else if (b == 'j')
b = 'i';
if (keyT[i][j] == a) {
arr[0] = i;
arr[1] = j;
} else if (keyT[i][j] == b) {
arr[2] = i;
arr[3] = j;
}
}
}
}
6
Information Security (3170720)
str[ptrs++] = 'z';
str[ptrs] = '\0';
}
return ptrs;
}
if (a[0] == a[2]) {
str[i] = keyT[a[0]][mod5(a[1] + 1)];
str[i + 1] = keyT[a[0]][mod5(a[3] + 1)];
} else if (a[1] == a[3]) {
str[i] = keyT[mod5(a[0] + 1)][a[1]];
str[i + 1] = keyT[mod5(a[2] + 1)][a[1]];
} else {
str[i] = keyT[a[0]][a[3]];
str[i + 1] = keyT[a[2]][a[1]];
}
}
}
// Key
ks = strlen(key);
ks = removeSpaces(key, ks);
toLowerCase(key, ks);
// Plaintext
ps = strlen(str);
toLowerCase(str, ps);
ps = removeSpaces(str, ps);
ps = prepare(str, ps);
// Driver code
int main() {
char str[SIZE], key[SIZE];
// Key to be encrypted
strcpy(key, "monarchy");
printf("Key text: %s\n", key);
// Plaintext to be encrypted
strcpy(str, "helloworld");
printf("Plain text: %s\n", str);
7
Information Security (3170720)
return 0;
}
Output:
Conclusion:
The Playfair cipher is relatively fast and doesn't require special equipment and can be used to encrpyt
data to pass securely in an unsecure channel.
Quiz:
Suggested Reference:
1. https://www.geeksforgeeks.org/playfair-cipher-with-examples/
Rubrics 1 2 3 4 5 Total
Marks
8
Information Security (3170720)
Experiment No: 3
Implementation of Hill cipher
Date:
Relevant CO: Explore the basic principles of the symmetric cryptography and techniques with their
strengths and weaknesses from perspective of cryptanalysis
Algorithm:
STEP-1: Read the plain text and key from the user.
STEP-2: Split the plain text into groups of length three.
STEP-3: Arrange the keyword in a 3*3 matrix.
STEP-4: Multiply the two matrices to obtain the cipher text of length three.
STEP-5: Combine all these groups to get the complete cipher text.
Program:
cipherMatrix[i][j] = 0;
int messageVector[3][1];
int cipherMatrix[3][1];
string CipherText;
HillCipher(message, key);
return 0;
}
Output:
10
Information Security (3170720)
Conclusion:
Hill cipher is a matrix multiplication based block cipher and is used to encrypt data mathematically. It
is harder to crack compared to traditional stream ciphers or monoalphabetic ciphers.
Quiz:
Suggested Reference:
1. https://crypto.interactive-maths.com/hill-cipher.html
Rubrics 1 2 3 4 5 Total
Marks
11
Information Security (3170720)
Experiment No: 4
Implementation of Vigenere cipher
Date:
Relevant CO: Explore the basic principles of the symmetric cryptography and techniques with their
strengths and weaknesses from perspective of cryptanalysis
Example:
12
Information Security (3170720)
Algorithm:
Program:
#include <iostream>
#include <string>
class Vigenere{
public:
string key;
Vigenere(string key){
for (int i = 0; i < key.size(); ++i){
if (key[i] >= 'A' && key[i] <= 'Z')
this->key += key[i];
else if (key[i] >= 'a' && key[i] <= 'z')
this->key += key[i] + 'A' - 'a';
}
}
13
Information Security (3170720)
return out;
}
};
int main(){
Vigenere cipher("VIGENERECIPHER");
string original = "We will meet at the east wall";
Output:
Conclusion:
Vigenere Cipher is a simple polyalphabetic substitution method that goes from a simple to advanced
method. The Vigenere Square or Table is an important tool used in this Cipher. You can use this cipher
in three different ways as per your needs.
Quiz:
14
Information Security (3170720)
Suggested Reference:
1. https://intellipaat.com/blog/vigenere-cipher/
Rubrics 1 2 3 4 5 Total
Marks
15
Information Security (3170720)
Experiment No: 5
Implementation of Rail Fence Transposition
Date:
Relevant CO: Explore the basic principles of the symmetric cryptography and techniques with their
strengths and weaknesses from perspective of cryptanalysis
Example:
Algorithm:
STEP-5: Read the characters row wise or column wise in the former order to get the
cipher text.
16
Information Security (3170720)
Program:
// C++ program to illustrate Rail Fence Cipher
// Encryption and Decryption
#include <bits/stdc++.h>
using namespace std;
return result;
}
bool dir_down;
row = 0, col = 0;
for (int i = 0; i < cipher.length(); i++) {
// check the direction of flow
if (row == 0)
dir_down = true;
if (row == key - 1)
dir_down = false;
return 0;
18
Information Security (3170720)
}
Output:
Conclusion:
The Rail Fence algorithm is a simple cryptography algorithm. However, it is not secure. The key is
how many rows is implemented. It can be guessed by making a brute-force attack
Quiz:
2. Rail fence cipher is more secure than one time pad cipher? True/False
True
Suggested Reference:
1. https://crypto.interactive-maths.com/rail-fence-cipher.html
Rubrics 1 2 3 4 5 Total
Marks
19
Information Security (3170720)
Experiment No: 6
Implementation of Simple DES
Date:
Relevant CO: Implement and analyze various symmetric key cryptography algorithms
and their application in different context
Example:
20
Information Security (3170720)
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 <cmath>
#include <iostream>
#include <string>
using namespace std;
string round_keys[16];
string pt;
string convertDecimalToBinary(int decimal) {
string binary;
while (decimal != 0) {
binary = (decimal % 2 == 0 ? "0" : "1") + binary;
decimal = decimal / 2;
}
while (binary.length() < 4) {
binary = "0" + binary;
}
return binary;
}
int convertBinaryToDecimal(string binary) {
int decimal = 0;
int counter = 0;
int size = binary.length();
for (int i = size - 1; i >= 0; i--) {
if (binary[i] == '1') {
decimal += pow(2, counter);
}
counter++;
}
return decimal;
}
string shift_left_once(string key_chunk) {
string shifted = "";
for (int i = 1; i < 28; i++) {
shifted += key_chunk[i];
}
shifted += key_chunk[0];
return shifted;
}
string shift_left_twice(string key_chunk) {
21
Information Security (3170720)
int initial_permutation[64] = {
58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4,
62, 54, 46, 38, 30, 22, 14, 6, 64, 56, 48, 40, 32, 24, 16, 8,
57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35, 27, 19, 11, 3,
61, 53, 45, 37, 29, 21, 13, 5, 63, 55, 47, 39, 31, 23, 15, 7};
int expansion_table[48] = {32, 1, 2, 3, 4, 5, 4, 5, 6, 7, 8, 9,
8, 9, 10, 11, 12, 13, 12, 13, 14, 15, 16, 17,
16, 17, 18, 19, 20, 21, 20, 21, 22, 23, 24, 25,
24, 25, 26, 27, 28, 29, 28, 29, 30, 31, 32, 1};
int substition_boxes[8][4][16] = {
{14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7,
0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8,
4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0,
15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13},
{15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10,
3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5,
0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15,
13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9},
{10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8,
13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1,
13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7,
1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12},
{7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15,
13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9,
10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4,
3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14},
{2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9,
14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6,
4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14,
11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3},
{12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11,
10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8,
9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6,
4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13},
{4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1,
13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6,
1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2,
6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12},
{13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7,
1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2,
7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8,
2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11}};
int permutation_tab[32] = {16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23,
26, 5, 18, 31, 10, 2, 8, 24, 14, 32, 27,
3, 9, 19, 13, 30, 6, 22, 11, 4, 25};
int inverse_permutation[64] = {
40, 8, 48, 16, 56, 24, 64, 32, 39, 7, 47, 15, 55, 23, 63, 31,
38, 6, 46, 14, 54, 22, 62, 30, 37, 5, 45, 13, 53, 21, 61, 29,
36, 4, 44, 12, 52, 20, 60, 28, 35, 3, 43, 11, 51, 19, 59, 27,
34, 2, 42, 10, 50, 18, 58, 26, 33, 1, 41, 9, 49, 17, 57, 25};
string perm = "";
for (int i = 0; i < 64; i++) {
perm += pt[initial_permutation[i] - 1];
}
string left = perm.substr(0, 32);
23
Information Security (3170720)
Output:
24
Information Security (3170720)
Conclusion:
DES is a symmetric block cipher that can be used to encrypt 64-bits of plaintext into 64-bits of
ciphertext. The algorithm is the same for the process of encryption as well as decryption. The only
difference is that the decryption procedure is the opposite of the encryption procedure
Quiz:
Suggested Reference:
1. https://www.tutorialspoint.com/cryptography/data_encryption_standard.htm
Rubrics 1 2 3 4 5 Total
Marks
25
Information Security (3170720)
Experiment No: 7
Implementation of AES
Date:
Relevant CO: Implement and analyze various symmetric key cryptography algorithms
and their application in different context
Example:
Algorithm:
26
Information Security (3170720)
Program:
/* encrypt.cpp
* Performs encryption using AES 128-bit
* @author Cecelia Wisniewska
*/
#include <cstring>
#include <fstream>
#include <iostream>
#include <sstream>
0x48, 0x4a, 0x4c, 0x4e, 0x50, 0x52, 0x54, 0x56, 0x58, 0x5a, 0x5c, 0x5e,
0x60, 0x62, 0x64, 0x66, 0x68, 0x6a, 0x6c, 0x6e, 0x70, 0x72, 0x74, 0x76,
0x78, 0x7a, 0x7c, 0x7e, 0x80, 0x82, 0x84, 0x86, 0x88, 0x8a, 0x8c, 0x8e,
0x90, 0x92, 0x94, 0x96, 0x98, 0x9a, 0x9c, 0x9e, 0xa0, 0xa2, 0xa4, 0xa6,
0xa8, 0xaa, 0xac, 0xae, 0xb0, 0xb2, 0xb4, 0xb6, 0xb8, 0xba, 0xbc, 0xbe,
0xc0, 0xc2, 0xc4, 0xc6, 0xc8, 0xca, 0xcc, 0xce, 0xd0, 0xd2, 0xd4, 0xd6,
0xd8, 0xda, 0xdc, 0xde, 0xe0, 0xe2, 0xe4, 0xe6, 0xe8, 0xea, 0xec, 0xee,
0xf0, 0xf2, 0xf4, 0xf6, 0xf8, 0xfa, 0xfc, 0xfe, 0x1b, 0x19, 0x1f, 0x1d,
0x13, 0x11, 0x17, 0x15, 0x0b, 0x09, 0x0f, 0x0d, 0x03, 0x01, 0x07, 0x05,
0x3b, 0x39, 0x3f, 0x3d, 0x33, 0x31, 0x37, 0x35, 0x2b, 0x29, 0x2f, 0x2d,
0x23, 0x21, 0x27, 0x25, 0x5b, 0x59, 0x5f, 0x5d, 0x53, 0x51, 0x57, 0x55,
0x4b, 0x49, 0x4f, 0x4d, 0x43, 0x41, 0x47, 0x45, 0x7b, 0x79, 0x7f, 0x7d,
0x73, 0x71, 0x77, 0x75, 0x6b, 0x69, 0x6f, 0x6d, 0x63, 0x61, 0x67, 0x65,
0x9b, 0x99, 0x9f, 0x9d, 0x93, 0x91, 0x97, 0x95, 0x8b, 0x89, 0x8f, 0x8d,
0x83, 0x81, 0x87, 0x85, 0xbb, 0xb9, 0xbf, 0xbd, 0xb3, 0xb1, 0xb7, 0xb5,
0xab, 0xa9, 0xaf, 0xad, 0xa3, 0xa1, 0xa7, 0xa5, 0xdb, 0xd9, 0xdf, 0xdd,
0xd3, 0xd1, 0xd7, 0xd5, 0xcb, 0xc9, 0xcf, 0xcd, 0xc3, 0xc1, 0xc7, 0xc5,
0xfb, 0xf9, 0xff, 0xfd, 0xf3, 0xf1, 0xf7, 0xf5, 0xeb, 0xe9, 0xef, 0xed,
0xe3, 0xe1, 0xe7, 0xe5};
// Used in KeyExpansion
unsigned char rcon[256] = {
0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
28
Information Security (3170720)
0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
0x74, 0xe8, 0xcb, 0x8d};
}
}
/* Column 1 */
tmp[0] = state[0];
tmp[1] = state[5];
tmp[2] = state[10];
tmp[3] = state[15];
/* Column 2 */
tmp[4] = state[4];
tmp[5] = state[9];
tmp[6] = state[14];
tmp[7] = state[3];
/* Column 3 */
tmp[8] = state[8];
tmp[9] = state[13];
tmp[10] = state[2];
tmp[11] = state[7];
/* Column 4 */
tmp[12] = state[12];
tmp[13] = state[1];
tmp[14] = state[6];
tmp[15] = state[11];
tmp[8] =
(unsigned char)mul2[state[8]] ^ mul3[state[9]] ^ state[10] ^ state[11];
tmp[9] =
30
Information Security (3170720)
tmp[12] =
(unsigned char)mul2[state[12]] ^ mul3[state[13]] ^ state[14] ^ state[15];
tmp[13] =
(unsigned char)state[12] ^ mul2[state[13]] ^ mul3[state[14]] ^ state[15];
tmp[14] =
(unsigned char)state[12] ^ state[13] ^ mul2[state[14]] ^ mul3[state[15]];
tmp[15] =
(unsigned char)mul3[state[12]] ^ state[13] ^ state[14] ^ mul2[state[15]];
// S-box 4 bytes
in[0] = s[in[0]];
in[1] = s[in[1]];
in[2] = s[in[2]];
in[3] = s[in[3]];
// RCon
in[0] ^= rcon[i];
}
int numberOfRounds = 9;
int main() {
char message[1024];
if ((paddedMessageLen % 16) != 0) {
paddedMessageLen = (paddedMessageLen / 16 + 1) * 16;
}
string str;
istringstream hex_chars_stream(str);
unsigned char key[16];
int i = 0;
unsigned int c;
while (hex_chars_stream >> hex >> c) {
key[i] = c;
i++;
}
33
Information Security (3170720)
KeyExpansion(key, expandedKey);
return 0;
}
Output:
Conclusion:
the AES algorithm computes much faster than RSA in execution and implementation. RSA algorithm
is reliable for key exchange management, but it's not very efficient in terms of performance and cost
factor
Quiz:
Suggested Reference:
1. https://www.geeksforgeeks.org/advanced-encryption-standard-aes/
Rubrics 1 2 3 4 5 Total
Marks
34
Information Security (3170720)
Experiment No: 8
Implementation of RSA Algorithm
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:
35
Information Security (3170720)
Algorithm:
Program:
36
Information Security (3170720)
e++;
}
// Message to be encrypted
double msg = 12;
// Encryption c = (msg ^ e) % n
double c = pow(msg, e);
c = fmod(c, n);
printf("\nEncrypted data = %lf", c);
// Decryption m = (c ^ d) % n
double m = pow(c, d);
m = fmod(m, n);
printf("\nOriginal Message Sent = %lf\n", m);
return 0;
}
Output:
Conclusion:
RSA is a type of asymmetric encryption, which uses two different but linked keys. In RSA
cryptography, both the public and the private keys can encrypt a message. The opposite key from the
one used to encrypt a message is used to decrypt it.
37
Information Security (3170720)
Quiz:
Rubrics 1 2 3 4 5 Total
Marks
38
Information Security (3170720)
Experiment No: 9
Implementation of Diffie–Hellman Key Exchange
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.
39
Information Security (3170720)
Program:
else
return (((long long int)pow(a, b)) % P);
}
// Driver program
int main() {
long long int P, G, x, a, y, b, ka, kb;
cout << "Secret key for the Bob is : " << kb << endl;
return 0;
}
40
Information Security (3170720)
Output:
Conclusion:
With this algorithm of key exchange we can generate and share keys through an insecure channel,
securely without compromising and security and make use of symmetric cipher techniques
Quiz:
1. Suppose that two parties A and B wish to set up a common secret key (D-H key) between
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 ?
Suggested Reference:
1. https://www.techtarget.com/searchsecurity/definition/Diffie-Hellman-key-exchange
Rubrics 1 2 3 4 5 Total
Marks
41
Information Security (3170720)
Experiment No: 10
Implementation of MD-5
Date:
Relevant CO: Explore the concept of hashing and implement various hashing
algorithms for message integrity
Example:
42
Information Security (3170720)
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:
/*
* Derived from the RSA Data Security, Inc. MD5 Message-Digest Algorithm
* and modified slightly to be functionally identical but condensed into control structures.
*/
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
typedef struct{
uint64_t size; // Size of input in bytes
uint32_t buffer[4]; // Current accumulation of hash
uint8_t input[64]; // Input to be used in the next step
uint8_t digest[16]; // Result of algorithm
}MD5Context;
/*
* Constants defined by the MD5 algorithm
*/
#define A 0x67452301
#define B 0xefcdab89
#define C 0x98badcfe
#define D 0x10325476
static uint32_t S[] = {7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21};
43
Information Security (3170720)
/*
* Padding used to make the size (in bits) of the input congruent to 448 mod 512
*/
static uint8_t PADDING[] = {0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
/*
* Bit-manipulation functions defined by the MD5 algorithm
*/
#define F(X, Y, Z) ((X & Y) | (~X & Z))
#define G(X, Y, Z) ((X & Z) | (Y & ~Z))
#define H(X, Y, Z) (X ^ Y ^ Z)
#define I(X, Y, Z) (Y ^ (X | ~Z))
/*
* Rotates a 32-bit word left by n bits
*/
uint32_t rotateLeft(uint32_t x, uint32_t n){
return (x << n) | (x >> (32 - n));
}
/*
* Initialize a context
*/
void md5Init(MD5Context *ctx){
ctx->size = (uint64_t)0;
ctx->buffer[0] = (uint32_t)A;
ctx->buffer[1] = (uint32_t)B;
ctx->buffer[2] = (uint32_t)C;
ctx->buffer[3] = (uint32_t)D;
}
/*
* Add some amount of input to the context
44
Information Security (3170720)
*
* If the input fills out a block of 512 bits, apply the algorithm (md5Step)
* and save the result in the buffer. Also updates the overall size.
*/
void md5Update(MD5Context *ctx, uint8_t *input_buffer, size_t input_len){
uint32_t input[16];
unsigned int offset = ctx->size % 64;
ctx->size += (uint64_t)input_len;
// Copy each byte in input_buffer into the next space in our context input
for(unsigned int i = 0; i < input_len; ++i){
ctx->input[offset++] = (uint8_t)*(input_buffer + i);
// If we've filled our context input, copy it into our local array input
// then reset the offset to 0 and fill in a new buffer.
// Every time we fill out a chunk, we run it through the algorithm
// to enable some back and forth between cpu and i/o
if(offset % 64 == 0){
for(unsigned int j = 0; j < 16; ++j){
// Convert to little-endian
// The local variable `input` our 512-bit chunk separated into 32-bit words
// we can use in calculations
input[j] = (uint32_t)(ctx->input[(j * 4) + 3]) << 24 |
(uint32_t)(ctx->input[(j * 4) + 2]) << 16 |
(uint32_t)(ctx->input[(j * 4) + 1]) << 8 |
(uint32_t)(ctx->input[(j * 4)]);
}
md5Step(ctx->buffer, input);
offset = 0;
}
}
}
/*
* Pad the current input to get to 448 bytes, append the size in bits to the very end,
* and save the result of the final iteration into digest.
*/
void md5Finalize(MD5Context *ctx){
uint32_t input[16];
unsigned int offset = ctx->size % 64;
unsigned int padding_length = offset < 56 ? 56 - offset : (56 + 64) - offset;
// Fill in the padding and undo the changes to size that resulted from the update
md5Update(ctx, PADDING, padding_length);
ctx->size -= (uint64_t)padding_length;
md5Step(ctx->buffer, input);
45
Information Security (3170720)
/*
* Step on 512 bits of input with the main MD5 algorithm.
*/
void md5Step(uint32_t *buffer, uint32_t *input){
uint32_t AA = buffer[0];
uint32_t BB = buffer[1];
uint32_t CC = buffer[2];
uint32_t DD = buffer[3];
uint32_t E;
unsigned int j;
buffer[0] += AA;
buffer[1] += BB;
buffer[2] += CC;
buffer[3] += DD;
}
/*
* Functions that run the algorithm on the provided input and put the digest into result.
* result should be able to store 16 bytes.
*/
void md5String(char *input, uint8_t *result){
MD5Context ctx;
46
Information Security (3170720)
md5Init(&ctx);
md5Update(&ctx, (uint8_t *)input, strlen(input));
md5Finalize(&ctx);
int main(void){
char *plaintext = "helloworld";
uint8_t result[16];
md5String(plaintext, result);
printf("MD5 hash of %s : ", plaintext);
printArrayBuffer(result, 16);
return 0;
}
Output:
Conclusion:
The MD5 hashing technique relies on a complex mathematical formula to compute the plain text cipher
hash value. As we've seen, the MD5 algorithm divides the plain text into blocks of varying sizes and
then performs various operations on them.
Quiz:
Suggested Reference:
1. https://www.simplilearn.com/tutorials/cyber-security-tutorial/md5-algorithm
Rubrics 1 2 3 4 5 Total
Marks
47
Information Security (3170720)
Experiment No: 11
Implementation of SHA-1
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:
#include <cstdint>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
class SHA1 {
public:
SHA1();
void update(const std::string &s);
void update(std::istream &is);
std::string final();
static std::string from_file(const std::string &filename);
private:
uint32_t digest[5];
std::string buffer;
uint64_t transforms;
};
/* Reset counters */
buffer = "";
transforms = 0;
}
49
Information Security (3170720)
/*
* (R0+R1), R2, R3, R4 are the different operations used in SHA1
*/
/*
* Hash a single 512-bit block. This is the core of the algorithm.
*/
R3(block, d, e, a, b, c, 15);
R3(block, c, d, e, a, b, 0);
R3(block, b, c, d, e, a, 1);
R3(block, a, b, c, d, e, 2);
R3(block, e, a, b, c, d, 3);
R3(block, d, e, a, b, c, 4);
R3(block, c, d, e, a, b, 5);
R3(block, b, c, d, e, a, 6);
R3(block, a, b, c, d, e, 7);
R3(block, e, a, b, c, d, 8);
R3(block, d, e, a, b, c, 9);
R3(block, c, d, e, a, b, 10);
R3(block, b, c, d, e, a, 11);
R4(block, a, b, c, d, e, 12);
R4(block, e, a, b, c, d, 13);
R4(block, d, e, a, b, c, 14);
R4(block, c, d, e, a, b, 15);
R4(block, b, c, d, e, a, 0);
R4(block, a, b, c, d, e, 1);
R4(block, e, a, b, c, d, 2);
R4(block, d, e, a, b, c, 3);
R4(block, c, d, e, a, b, 4);
R4(block, b, c, d, e, a, 5);
R4(block, a, b, c, d, e, 6);
R4(block, e, a, b, c, d, 7);
R4(block, d, e, a, b, c, 8);
R4(block, c, d, e, a, b, 9);
R4(block, b, c, d, e, a, 10);
R4(block, a, b, c, d, e, 11);
R4(block, e, a, b, c, d, 12);
R4(block, d, e, a, b, c, 13);
R4(block, c, d, e, a, b, 14);
R4(block, b, c, d, e, a, 15);
52
Information Security (3170720)
/*
* Add padding and return the message digest.
*/
/* Padding */
buffer += (char)0x80;
size_t orig_size = buffer.size();
while (buffer.size() < BLOCK_BYTES) {
buffer += (char)0x00;
}
uint32_t block[BLOCK_INTS];
buffer_to_block(buffer, block);
/* Hex std::string */
std::ostringstream result;
for (size_t i = 0; i < sizeof(digest) / sizeof(digest[0]); i++) {
53
Information Security (3170720)
return result.str();
}
int main() {
SHA1 checksum;
std::cout << std::endl;
std::cout << "Test: \t" << plaintext << std::endl;
checksum.update(plaintext);
std::cout << "Hashed: " << checksum.final() << std::endl;
return 0;
}
Output:
Conclusion:
In conclusion, SHA-1 is a widely used hash function that has been in use for several decades.
While it was once considered secure, it is now vulnerable to various attacks due to its collision
resistance. It is recommended to use stronger hash functions such as SHA-2 and SHA-3 for new
applications and systems.
Quiz:
54
Information Security (3170720)
Suggested Reference:
1. https://www.geeksforgeeks.org/sha-1-hash-in-java/.
Rubrics 1 2 3 4 5 Total
Marks
55
Information Security (3170720)
Experiment No: 12
Implementation of digital signature standard
Date:
Relevant CO: Explore and use the techniques and standards of digital signature, key
management and authentication
Example:
Algorithm:
56
Information Security (3170720)
Program:
#include <cstdint>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
class SHA1 {
public:
SHA1();
void update(const std::string &s);
void update(std::istream &is);
std::string final();
static std::string from_file(const std::string &filename);
private:
uint32_t digest[5];
std::string buffer;
uint64_t transforms;
};
/* Reset counters */
buffer = "";
transforms = 0;
}
/*
* (R0+R1), R2, R3, R4 are the different operations used in SHA1
*/
/*
* Hash a single 512-bit block. This is the core of the algorithm.
*/
R0(block, c, d, e, a, b, 3);
R0(block, b, c, d, e, a, 4);
R0(block, a, b, c, d, e, 5);
R0(block, e, a, b, c, d, 6);
R0(block, d, e, a, b, c, 7);
R0(block, c, d, e, a, b, 8);
R0(block, b, c, d, e, a, 9);
R0(block, a, b, c, d, e, 10);
R0(block, e, a, b, c, d, 11);
R0(block, d, e, a, b, c, 12);
R0(block, c, d, e, a, b, 13);
R0(block, b, c, d, e, a, 14);
R0(block, a, b, c, d, e, 15);
R1(block, e, a, b, c, d, 0);
R1(block, d, e, a, b, c, 1);
R1(block, c, d, e, a, b, 2);
R1(block, b, c, d, e, a, 3);
R2(block, a, b, c, d, e, 4);
R2(block, e, a, b, c, d, 5);
R2(block, d, e, a, b, c, 6);
R2(block, c, d, e, a, b, 7);
R2(block, b, c, d, e, a, 8);
R2(block, a, b, c, d, e, 9);
R2(block, e, a, b, c, d, 10);
R2(block, d, e, a, b, c, 11);
R2(block, c, d, e, a, b, 12);
R2(block, b, c, d, e, a, 13);
R2(block, a, b, c, d, e, 14);
R2(block, e, a, b, c, d, 15);
R2(block, d, e, a, b, c, 0);
R2(block, c, d, e, a, b, 1);
R2(block, b, c, d, e, a, 2);
R2(block, a, b, c, d, e, 3);
R2(block, e, a, b, c, d, 4);
R2(block, d, e, a, b, c, 5);
R2(block, c, d, e, a, b, 6);
R2(block, b, c, d, e, a, 7);
R3(block, a, b, c, d, e, 8);
R3(block, e, a, b, c, d, 9);
R3(block, d, e, a, b, c, 10);
R3(block, c, d, e, a, b, 11);
R3(block, b, c, d, e, a, 12);
R3(block, a, b, c, d, e, 13);
R3(block, e, a, b, c, d, 14);
R3(block, d, e, a, b, c, 15);
R3(block, c, d, e, a, b, 0);
R3(block, b, c, d, e, a, 1);
R3(block, a, b, c, d, e, 2);
R3(block, e, a, b, c, d, 3);
R3(block, d, e, a, b, c, 4);
R3(block, c, d, e, a, b, 5);
R3(block, b, c, d, e, a, 6);
R3(block, a, b, c, d, e, 7);
R3(block, e, a, b, c, d, 8);
R3(block, d, e, a, b, c, 9);
59
Information Security (3170720)
R3(block, c, d, e, a, b, 10);
R3(block, b, c, d, e, a, 11);
R4(block, a, b, c, d, e, 12);
R4(block, e, a, b, c, d, 13);
R4(block, d, e, a, b, c, 14);
R4(block, c, d, e, a, b, 15);
R4(block, b, c, d, e, a, 0);
R4(block, a, b, c, d, e, 1);
R4(block, e, a, b, c, d, 2);
R4(block, d, e, a, b, c, 3);
R4(block, c, d, e, a, b, 4);
R4(block, b, c, d, e, a, 5);
R4(block, a, b, c, d, e, 6);
R4(block, e, a, b, c, d, 7);
R4(block, d, e, a, b, c, 8);
R4(block, c, d, e, a, b, 9);
R4(block, b, c, d, e, a, 10);
R4(block, a, b, c, d, e, 11);
R4(block, e, a, b, c, d, 12);
R4(block, d, e, a, b, c, 13);
R4(block, c, d, e, a, b, 14);
R4(block, b, c, d, e, a, 15);
buffer.append(sbuf, (std::size_t)is.gcount());
if (buffer.size() != BLOCK_BYTES) {
return;
}
uint32_t block[BLOCK_INTS];
buffer_to_block(buffer, block);
transform(digest, block, transforms);
buffer.clear();
}
}
/*
* Add padding and return the message digest.
*/
/* Padding */
buffer += (char)0x80;
size_t orig_size = buffer.size();
while (buffer.size() < BLOCK_BYTES) {
buffer += (char)0x00;
}
uint32_t block[BLOCK_INTS];
buffer_to_block(buffer, block);
/* Hex std::string */
std::ostringstream result;
for (size_t i = 0; i < sizeof(digest) / sizeof(digest[0]); i++) {
result << std::hex << std::setfill('0') << std::setw(8);
result << digest[i];
}
return result.str();
}
int main() {
SHA1 checksum;
std::cout << std::endl;
std::cout << "Test: \t" << plaintext << std::endl;
checksum.update(plaintext);
std::cout << "Hashed: " << checksum.final() << std::endl;
return 0;
}
Output:
Conclusion:
Signature algorithms can bee used to verify the indivual securely using the signature used with the
signing key.
62
Information Security (3170720)
Quiz:
Suggested Reference:
1. https://www.geeksforgeeks.org/digital-signature-standard-dss/
Rubrics 1 2 3 4 5 Total
Marks
63
Information Security (3170720)
Experiment No: 13
Demonstrate how to work with CrypTool
Date:
Relevant CO: -----
Introduction:
The JCrypTool installation is very 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.
64
Information Security (3170720)
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.”
65
Information Security (3170720)
4. The document is encrypted as per the configured policy. This is a very basic example of how
symmetric encryption works.
Decryption process
Conclusion:
66
Information Security (3170720)
CrypTool is a powerful and comprehensive free software package with very approachable interface.
Along with its accompanying extensive support materials and programs, it provides substantial
assistance to individuals interested in security, student wanting to explore the field, and as a
teaching tool for instructors.
The variety of different algorithms implemented in CrypTool, from the earliest known to the most
modern, both sets the background for current cryptography, and also enables an understanding of the
most modern cryptographic principles and algorithms.
While tools like CrypTool do take class time to teach, the learning curve is not steep and the time that
would otherwise be used to discuss coding the different cryptography and cryptanalysis tools can be
used to cover additional cryptography concept
Suggested Reference:
1. https://www.c-sharpcorner.com/article/encryption-decryption-using-cryptool/
67
Information Security (3170720)
Experiment No: 14
Demonstrate Working of Wireshark
Date:
Relevant CO:
Introduction:
The Wireshark installation is very simple: download and extract the zip-archive, launch the main
program and get started.
Installation
Installing Wireshark on Windows: Follow the below steps to install Wireshark on Windows:
Step 1: Visit the official Wireshark website using any web browser.
Step 2: Click on Download, a new webpage will open with different installers of Wireshark.
68
Information Security (3170720)
Step 3: Downloading of the executable file will start shortly. It is a small 73.69 MB file that will
take some time.
Step 4: Now check for the executable file in downloads in your system and run it.
Step 5: It will prompt confirmation to make changes to your system. Click on Yes.
69
Information Security (3170720)
70
Information Security (3170720)
Step 8: This screen is for choosing components, all components are already marked so don’t change
anything just click on the Next button.
Step 9: This screen is of choosing shortcuts like start menu or desktop icon along with file
extensions which can be intercepted by Wireshark, tick all boxes and click on Next button.
Step 10: The next screen will be of installing location so choose the drive which will have sufficient
memory space for installation. It needed only a memory space of 223.4 MB.
71
Information Security (3170720)
Step 11: Next screen has an option to install Npcap which is used with Wireshark to capture
packets pcap means packet capture so the install option is already checked don’t change anything
and click the next button.
Step 12: Next screen is about USB network capturing so it is one’s choice to use it or not, click on
Install.
72
Information Security (3170720)
Step 14: This installation will prompt for Npcap installation as already checked so the license
agreement of Npcap will appear to click on the I Agree button.
Step 15: Next screen is about different installing options of npcap, don’t do anything click on
Install.
73
Information Security (3170720)
Step 16: After this installation process will start which will take only a minute.
Step 17: After this installation process will complete click on the Next button.
74
Information Security (3170720)
75
Information Security (3170720)
Step 19: After this installation process of Wireshark will complete click on the Next button.
Step 20: Click on Finish after the installation process of Wireshark is complete.
76
Information Security (3170720)
Wireshark is successfully installed on the system and an icon is created on the desktop as shown
below:
77
Information Security (3170720)
Now you can use wireshark for packet capturing and filtering
Conclusion:
Wireshark plays a crucial role in network security analysis. It allows security professionals to inspect
packets for signs of malicious activities, such as suspicious traffic patterns, unauthorized access
attempts, or data exfiltration
Suggested Reference:
1. https://www.javatpoint.com/wireshark
2. https://www.comptia.org/content/articles/what-is-wireshark-and-how-to-use-
it#:~:text=What%20Is%20Wireshark%20Used%20For,identify%20bursts%20of%20network
%20traffic.
78