CYB318 Assignment Ayomide
CYB318 Assignment Ayomide
ASSIGNMENT
QUESTIONS
1. Compare RSA vs AES encryption using a Python script to analyze speed differences.
2. Set up a basic firewall rule with iptables (Linux) or Windows Defender Firewall.
3. Capture and analyze HTTPS traffic using Wireshark, examining encryption processes.
4. Set up a VPN using OpenVPN or WireGuard on virtual machines.
ANSWERS
1. 1. Comparison of RSA vs AES Encryption using Python:
Python Code:
from cryptography.hazmat.primitives.asymmetric import rsa, padding
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.primitives import serialization, hashes
import os, time
message = b"Cybersecurity Speed Test Message" * 100
key = os.urandom(32)
iv = os.urandom(16)
cipher = Cipher(algorithms.AES(key), modes.CFB(iv))
encryptor = cipher.encryptor()
start_aes = time.time()
aes_encrypted = encryptor.update(message) + encryptor.finalize()
end_aes = time.time()
private_key = rsa.generate_private_key(public_exponent=65537, key_size=2048)
public_key = private_key.public_key()
start_rsa = time.time()
rsa_encrypted = public_key.encrypt(message[:190],
padding.OAEP(mgf=padding.MGF1(algorithm=hashes.SHA256()), algorithm=hashes.SHA256(), label=None))
end_rsa = time.time()
print(f"AES Encryption Time: {end_aes - start_aes:.6f} seconds")
print(f"RSA Encryption Time: {end_rsa - start_rsa:.6f} seconds")
Sample Output:
AES Encryption Time: 0.000432 seconds
RSA Encryption Time: 0.002842 seconds
Linux (iptables):
sudo iptables -A INPUT -p tcp --dport 22 -j DROP
Windows (PowerShell):
New-NetFirewallRule -DisplayName "Block HTTP" -Direction Inbound -Protocol TCP -LocalPort 80
-Action Block
Steps:
1. Open Wireshark.
2. Start capture on your network interface.
3. Visit https://example.com
4. Stop capture.
5. Use filter: tls
Look for TLS handshake steps like Client Hello, Server Hello, Certificate, Encrypted Handshake.
WireGuard (Ubuntu):
sudo apt install wireguard -y
wg genkey | tee privatekey | wg pubkey > publickey
Config File - /etc/wireguard/wg0.conf:
[Interface]
PrivateKey = <private-key>
Address = 10.0.0.1/24
ListenPort = 51820
[Peer]
PublicKey = <peer-key>
AllowedIPs = 10.0.0.2/32
Start VPN:
sudo wg-quick up wg0
sudo wg