Exp No:1a
IMPLEMENTATION OF SYMMETRIC ALGORITHM
Date: (DES ALGORITHM)
AIM:
To implement the Symmetric DES Algorithm using python program.
ALGORITHM:
Step 1: Take 8-bit binary plaintext and 8-bit binary key.
Step 2: Split plaintext into two 4-bit halves: left and right.
Step 3: For encryption, perform 4 Feistel rounds using the same key.
Step 4: In each round, compute a function f(right, key) using XOR.
Step 5: Update halves: new_right = left XOR f(right, key) and swap.
Step 6: After 4 rounds, combine left and right as ciphertext.
Step 7: For decryption, repeat 4 rounds with swapped order of halves.
Step 8: Combine final halves to get the original plaintext.
PROGRAM:
def xor(a, b):
return ''.join(['0' if i == j else '1' for i, j in zip(a, b)])
def f(right, key):
return xor(right, key)
def feistel_round(left, right, key):
new_right = xor(left, f(right, key))
return right, new_right
def encrypt(plaintext, key):
left = plaintext[:4]
right = plaintext[4:]
for i in range(4):
left, right = feistel_round(left, right, key)
return left + right
def decrypt(ciphertext, key):
left = ciphertext[:4]
right = ciphertext[4:]
for i in range(4):
right, left = feistel_round(right, left, key)
return left + right
plaintext = '11010111'
key = '10101010'
ciphertext = encrypt(plaintext, key)
print("Encrypted:", ciphertext)
decrypted = decrypt(ciphertext, key)
print("Decrypted:", decrypted)
OUTPUT:
Encrypted: 01110000
Decrypted: 11010111
RESULT:
Thus the python program to implement Symmetric DES algorithm was executed successfully.
Exp No:1b
IMPLEMENTATION OF SYMMETRIC ALGORITHM
Date: (AES ALGORITHM)
AIM:
To implement the Symmetric AES Algorithm using python program.
ALGORITHM:
Step 1: Generate a 16-byte symmetric key.
Step 2: Prepare the plaintext message in bytes.
Step 3: Create AES cipher in CBC mode using the key and IV.
Step 4: Pad the plaintext to match AES block size.
Step 5: Encrypt the padded plaintext using the AES cipher.
Step 6: Create a new AES cipher with the same key and IV.
Step 7: Decrypt the ciphertext and unpad it.
Step 8: Output the encrypted and decrypted messages.
PROGRAM:
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad, unpad
from Crypto.Random import get_random_bytes
def aes_encrypt_decrypt():
key = get_random_bytes(16)
data = b"Hello AES User"
cipher = AES.new(key, AES.MODE_CBC)
ct = cipher.encrypt(pad(data, AES.block_size))
print("Encrypted:", ct)
cipher_dec = AES.new(key, AES.MODE_CBC, iv=cipher.iv)
pt = unpad(cipher_dec.decrypt(ct), AES.block_size)
print("Decrypted:", pt)
aes_encrypt_decrypt()
OUTPUT:
Encrypted: b"Dvc\x9eP'\x00\xb3e\xbc\xbfF\xbd\xec\xefF"
Decrypted: b'Hello AES User'
RESULT:
Thus the python program to implement Symmetric AES algorithm was executed successfully.
Exp No:1c
IMPLEMENTATION OF SYMMETRIC ALGORITHM
Date: (ADDITIVE CHIPHER ALGORITHM)
AIM:
To implement the Symmetric Additive Chipher Algorithm using python program.
ALGORITHM:
Step 1: Take a plaintext message and a numerical key.
Step 2: For encryption, shift each letter by the key's value.
Step 3: Wrap around if shifting goes past 'Z' or 'z'.
Step 4: Preserve the case (uppercase/lowercase) of each letter.
Step 5: Leave non-alphabetic characters unchanged.
Step 6: Collect and print the encrypted result (ciphertext).
Step 7: For decryption, shift letters by the negative of the key.
Step 8: Output the original plaintext after decryption.
PROGRAM:
def encrypt(text, key):
result = ''
for char in text:
if char.isalpha():
shift = ord('A') if char.isupper() else ord('a')
result += chr((ord(char) - shift + key) % 26 + shift)
else:
result += char
return result
def decrypt(cipher, key):
return encrypt(cipher, -key)
plaintext = "HELLOworld"
key = 3
ciphertext = encrypt(plaintext, key)
print("Encrypted:", ciphertext)
decrypted = decrypt(ciphertext, key)
print("Decrypted:", decrypted)
OUTPUT:
Encrypted: KHOORzruog
Decrypted: HELLOworld
RESULT:
Thus the python program to implement Symmetric Additive Chiper algorithm was executed
successfully.
Exp No:2a
IMPLEMENTATION OF ASYMMETRIC ALGORITHM
Date: (RSA ALGORITHM)
AIM:
To implement the Asymmetric RSA Algorithm using python program.
ALGORITHM:
Step1: Start by taking two prime numbers p and q, and an integer message that needs to be
encrypted and decrypted.
Step2: Multiply p and q to get n, which will be used as part of both the public and private keys.
Step3: Calculate Euler's totient function t as (p - 1) * (q - 1), which is required to determine
valid encryption and decryption keys.
Step4: Choose a number e such that 1 < e < t and gcd(e, t) = 1, meaning e and t are coprime;
this e will act as the encryption exponent.
Step5: Find a number d such that (d * e) % t = 1, which means d is the modular multiplicative
inverse of e modulo t; this d will serve as the decryption exponent.
Step6: Encrypt the message by raising it to the power of e and taking the result modulo n, ct =
(message ^ e) % n.
Step7: Decrypt the encrypted message by raising it to the power of d and taking the result
modulo n, mes = (ct ^ d) % n.
Step8: Finally, print the public key value d, the encrypted message ct, and the decrypted
message mes to verify the RSA process.
PROGRAM:
from math import gcd
def RSA(p: int, q: int, message: int):
n=p*q
t = (p - 1) * (q - 1)
for i in range(2, t):
if gcd(i, t) == 1:
e=i
break
j=0
while True:
if (j * e) % t == 1:
d=j
break
j += 1
print("The value of Public key", d)
ct = (message ** e) % n
print(f"Encrypted message is {ct}")
mes = (ct ** d) % n
print(f"Decrypted message is {mes}")
RSA(p=3, q=11, message=2)
RSA(p=3, q=7, message=12)
OUTPUT:
The value of Public key 7
Encrypted message is 8
Decrypted message is 2
The value of Public key 5
Encrypted message is 3
Decrypted message is 12
RESULT:
Thus the python program to implement Asymmetric RSA algorithm was executed successfully.
Exp No:2b
Implementation of Asymmetric Key Algorithm
Date: (Diffie-Hellman Key Exchange Algorithm)
AIM:
To implement the Asymmetric Diffie-Hellman Key Exchange Algorithm using python program.
ALGORITHM:
Step 1: Select a prime number P and its primitive root G as public keys.
Step 2: Sender selects a private key.
Step 3: Receiver selects a private key.
Step 4: Sender computes their public key using G^a mod P.
Step 5: Receiver computes their public key using G^b mod P.
Step 6: Sender receives the Receiver's public key and computes the shared key.
Step 7: Receiver receives the Sender's public key and computes the shared key.
Step 8: Both Sender and Receiver now share the same secret key.
PROGRAM:
def power(a, b, p):
return pow(a, b, p)
def main():
P = 23
G=9
print("The value of P:", P)
print("The value of G:", G)
sender_private = 4
print("Sender's private key:", sender_private)
sender_public = power(G, sender_private, P)
receiver_private = 3
print("Receiver's private key:", receiver_private)
receiver_public = power(G, receiver_private, P)
sender_secret = power(receiver_public, sender_private, P)
receiver_secret = power(sender_public, receiver_private, P)
print("Secret key for Sender is:", sender_secret)
print("Secret key for Receiver is:", receiver_secret)
if __name__ == "__main__":
main()
OUTPUT:
The value of P: 23
The value of G: 9
Sender's private key: 4
Receiver's private key: 3
Secret key for Sender is: 9
Secret key for Receiver is: 9
RESULT:
Thus the python program to implement the Asymmetric Diffie-Hellman Key Exchange Algorithm
was executed successfully.
Exp No:3 IMPLEMENTATION OF DIGITAL SIGNATURE SCHEMES
Date:
AIM:
To implement the Digital Signature Schemes using python program.
ALGORITHM:
Step 1: Generate an RSA private key with a specified public exponent and key size.
Step 2: Obtain the corresponding public key from the generated private key.
Step 3: Specify the message to be digitally signed in byte format.
Step 4: Use the private key to create a digital signature for the message, applying PSS
padding and the SHA-256 hash function.
Step 5: Convert the generated digital signature into a hexadecimal string and display it.
Step 6: Set up the verification process using the public key, the original message, the
signature, and the same padding and hash function.
Step7: Attempt to verify the digital signature using the public key and provided
parameters.
Step 8: If verification succeeds, indicate that the signature is valid.
Step 9: If verification fails, catch the error and indicate that the signature verification
failed.
Step 10: End the process after demonstrating both signing and verification of the digital
signature.
PROGRAM:
from cryptography.hazmat.primitives.asymmetric import rsa, padding
from cryptography.hazmat.primitives import hashes
private_key = rsa.generate_private_key(
public_exponent=65537,
key_size=2048)
public_key = private_key.public_key()
message = b"Hello, this is a digitally signed message."
signature = private_key.sign(
message,
padding.PSS(mgf=padding.MGF1(hashes.SHA256()),
salt_length=padding.PSS.MAX_LENGTH),
hashes.SHA256())
print("Digital Signature:", signature.hex())
try:
public_key.verify(
signature,
message,
padding.PSS(
mgf=padding.MGF1(hashes.SHA256()),
salt_length=padding.PSS.MAX_LENGTH),
hashes.SHA256() )
print("Signature is valid!")
except Exception as e:
print("Signature verification failed:", str(e))
OUTPUT:
Digital Signature:
7de21893332eb7158da665945f2e5b8dc4b3dd2ccd725de017a900fc511f757d66c5afde72c5b4d0afbe
425e0c07a10891d77f51ce0f283106477a43c05501f755c3b9625e688d79e38bc83f1a3bfce541f1dd01
b5109bbf3b83a69545b6575993df4b96e1380c61564eebd4ea93e323d376804f0f133f9f46c412675de8
1d3236b1f89036aeef6e1d5ff32a724a5916294701fe9d3dbcbcdf3d13e8776c5918b551f5e5b94ce197c
cb17e87527ce38e8f7b2ed47c61e98010d235f987fca32e33fc402d212ac494bee897edc4a885e31aad11
53ee3218ec2fa8ad401643abf52a50f5ee79fa1283e993a2bd2527705b97901b0507b467087856a7cfcd
a15e05
Signature is valid!
RESULT:
Thus the python program to implement the Digital Signature Schemes was executed successfully.
Exp No:4 STUDY TO CONFIGURE FIREWALL, VPN
Date:
AIM:
To study and configure firewall and VPN in windows Operating System.
PROCEDURE FOR CONFIGURING FIREWALL AND VPN:
Working with Windows Firewall in Windows 7 Firewall
in Windows 7
Windows 7 comes with two firewalls that work together. One is the Windows Firewall,
and the other is Windows Firewall with Advanced Security (WFAS). The main difference between
them is the complexity of the rules configuration. Windows Firewall uses simple rules that directly
relate to a program or a service. The rules in WFAS can be configured based on protocols, ports,
addresses and authentication. By default, both firewalls come with predefined set of rules that allow
us to utilize network resources. This includes things like browsing the web, receiving e-mails,
etc.Other standard firewall exceptions are File and Printer Sharing, Network Discovery, Performance
Logs and Alerts, Remote Administration, Windows Remote Management, Remote Assistance,
Remote Desktop, Windows Media Player, Windows Media Player Network Sharing Service.
With firewall in Windows 7 we can configure inbound and outbound rules. By default,
all outbound traffic is allowed, and inbound responses to that traffic are also allowed. Inbound traffic
initiated from external sources is automatically blocked.
Configuring Windows Firewall
To open Windows Firewall we can go to Start > Control Panel > Windows Firewall.
It is also configured to block all connections to programs that are not on the list of
allowed programs. To configure exceptions we can go to the menu on the left and select "Allow a
program or feature trough Windows Firewall" option.
To change settings in this window we have to click the "Change settings" button. the Core
Networking feature is allowed on both private and public networks, while the File and Printer
Sharing is only allowed on private networks.
If we have a program on our computer that is not in this list, we can manually add it by
clicking on the "Allow another program" button.
Program will be allowed to communicate by clicking on the "Network location types" button.
Windows Firewall can be turned off completely. To do that selects the "Turn Windows
Firewall on or off" option from the menu on the left.
Windows Firewall is actually a Windows service. As you know, services can be stopped
and started. If the Windows Firewall service is stopped, the Windows Firewall will not work.
RESULT:
Thus the program to study and configure firewall and VPN in windows Operating System was
implemented successfully.
Exp No:5
Installation of Wireshark, TCPdump and observe the data
Date: transferred in client- server communication using
UDP/TCP and Identify the UDP/TCP datagram.
AIM:
To install wireshark, TCPdump and observe the data transferred in client server
communication using UDP/TCP and Identify the UDP/TCP datagram.
Wireshark:
• Wireshark is an open-source tool for profiling network traffic and analyzing packets. Such
tool is often referred as a network analyzer, network protocol analyzer or sniffer.
• It is used to understand how communication takes place across a network and to analyze
what went wrong when an issue in communication arises.
• It captures network traffic from ethernet, Bluetooth, wireless (IEEE.802.11), token ring,
and frame relay connections, among others, and stores that data for offline analysis.
• Wireshark allows you to filter the log before the capture starts or during analysis, For
example, you can set a filter to see TCP traffic between two IP addresses, or you can set it
only to show you the packets sent from one computer. The filters in Wireshark are one of
the primary reasons it has become the standard tool for packet analysis.
Installation of Wireshark:
Step 1: Your first step is to head to the Wireshark download page
https://www.wireshark.org/download.html and locate the Windows installer.
Step 2: You will be presented with the Wireshark wizard to guide you through the installation.
Click “Next.”
Step 3: Next, you can review, agree to the license agreement, and click “Noted” to continue.
Step 4: You will be asked what components you want to install. You can make your choice and then
click “Next.”
Step 5: Choose a directory to install Wireshark in, showing you the space required to install it.
Step 6: Install Ncap.
Ncap is an open-source library for packet capture and network analysis which allows Wireshark
to capture and analyze network traffic effectively. It enhances Wireshark's capabilities by
providing optimized packet capture.
Step 7: The next screen will ask if you want to install USB Pcap, an open-source USB packet capture
utility that lets you capture raw USB traffic, helping analyze and troubleshoot USB devices, this is not
mandatory. Click “Install” to begin the installation.
Step 8: Wireshark will now begin the installation process. A window will pop up during installation to
install cap.
Step 9: Ncap will begin the installation; click “Next” once complete.
Step 10: Wireshark will now complete its installation. Once complete, you can click “Next.”
Step 11: On the last window, click “Finish” to complete the setup.
Step 12: Wireshark will now be installed, and you can begin packet capturing.
When you install the wireshark program, the wireshark GUI with no data will be displayed.Select one
of the wireshark interface, eth0, eth1 will be displayed. Click “Start”for interface eth0to begin the
Packet capture. All packets being sent/received from/by the computer are now being captured by
wireshark. Click”Start”.
Wireshark User Interface:
The wireshark interface has 5 major components;
▪ The Command menus are the standard pulldown menus located at top.
▪ The Packet listing window displays a one-line summary for each
packet captured, it includes Packet number, Packet captured time,
Packet’s source & destination address, Protocol type, Protocol specific information.
▪ The Packet header details window provides about packet selected in the packet listing
window. It includes details about Ethernet frame and IP datagram of the packet. If the
packet has been carried over by TCP/UDP, that details will also be displayed.
▪ Packet contents window display entire contents of the captured frame in both ASCII and
hexadecimal format.
▪ In the Packet display filter field, the protocol name or other information can be entered to
filter the information displayed in packet listing window.
Capturing Packets:
After installing and downloading wireshark, Launch it and click the name of an interface
underInyerface List to start capturing packets.
Test Run:
Start any browser>Start the wireshark software > Select an interface > Stop wireshark packet
capture once the browser has been displayed.
Colour coding:
Packets will be highlighted in blue, green, black which helps to identify the types of traffic.
Green >TCP traffic, Dark Blue > DNS traffic, Light Blue > UDP traffic, Black > TCP
packets with problems.
Inspecting Packets:
Click on any packet and go to the bottom pane.
Inspecting Packet flow:
We have a live packet data that contains all protocol message exchanged between your computer
and other network entities. To filter the connection and to get a clear data type “http” in the
filtering field. Note that directly typing the destination will not work as wireshark doesn’t have
ability to discern the protocols field. To get more precise data set
http.host==www.netwoksecurity.eduRight click on any packet Select “Follow
UDP Stream”.
Close the window, change filter back to
“http.host==www.networksecurity.edu” follow a packet from the list that matches the filter. Use
“Contains with other protocols.”
TCPdump:
• TCP (Transmission Control Protocol) facilitates the transmission of packets from source to
destination.
• Tcpdump is a command line utility that allows you to capture and analyze network traffic
going through your system. It is often used to help troubleshoot network issues, as well as a
security tool.
• It is a network monitoring and management utility that captures and records TCP/IP data on
the run time. Tcpdump is designed to provide statistics about the number of packets received
and captured at the operating node for network performance analysis, debugging and
diagnosing network bottlenecks and other network-oriented tasks.
Identifying UDP/TCP datagram:
• IP packets have 8-bit header (Protocol for v4 and Next Header in v6) which determines which
transport-layer protocol is used in the payload. For example, if it's 6, the payload is a TCP
segment, and if it's 17 then that is an UDP.
• TCP is connection-oriented while UDP is connectionless.
• TCP sends data in a particular sequence, whereas there is no fixed order for UDP protocol.
RESULT:
Thus the program to install wireshark, TCPdump and observe the data transferred in client server
communication using UDP/TCP and Identify the UDP/TCP datagram was executed successfully.