← Back to kitOffline reference
Experiment 13 — Symmetric XOR and Asymmetric RSA Encryption
Manual pages: 105–107 | Tool: Python
AIM
To simulate symmetric and asymmetric encryption in Python and study encryption/decryption.
PART A — SYMMETRIC XOR PROGRAM
- Terminal in this folder:
python symmetric_xor.py. - Program converts each character to an integer (
ord), applies XOR (^) with shared key7, converts back (chr). - Decryption applies the same XOR key again:
(A ^ K) ^ K == A. - Sample encrypted output is text-like but not secure. XOR with a single reused byte key is educational only.
PART B — ASYMMETRIC RSA PROGRAM
- Install dependency:
python -m pip install cryptography. - Run
python asymmetric_rsa.py. - Generate RSA private key and derive public key; encrypt with public key, decrypt with private key.
- Lab manual uses PKCS#1 v1.5 encryption padding; this kit preserves it to match the manual. Real modern new RSA-encryption designs generally prefer OAEP padding.
EXPECTED OUTPUT
Original Message : NETWORK SECURITY
Encrypted Message: IBSPHUL'TBDRUNS^
Decrypted Message: NETWORK SECURITY
Original Message : HELLO NETWORK SECURITY
Encrypted Message: b'<changing ciphertext>'
Decrypted Message: HELLO NETWORK SECURITY
Manual correction: The page 105 heading mistakenly says Program 1 asymmetric, but the code is actually symmetric XOR. See EXPECTED_OUTPUT.txt.
RESULT
Thus, symmetric XOR and asymmetric RSA encryption/decryption were simulated using Python and the original messages were recovered.
VIVA
- Symmetric uses one shared key for encryption and decryption.
- Asymmetric uses a public/private key pair; RSA is an asymmetric algorithm.
ord,chr,^support XOR example;.encode()/.decode()convert text and bytes.