0% found this document useful (0 votes)
29 views

Network Security Lab File

Uploaded by

parthgupta1026
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Network Security Lab File

Uploaded by

parthgupta1026
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Index

ACROPOLIS INSTITUTE OF TECHNOLOGY &


RESEARCH, INDORE

Name of Department CSIT

Page Date of Grade & Sign of


S.No. Date of Exp. Name of the Experiment
No. Submission the Faculty
Write Code for cipher
1. algorithms.

2. Study of cryptography tools

CTF Challenge Report


3.

Cryptography Study Summary


4. from TryHackMe

5.

6.

7.

8.
Experiment – 1

Aim: Write Code for cipher algorithms.

#include <iostream>
#include <string>
using namespace std;

// Function to encrypt the plaintext using Caesar Cipher


string caesar_encrypt(string text, int shift) {
string result = "";

// Traverse through each character in the text


for (int i = 0; i < text.length(); i++) {
char ch = text[i];

// Encrypt uppercase letters


if (isupper(ch)) {
result += char(int(ch + shift - 65) % 26 + 65);
}
// Encrypt lowercase letters
else if (islower(ch)) {
result += char(int(ch + shift - 97) % 26 + 97);
}
// If it's not an alphabet, add it as is
else {
result += ch;
}
}
return result;
}

// Function to decrypt the ciphertext using Caesar Cipher


string caesar_decrypt(string text, int shift) {
// To decrypt, simply use the encryption function with a negative shift
return caesar_encrypt(text, -shift);
}

int main() {
string plaintext, ciphertext, decryptedtext;
int shift;

// Input the plaintext from user


cout << "Enter the plaintext: ";
getline(cin, plaintext);

// Input the shift value (key)


cout << "Enter the shift value: ";
cin >> shift;

// Encrypt the plaintext


ciphertext = caesar_encrypt(plaintext, shift);
cout << "Encrypted Text (Ciphertext): " << ciphertext << endl;

// Decrypt the ciphertext


decryptedtext = caesar_decrypt(ciphertext, shift);
cout << "Decrypted Text (Plaintext): " << decryptedtext << endl;
return 0;
}
Output:

2. Monoalphabetic Cipher

#include <iostream>
#include <string>
using namespace std;

// Function to generate substitution mapping for encryption


void generateSubstitutionArrays(char originalAlphabet[], char shuffledAlphabet[]) {
string normalAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

// Fill the originalAlphabet array


for (int i = 0; i < 26; i++) {
originalAlphabet[i] = normalAlphabet[i];
}
}

// Function to encrypt using Monoalphabetic Cipher


string encrypt(string plaintext, char originalAlphabet[], char shuffledAlphabet[]) {
string ciphertext = "";

for (char &ch : plaintext) {


if (isalpha(ch)) {
char upperCh = toupper(ch);
for (int i = 0; i < 26; i++) {
if (upperCh == originalAlphabet[i]) {
ciphertext += shuffledAlphabet[i]; // Substituting each letter
break;
}
}
} else {
ciphertext += ch; // If it's not a letter, just append the character
}
}

return ciphertext;
}

// Function to decrypt using Monoalphabetic Cipher


string decrypt(string ciphertext, char originalAlphabet[], char shuffledAlphabet[]) {
string decryptedText = "";

for (char &ch : ciphertext) {


if (isalpha(ch)) {
for (int i = 0; i < 26; i++) {
if (ch == shuffledAlphabet[i]) {
decryptedText += originalAlphabet[i]; // Reverse substitution
break;
}
}
} else {
decryptedText += ch; // If it's not a letter, just append the character
}
}
return decryptedText;
}

int main() {
// Define the original and shuffled alphabets
char originalAlphabet[26], shuffledAlphabet[26] = {'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P',
'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Z',
'X', 'C', 'V', 'B', 'N', 'M'};

// Generate the substitution arrays


generateSubstitutionArrays(originalAlphabet, shuffledAlphabet);

// Input plaintext from user


string plaintext;
cout << "Enter the plaintext: ";
getline(cin, plaintext);

// Encrypt the plaintext


string ciphertext = encrypt(plaintext, originalAlphabet, shuffledAlphabet);
cout << "Encrypted text: " << ciphertext << endl;

// Decrypt the ciphertext


string decryptedText = decrypt(ciphertext, originalAlphabet, shuffledAlphabet);
cout << "Decrypted text: " << decryptedText << endl;

return 0;
}
OUTPUT:
3. playfair

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cctype>

