
- Cryptography with Python Tutorial
- Home
- Overview
- Double Strength Encryption
- Python Overview and Installation
- Reverse Cipher
- Caesar Cipher
- ROT13 Algorithm
- Transposition Cipher
- Encryption of Transposition Cipher
- Decryption of Transposition Cipher
- Encryption of files
- Decryption of files
- Base64 Encoding & Decoding
- XOR Process
- Multiplicative Cipher
- Affine Ciphers
- Hacking Monoalphabetic Cipher
- Simple Substitution Cipher
- Testing of Simple Substitution Cipher
- Decryption of Simple Substitution Cipher
- Python Modules of Cryptography
- Understanding Vignere Cipher
- Implementing Vignere Cipher
- One Time Pad Cipher
- Implementation of One Time Pad Cipher
- Symmetric & Asymmetric Cryptography
- Understanding RSA Algorithm
- Creating RSA Keys
- RSA Cipher Encryption
- RSA Cipher Decryption
- Hacking RSA Cipher
- Useful Resources
- Quick Guide
- Resources
- Discussions
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Hacking RSA Cipher
Hacking RSA cipher is possible with small prime numbers, but it is considered impossible if it is used with large numbers. The reasons which specify why it is difficult to hack RSA cipher are as follows −
Brute force attack would not work as there are too many possible keys to work through. Also, this consumes a lot of time.
Dictionary attack will not work in RSA algorithm as the keys are numeric and does not include any characters in it.
Frequency analysis of the characters is very difficult to follow as a single encrypted block represents various characters.
There are no specific mathematical tricks to hack RSA cipher.
The RSA decryption equation is −
M = C^d mod n
With the help of small prime numbers, we can try hacking RSA cipher and the sample code for the same is mentioned below −
def p_and_q(n): data = [] for i in range(2, n): if n % i == 0: data.append(i) return tuple(data) def euler(p, q): return (p - 1) * (q - 1) def private_index(e, euler_v): for i in range(2, euler_v): if i * e % euler_v == 1: return i def decipher(d, n, c): return c ** d % n def main(): e = int(input("input e: ")) n = int(input("input n: ")) c = int(input("input c: ")) # t = 123 # private key = (103, 143) p_and_q_v = p_and_q(n) # print("[p_and_q]: ", p_and_q_v) euler_v = euler(p_and_q_v[0], p_and_q_v[1]) # print("[euler]: ", euler_v) d = private_index(e, euler_v) plain = decipher(d, n, c) print("plain: ", plain) if __name__ == "__main__": main()
Output
The above code produces the following output −
