Project Title: Substitution Cipher Encryption/Decryption System
Student Name: Zaeem Khan
Registration Number: 25MEI10036
Institution: VIT Bhopal University
Course: CSE1021
Submitted To: Professor Sukumar
Date: November 22, 2025
- Introduction
- Features
- Technology Stack
- Installation and Setup
- How to Use
- Program Workflow
- Code Structure
- Algorithm and Logic
- Screenshots
- Security Considerations
- Future Enhancements
- Conclusion
- References
This project implements a Substitution Cipher encryption and decryption system using Python. The program provides a simple yet effective method for encrypting plaintext messages by substituting each character with another character from a randomly shuffled key. The same key is then used to decrypt the encrypted text back to its original form.
The substitution cipher is one of the oldest and simplest encryption techniques, where each character in the plaintext is replaced with a corresponding character from the cipher alphabet. This implementation demonstrates fundamental concepts of cryptography and data security.
- Encryption: Converts plaintext into encrypted ciphertext using a randomly generated substitution key
- Decryption: Converts encrypted text back to original plaintext using the same key
- Character Support: Handles uppercase letters, lowercase letters, digits, and punctuation marks
- Random Key Generation: Creates a unique substitution key each time the program runs
- User-Friendly Interface: Interactive command-line interface for easy operation
- Case Preservation: Maintains the original character set integrity
- Programming Language: Python 3.x
- Libraries Used:
random- For shuffling the character set to create substitution keysstring- For accessing predefined character sets (letters, digits, punctuation)
- Development Environment: Python IDE (VS Code/PyCharm/Jupyter Notebook)
- Python 3.6 or higher installed on your system
- Basic understanding of command-line operations
-
Clone or Download the Project:
git clone <repository-url> cd encryption-decryption-program
-
Verify Python Installation:
python --version
-
Run the Program:
python Encryption-Decryption-Program.py
-
Start the Program:
- Run the Python script from your terminal or IDE
- The welcome message will appear
-
Encryption Process:
- Enter the text you want to encrypt when prompted
- The program will display the encrypted text
-
Decryption Process:
- Enter the encrypted text you want to decrypt
- The program will display the original decrypted text
Welcome to the Encryption/Decryption Program!
Enter the text to encrypt: Zaeem Khan
Encrypted text: uA+rn Z@Ab
Enter the text to decrypt: uA+rn Z@Ab
Decrypted text: Zaeem Khan
The program follows this workflow:
- Initialization: Create character set and generate random substitution key
- User Input: Accept plaintext from user
- Encryption: Transform plaintext using substitution key
- Display Encrypted Text: Show encrypted result
- Decryption Input: Accept encrypted text from user
- Decryption: Transform encrypted text back to plaintext
- Display Decrypted Text: Show original message
The main class that handles all encryption and decryption operations.
Purpose: Initializes the cipher object with character set and substitution key
Process:
- Creates a list of all ASCII letters (uppercase and lowercase)
- Adds digits (0-9)
- Adds punctuation marks
- Creates a copy of this character set
- Shuffles the copy to create a random substitution key
Purpose: Encrypts the input plaintext
Parameters:
plaintext(string): The text to be encrypted
Returns:
- Encrypted text (string)
Logic:
- Iterates through each character in the plaintext
- Finds the index of the character in the original character set
- Replaces it with the character at the same index in the shuffled key
- Returns the encrypted string
Purpose: Decrypts the input encrypted text
Parameters:
encrypted_text(string): The text to be decrypted
Returns:
- Decrypted plaintext (string)
Logic:
- Iterates through each character in the encrypted text
- Finds the index of the character in the shuffled key
- Replaces it with the character at the same index in the original character set
- Returns the decrypted string
Purpose: Main driver function that controls program flow
Process:
- Creates a Cipher object
- Displays welcome message
- Takes plaintext input from user
- Encrypts the plaintext and displays result
- Takes encrypted text input from user
- Decrypts the text and displays result
ALGORITHM SubstitutionCipher
CLASS Cipher:
METHOD __init__():
// Initialize character set and substitution key
chars ← list of (ASCII_LETTERS + DIGITS + PUNCTUATION)
key ← copy of chars
SHUFFLE(key)
END METHOD
METHOD encrypt(plaintext):
// Encrypt plaintext using substitution
encrypted_text ← empty string
FOR each char IN plaintext DO
IF char IN chars THEN
index ← FIND_INDEX(char, chars)
encrypted_char ← key[index]
APPEND encrypted_char TO encrypted_text
ELSE
APPEND char TO encrypted_text
END IF
END FOR
RETURN encrypted_text
END METHOD
METHOD decrypt(encrypted_text):
// Decrypt encrypted text by reverse substitution
decrypted_text ← empty string
FOR each char IN encrypted_text DO
IF char IN key THEN
index ← FIND_INDEX(char, key)
decrypted_char ← chars[index]
APPEND decrypted_char TO decrypted_text
ELSE
APPEND char TO decrypted_text
END IF
END FOR
RETURN decrypted_text
END METHOD
END CLASS
FUNCTION main():
// Main program execution
cipher ← NEW Cipher()
PRINT "Welcome to the Encryption/Decryption Program!"
plaintext ← INPUT "Enter the text to encrypt: "
encrypted ← cipher.encrypt(plaintext)
PRINT "Encrypted text: " + encrypted
encrypted_input ← INPUT "Enter the text to decrypt: "
decrypted ← cipher.decrypt(encrypted_input)
PRINT "Decrypted text: " + decrypted
END FUNCTION
// Program entry point
IF __name__ == "__main__":
CALL main()
END IF
- Initialization: O(n log n) where n is the size of character set (due to shuffling)
- Encryption: O(m × n) where m is the length of plaintext and n is the size of character set
- Decryption: O(m × n) where m is the length of encrypted text
- O(n) where n is the size of the character set (for storing chars and key lists)
The screenshot shows the complete implementation of the Cipher class with encryption and decryption methods.
The screenshot demonstrates the program in action:
- Input: "Zaeem Khan"
- Encrypted Output: "uA+rn Z@Ab"
- Decrypted Output: "Zaeem Khan"
- Simple Implementation: Easy to understand and implement
- Random Key Generation: Each execution creates a unique substitution pattern
- Character Variety: Supports letters, digits, and punctuation
- Frequency Analysis Vulnerability: Substitution ciphers can be broken using frequency analysis of letters
- Key Management: The key must be securely shared between sender and receiver
- Same Session Limitation: The key changes with each program execution, making it unsuitable for multi-session communication
- No Key Persistence: Current implementation doesn't save or load keys
- Statistical Attacks: Vulnerable to statistical cryptanalysis methods
- Implement key persistence mechanism
- Add key export/import functionality
- Consider implementing more secure encryption algorithms (AES, RSA)
- Add file encryption capabilities
- Implement digital signatures for authentication
- GUI Implementation: Develop a graphical user interface using Tkinter or PyQt
- File Encryption: Add capability to encrypt and decrypt files
- Key Management System: Implement secure key storage and retrieval
- Multiple Cipher Support: Add support for other cipher techniques (Caesar, Vigenère, etc.)
- Network Communication: Enable encrypted message transmission over networks
- Password Protection: Add password-based encryption for additional security
- Batch Processing: Support encryption/decryption of multiple texts at once
- Error Handling: Implement comprehensive error handling and validation
- Logging System: Add logging for encryption/decryption operations
- Unit Testing: Develop comprehensive test suite for all functionalities
This Substitution Cipher project successfully demonstrates fundamental concepts of cryptography and data security. The program provides a practical implementation of classical encryption techniques using Python programming. While the substitution cipher has known vulnerabilities, it serves as an excellent educational tool for understanding encryption principles and provides a foundation for exploring more advanced cryptographic systems.
The project showcases object-oriented programming concepts, string manipulation, and user interaction in Python. It can be extended with additional features to create a more robust and secure encryption system suitable for real-world applications.
-
Python Documentation:
- Official Python String Module: https://docs.python.org/3/library/string.html
- Official Python Random Module: https://docs.python.org/3/library/random.html
-
Cryptography Concepts:
- Schneier, B. (1996). Applied Cryptography: Protocols, Algorithms, and Source Code in C. Wiley.
- Singh, S. (1999). The Code Book: The Science of Secrecy from Ancient Egypt to Quantum Cryptography. Doubleday.
-
Substitution Cipher:
- Classical Cipher Techniques: https://en.wikipedia.org/wiki/Substitution_cipher
- Introduction to Cryptography (Online Courses and Tutorials)
-
Python Programming:
- McKinney, W. (2017). Python for Data Analysis. O'Reilly Media.
- Lutz, M. (2013). Learning Python. O'Reilly Media.
Student: Zaeem Khan
Registration Number: 25MEI10036
Institution: VIT Bhopal University
Department: Computer Science and Engineering
Supervisor: Professor Sukumar
This project is submitted as an academic assignment for VIT Bhopal University. All rights reserved.
End of README