using namespace std;

// Function to create a 5x5 matrix for the Playfair Cipher


void createMatrix(const string &key, char matrix[5][5]) {
string keyStr;

// Remove duplicates and prepare the key


for (char ch : key) {
ch = toupper(ch);
if (keyStr.find(ch) == string::npos && ch != 'J') {
keyStr += ch; // Exclude 'J' for the matrix
}
}

// Add remaining letters of the alphabet


for (char ch = 'A'; ch <= 'Z'; ch++) {
if (ch != 'J' && keyStr.find(ch) == string::npos) {
keyStr += ch;
}
}

// Fill the matrix


int index = 0;
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
matrix[i][j] = keyStr[index++];
}
}
}

// Function to find the position of a character in the matrix


pair<int, int> findPosition(char ch, char matrix[5][5]) {
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
if (matrix[i][j] == ch) {
return {i, j};
}
}
}
return {-1, -1}; // Not found
}

// Function to encrypt plaintext using the Playfair Cipher


string encrypt(const string &plaintext, char matrix[5][5]) {
string ciphertext = "";

// Process the plaintext


for (size_t i = 0; i < plaintext.length(); i += 2) {
char first = toupper(plaintext[i]);
char second = (i + 1 < plaintext.length()) ? toupper(plaintext[i + 1]) : 'X';

// Skip spaces
if (first == ' ') {
i--;
continue;
}

if (second == ' ') {


second = 'X'; // If the second letter is a space, replace it with 'X'
} else if (first == second) {
second = 'X'; // If both letters are the same, replace the second with 'X'
}

pair<int, int> pos1 = findPosition(first, matrix);


pair<int, int> pos2 = findPosition(second, matrix);

if (pos1.first == pos2.first) { // Same row


ciphertext += matrix[pos1.first][(pos1.second + 1) % 5];
ciphertext += matrix[pos2.first][(pos2.second + 1) % 5];
} else if (pos1.second == pos2.second) { // Same column
ciphertext += matrix[(pos1.first + 1) % 5][pos1.second];
ciphertext += matrix[(pos2.first + 1) % 5][pos2.second];
} else { // Rectangle case
ciphertext += matrix[pos1.first][pos2.second];
ciphertext += matrix[pos2.first][pos1.second];
}
}

return ciphertext;
}

int main() {
string key, plaintext;

cout << "Enter the key: ";


getline(cin, key);

cout << "Enter the plaintext: ";


getline(cin, plaintext);

char matrix[5][5];

// Create the matrix based on the key


createMatrix(key, matrix);

// Encrypt the plaintext


string ciphertext = encrypt(plaintext, matrix);
cout << "Encrypted text: " << ciphertext << endl;

return 0;
}

Output:
Experiment -2

Study of cryptography tools

1. CrypTool
 Description: An interactive e-learning platform that allows users to learn about
various cryptographic methods, including classical encryption techniques like Caesar
cipher, Vigenère cipher, and more.
Hash Generator( OnlineWebToolKit)
A Hash Generator is an online tool that allows users to create hash values from input text
using various hashing algorithms. Hashing is a cryptographic process that transforms input
data (like passwords or files) into a fixed-size string of characters, which typically appears
random. Hashes are often used for data integrity verification, secure password storage, and
digital signatures.
Key Features of Hash Generators
1. Multiple Hashing Algorithms:
o Most hash generators support various algorithms, allowing users to choose the one
that best fits their needs. Common algorithms include:
 MD5: Produces a 128-bit hash value, typically represented as a 32-character
hexadecimal number. While fast, MD5 is not considered secure for
cryptographic purposes due to vulnerabilities.
 SHA-1: Generates a 160-bit hash value and is more secure than MD5, but has
