Data Communication & Networks · 2025–26

DCN Practical Exam Kit

Ten selected experiments · aim, procedure, runnable code, illustrated output and result

← 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

  1. Terminal in this folder: python symmetric_xor.py.
  2. Program converts each character to an integer (ord), applies XOR (^) with shared key 7, converts back (chr).
  3. Decryption applies the same XOR key again: (A ^ K) ^ K == A.
  4. Sample encrypted output is text-like but not secure. XOR with a single reused byte key is educational only.

PART B — ASYMMETRIC RSA PROGRAM

  1. Install dependency: python -m pip install cryptography.
  2. Run python asymmetric_rsa.py.
  3. Generate RSA private key and derive public key; encrypt with public key, decrypt with private key.
  4. 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