-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_ecies.py
44 lines (40 loc) · 1.36 KB
/
test_ecies.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
#!/usr/bin/env python2
from __future__ import print_function
import binascii, os
import jmbitcoin as btc
from ecies import encrypt_message, decrypt_message
def test_encrypt_decrypt():
bob_privkey = "02"*32 + "01"
bob_pubkey = btc.privkey_to_pubkey(bob_privkey)
print("encrypting to bob's public key: " , bob_pubkey)
alicemsg = "hello, no cigar, but some beer, and here is some more text."
encrypted = encrypt_message(alicemsg, bob_pubkey)
print(encrypted)
decrypted = decrypt_message(encrypted, bob_privkey)
print(decrypted)
return alicemsg == decrypted
def test_decrypt():
"""Can be used for manually testing compatibility;
shows compatibility with Electrum as of now.
"""
privkey = raw_input("Enter privkey:")
print("Got privkey: ", privkey)
enc_msg = raw_input("Enter encrypted message:")
print("Got encrypted message: ", enc_msg)
decrypted = decrypt_message(enc_msg, privkey)
print("Got decrypted message: ")
print(decrypted)
def test_encrypt():
"""Comment as for test_decrypt
"""
pubkey = raw_input("Enter pubkey:")
msg = raw_input("Enter plaintext:")
encrypted = encrypt_message(msg, pubkey)
print("Got encrypted message: ")
print(encrypted)
if __name__ == "__main__":
if not test_encrypt_decrypt():
print("Failed")
exit(1)
else:
print("Success")