also been found to have vulnerabilities over time.
 SHA-256: Part of the SHA-2 family, it creates a 256-bit hash value and is widely
used in security applications and protocols, including SSL and TLS.
 SHA-512: Similar to SHA-256 but produces a 512-bit hash value, offering
greater security.
 bcrypt: Specifically designed for hashing passwords with a salt to protect
against rainbow table attacks.
Online AES Encryption Tool (only cript)
Description: The Online AES Encryption Tool is a web-based application that enables users
to securely encrypt and decrypt messages using the AES (Advanced Encryption Standard)
algorithm. This tool supports various key lengths (128, 192, and 256 bits) and different
operational modes (like CBC, ECB, CFB, OFB, and CTR), allowing users to customize their
encryption process according to their security needs.
Key Features:
 AES Encryption and Decryption: Easily encrypt plaintext into ciphertext and
decrypt ciphertext back to plaintext using AES.
 Support for Different Key Lengths: Users can choose between 128, 192, or 256-bit
keys, enhancing security based on the required level.
 Multiple Modes of Operation: Select from various modes of operation:
o ECB (Electronic Codebook): Simplest mode, but less secure for identical
plaintext blocks.
o CBC (Cipher Block Chaining): More secure than ECB, using an
initialization vector (IV) for added randomness.
o CFB (Cipher Feedback): Allows encryption of data in smaller increments.
o OFB (Output Feedback): Similar to CFB, but the ciphertext is fed back for
the next encryption block.
o CTR (Counter): Converts block cipher into a stream cipher, allowing for
high-speed encryption.
 User-Friendly Interface: Simple and intuitive web interface that allows users to
input plaintext, select options, and receive encrypted output quickly.
 Base64 Encoding/Decoding: Automatically encodes or decodes the output in Base64
format, making it easier to handle binary data in text format.
 No Installation Required: As a web-based tool, it requires no downloads or
installations, allowing users to access it from any device with an internet connection.

CodeChef

What
A simple, intuitive web app for analysing and decoding data without having to deal with
complex tools or programming languages. CyberChef encourages both technical and non-
technical people to explore data formats, encryption and compression.

Why
Digital data comes in all shapes, sizes and formats in the modern world – CyberChef helps to
make sense of this data all on one easy-to-use platform.

How
The interface is designed with simplicity at its heart. Complex techniques are now as trivial
as drag-and-drop. Simple functions can be combined to build up a "recipe", potentially
resulting in complex analysis, which can be shared with other users and used with their input.
For those comfortable writing code, CyberChef is a quick and efficient way to prototype
solutions to a problem which can then be scripted once proven to work.
Who
It is expected that CyberChef will be useful for cybersecurity and antivirus companies. It
should also appeal to the academic world and any individuals or companies involved in the
analysis of digital data, be that software developers, analysts, mathematicians or casual
puzzle solvers.

Aim
It is hoped that by releasing CyberChef through GitHub, contributions can be added which
can be rolled out into future versions of the tool.
There are around 200 useful operations in CyberChef for anyone working on anything
vaguely Internet-related, whether you just want to convert a timestamp to a different format,
decompress gzipped data, create a SHA3 hash, or parse an X.509 certificate to find out who
issued it.
It’s the Cyber Swiss Army Knife.
Experiment-3

CTF Challenge Report

Challenge Overview:
The first challenge in this CTF focused on basic cryptography, where we were tasked with
deciphering an encoded message to retrieve the hidden flag. The encoded message was
scrambled using a cipher, and based on the challenge description and hints, it was highly
suggestive that a Caesar cipher or its variant, ROT13, was used to encode the message. The
goal was to determine the number of shifts in the cipher and then decode the message to
retrieve the flag.

