Cryptography with Python Tutorial
Useful Resources
Selected Reading
- Hacking RSA Cipher
- RSA Cipher Decryption
- RSA Cipher Encryption
- Creating RSA Keys
- Understanding RSA Algorithm
- Symmetric & Asymmetric Cryptography
- Implementation of One Time Pad Cipher
- One Time Pad Cipher
- Implementing Vignere Cipher
- Understanding Vignere Cipher
- Python Modules of Cryptography
- Decryption of Simple Substitution Cipher
- Testing of Simple Substitution Cipher
- Simple Substitution Cipher
- Hacking Monoalphabetic Cipher
- Affine Ciphers
- Multiplicative Cipher
- XOR Process
- Base64 Encoding & Decoding
- Decryption of files
- Encryption of files
- Decryption of Transposition Cipher
- Encryption of Transposition Cipher
- Transposition Cipher
- ROT13 Algorithm
- Caesar Cipher
- Reverse Cipher
- Python Overview and Installation
- Double Strength Encryption
- Overview
- Home
Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Testing of Simple Substitution Cipher
Testing of Simple Substitution Cipher
In this chapter, we will focus on testing substitution cipher using various methods, which helps to generate random strings as given below −
import random, string, substitution def main(): for i in range(1000): key = substitution.getRandomKey() message = random_string() print( Test %s: String: "%s.." % (i + 1, message[:50])) print("Key: " + key) encrypted = substitution.translateMessage(message, key, E ) decrypted = substitution.translateMessage(encrypted, key, D ) if decrypted != message: print( ERROR: Decrypted: "%s" Key: %s % (decrypted, key)) sys.exit() print( Substutition test passed! ) def random_string(size = 5000, chars = string.ascii_letters + string.digits): return .join(random.choice(chars) for _ in range(size)) if __name__ == __main__ : main()
Output
You can observe the output as randomly generated strings which helps in generating random plain text messages, as shown below −
After the test is successfully completed, we can observe the output message Substitution test passed!.
Thus, you can hack a substitution cipher in the systematic manner.
Advertisements