-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathkeycracker.py
88 lines (62 loc) · 1.66 KB
/
keycracker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/python
#
# keycracker.py - Key Cracker testing
#
# Mayank Gureja (ECE-C 353), Ayush Sobti (CS 283)
#
# Sun Aug 19 19:57:35 EDT 2012
import sys
import miniRSA
def decrypt(message, e, c) :
"""
Method to decrypt incoming message using given public keys
"""
words = message.split(",");
decrypted_data = "";
for i in range(0, len(words)-1) :
decrypted_data += str(miniRSA.decode(miniRSA.endecrypt(words[i], e, c)))
return decrypted_data
def test_example() :
"""
Automated text example for key cracking
"""
e, c = 277, 737
d = miniRSA.key_cracker(e, c)
print "\n** Private key: (%0d, %0d) **\n" % (d, c)
message = "37,635,418,54"
print "Message to decrypt: %s\n" % message
print "Decrypted message:"
print decrypt(message, e, c)
def test_keycracker() :
"""
Uses user input to test key cracking
"""
e = int(raw_input("\nEnter e from public key to crack: "))
c = int(raw_input("Enter c from public key to crack: "))
d = miniRSA.key_cracker(e, c)
print "\n** Private key: (%0d, %0d) **\n" % (d, c)
message = str(raw_input("Enter message to crack (no spaces): "))
print "Decrypted message:"
print decrypt(message, e, c)
def main() :
"""
Main
"""
while(1) :
print "\n***** MAIN MENU *****"
print "1. Test Key Cracker with coded example"
print "2. Test Key Cracker with your own example"
print "0. Exit"
print "***********************"
option = int(raw_input("Your option: "))
if option == 1 :
test_example()
elif option == 2 :
test_keycracker()
elif option == 0 :
print "Quiting..."
sys.exit(0)
else :
raw_input("\n* ERROR - Input is NOT recognized *\nPress Enter to continue")
# Execution begins
main()