Step-by-Step Breakdown:
1. Challenge Objective: The problem statement provided the encoded message:
Copy code
Gur frperg cnffjbeq vf uvqqra haqre gur oevqtr. Gur synt vf pgsn{pvcure_qrpvcure}
The challenge hinted that the message had been encoded using a cipher. Our task was to:
o Identify the type of cipher used.
o Determine how many shifts were applied in the encoded message.
o Decode the message and retrieve the flag.
2. Decoding the Cipher: The hint provided in the challenge description suggested the
use of CyberChef, an online tool designed for encoding and decoding various
ciphers. Based on the structure of the encoded text and the common use of Caesar
ciphers in introductory challenges, I suspected that the ROT13 cipher had been used.
o ROT13 Cipher: This is a special case of the Caesar cipher, where each letter
in the message is shifted by 13 positions in the alphabet. It’s a simple but
effective method for obscuring text.
o Since ROT13 is its own inverse (applying the same transformation twice
restores the original message), decoding it is as simple as encoding the text
again with a 13-letter shift.
3. Using CyberChef: To validate this hypothesis, I followed the steps below:
o Navigated to CyberChef and entered the provided encoded message.
o Applied the ROT13 decryption operation to the message.
o The decrypted message was:
csharp
Copy code
The secret password is hidden under the bridge. The flag is ctfa{cipher_decipher}
4. Analyzing the Decoded Message: From the decoded message, it became evident that
the challenge was using a ROT13 encoding scheme. The message provided both the
location of the secret password ("hidden under the bridge") and the flag for
submission:
Copy code
ctfa{cipher_decipher}
5. Submission of the Flag:
o The flag for this challenge, ctfa{cipher_decipher}, was successfully
submitted in the input box, leading to a successful completion of the first
challenge.
Tools and Methods Used:
 CyberChef:
o This is a web-based tool that supports a wide array of operations such as
encoding, decoding, encryption, and decryption using various ciphers,
including ROT13.
o The tool allowed me to quickly input the encoded text and apply the necessary
decryption operation.
 ROT13 Cipher:
o A simple substitution cipher where each letter is shifted by 13 positions.
o Commonly used in introductory cryptography challenges due to its simplicity
and ease of decryption.
Reflection:
The challenge provided a great introduction to basic cryptographic techniques, specifically
the Caesar cipher and its ROT13 variant. While this was a straightforward problem, it
underscored the importance of recognizing patterns in encrypted messages and leveraging
appropriate tools (like CyberChef) for efficient decoding. Understanding simple ciphers such
as Caesar and ROT13 forms the foundation for tackling more complex cryptographic
challenges in future levels of the competition.

Conclusion:
By identifying the ROT13 cipher and using the appropriate decryption method, I was able to
successfully decode the hidden message and retrieve the flag ctfa{cipher_decipher}. This
challenge served as a fundamental exercise in understanding the basics of cryptography,
providing essential skills that will be useful in future cryptographic tasks within the CTF.
Experiment – 4

Cryptography Study Summary from TryHackMe

In this experiment, I completed the "Introduction to Cryptography" room on TryHackMe,


gaining hands-on experience with various cryptographic principles and their applications.
The room covered the following topics in detail:
1. Symmetric Encryption (Task 2): I explored symmetric encryption, where the same
key is used for both encryption and decryption. This technique is efficient but requires
both parties to share the key securely. Algorithms like AES (Advanced Encryption
Standard) were studied, which are widely used for securing data due to their strength
and speed.
2. Asymmetric Encryption (Task 3): In contrast to symmetric encryption, asymmetric
encryption utilizes a pair of keys—a public key for encryption and a private key for
decryption. This method enhances security since only the recipient can decrypt the
data. RSA (Rivest–Shamir–Adleman) was the primary algorithm covered, which is
commonly used for securing emails, digital signatures, and more.
3. Diffie-Hellman Key Exchange (Task 4): This topic focused on the Diffie-Hellman
protocol, which allows two parties to securely exchange cryptographic keys over an
insecure channel. The protocol ensures that even if an attacker intercepts the
communication, they won’t be able to derive the shared secret key. This method is the
basis for many modern encryption schemes.
4. Hashing (Task 5): Hashing is the process of converting data into a fixed-length
string, known as a hash, regardless of the size of the input. This technique is widely
used for data integrity verification and password storage. I learned about popular
hashing algorithms like MD5 and SHA-256, their use cases, and vulnerabilities like
hash collisions in weaker algorithms.
5. Public Key Infrastructure (PKI) and SSL/TLS (Task 6): PKI is a system of digital
certificates, Certificate Authorities (CAs), and registration authorities used to secure
communications on the internet. I also learned about SSL/TLS protocols, which use
certificates to encrypt data between a user and a website, providing secure
communication channels for sensitive information like banking transactions.
6. Authenticating with Passwords (Task 7): This task delved into secure methods for
password authentication, discussing the importance of salting and hashing passwords
before storage to protect against brute force attacks. Additionally, password policies
and multi-factor authentication (MFA) methods were covered as a way to enhance
security.
7. Cryptography and Data - Real-world Example (Task 8): This section explored a
practical example of cryptography in action, showing how encryption and hashing
techniques are employed in industries like finance, healthcare, and online services to secure
sensitive data and prevent unauthorized access.
Conclusion
This study provided me with a strong foundational understanding of cryptographic methods
and their applications. I learned not only about the theory behind encryption, hashing, and
key exchanges, but also how these methods are applied in the real world to secure
communications and data. The hands-on tasks within the TryHackMe platform helped
solidify my understanding of these concepts, making it a valuable learning experience.
Experiment – 5

