A Python program that implements a simple encryption and decryption algorithm for 4-digit integers.
This program provides both encryption and decryption functionality:
- Encryption: Transforms 4-digit numbers using digit manipulation and swapping
- Decryption: Reverses the encryption process to recover original numbers
- Take a 4-digit integer (abcd)
- Add 7 to each digit and apply modulus 10
- Swap positions: 1st↔3rd digit, 2nd↔4th digit
- Output encrypted result
- Take encrypted 4-digit integer
- Add 3 to each digit and apply modulus 10
- Swap positions: 1st↔3rd digit, 2nd↔4th digit
- Output original number
- Interactive command-line interface
- Input validation for 4-digit integers
- Mathematical encryption/decryption
- Clear step-by-step digit manipulation
encryption_program.py- Complete encryption/decryption implementation
- Python 3
- Mathematical operations
- String manipulation
- Algorithm design
Toh Qi Hao
python encryption_program.py
Enter a 4 digits integer for encryption: 1234
==> Encrypted integer is 0189
Enter a 4 digits integer for decryption: 0189
==> Decrypted integer is 1234