What is a VPN (Virtual Private Network)?


A VPN (Virtual Private Network) is a service or technology that creates a secure and
encrypted connection over a less secure network, such as the public internet. It allows users
to access private networks or securely browse the internet by tunneling their internet traffic
through a server controlled by the VPN provider. This protects the data from potential
hackers or monitoring by ISPs (Internet Service Providers).
Key Features of VPN:
 Encryption: VPNs use encryption to secure data sent and received, preventing third
parties from eavesdropping on the communication.
 Anonymity: VPNs hide a user's IP address and geographical location, making it
appear as though the traffic originates from the VPN server.
 Bypass Geo-restrictions: VPNs can help users access content that might be restricted
in certain regions.
 Secure Access to Private Networks: Remote users can securely access a company’s
private network through a VPN, as if they were directly connected to it.
What is a Virtual Network?
A Virtual Network refers to the creation of network services or devices within a shared
infrastructure, typically in cloud environments. It allows resources (such as servers,
databases, and virtual machines) to communicate with each other over a simulated or
virtualized network instead of physical connections.
Key Features of Virtual Networks:
 Resource Isolation: Virtual networks isolate specific traffic, applications, or services
in a multi-tenant environment to ensure that they don't interfere with other network
traffic.
 Scalability and Flexibility: Virtual networks can be easily created, expanded, or
deleted, offering flexibility in cloud environments like AWS, Azure, or Google
Cloud.
 Internal Communication: In a cloud environment, virtual networks allow virtual
machines or instances to communicate with each other without needing public IP
addresses.

Steps to Configure VPN on Windows 11 Using VPNBook:


1. Visit VPNBook Website:
o Open a browser and go to the VPNBook website.
o Choose a VPN server from the options provided (e.g., US2.vpnbook.com) or
anything you want .
o Note the username and password displayed on the website, as they will be needed
during the setup.

2. Open VPN Settings in Windows 11:


o Click on the Start menu and go to Settings.
o Select Network & Internet from the list of options.
o In the left-hand menu, click on VPN.
3. Add a New VPN Connection:
o Click the Add VPN button to start the configuration.
o In the window that appears, enter the following details:
 VPN Provider: Windows (built-in)
 Connection Name: Any custom name, such as "VPNBook"
 Server Name or Address: Enter the VPN server address (e.g.,
US2.vpnbook.com).
 VPN Type: Choose PPTP (Point to Point Tunneling Protocol).
 Type of Sign-in Info: Select Username and Password.
 Username and Password: Enter the username and password provided by
VPNBook.

4. Save the VPN Connection:


o After entering all the details, click Save.

5. Connect to the VPN:


o In the VPN settings, you should now see the newly created VPN connection.
o Click on the VPN connection (e.g., VPNBook) and then click Connect to establish
the VPN connection.

6. Verify the VPN Connection:


o Once connected, you can check your IP address by visiting any "What is my IP"
website to confirm that your traffic is routed through the VPN.

After VPN

You might also like