def run_test4(): with CTClient() as c: # syncronous call m.refresh() print('MsgStore opened as ' + str(m)) print() Apriv = PrivateKey() Apriv.randomize(4) Apub = PublicKey.deserialize(Apriv.serialize_pubkey()) Bpriv = PrivateKey() Bpriv.randomize(4) Bpub = PublicKey.deserialize(Apriv.serialize_pubkey()) # asynchronous calls for ver in ['0200']: mtxt = 'the quick brown fox jumped over the lazy dog' msgs = [] print('Encoding messages ') print() for i in range(0,5): msg = Message.encode(mtxt, Bpub, Apriv, version=ver) msgs.append(msg) print('Posting messages') print() slist = [] for msg in msgs: h = MessageHeader.deserialize(msg.serialize_header()) r = yield m.post_message(msg, callback=register_message) print('sent async post for ' + h.serialize().decode()) print() mtxt += 'the quick brown fox jumped over the lazy dog'
def run_test1(): with CTClient() as c: # syncronous calls m.refresh() print('MsgStore opened as ' + str(m)) print() hdrs = m.get_headers() print('MsgStore all headers : ' + str(hdrs)) print() peers = m.get_peers() print('MsgStore found ' + str(len(peers)) + ' peers : ') for p in peers: print(' ' + str(p)) print() for i in range(0,5): h = random.choice(hdrs) msg = m.get_message(h) print('random message retreived as ' + msg.serialize().decode()) msg_test = m.get_message_by_id(h.Iraw()) assert msg == msg_test #print('random message retreived as ' + msg_test.serialize().decode()) print() Apriv = PrivateKey() Apriv.randomize(4) Apub = PublicKey.deserialize(Apriv.serialize_pubkey()) Bpriv = PrivateKey() Bpriv.randomize(4) Bpub = PublicKey.deserialize(Apriv.serialize_pubkey()) mtxt = 'the quick brown fox jumped over the lazy dog' for ver in ['0200']: msg = Message.encode(mtxt, Bpub, Apriv, version=ver) r = m.post_message(msg) print('message posted, server metadata' + str(r)) print()
def run_test1(): with CTClient() as c: # syncronous calls m.refresh() print('MsgStore opened as ' + str(m)) print() hdrs = m.get_headers() print('MsgStore all headers : ' + str(hdrs)) print() peers = m.get_peers() print('MsgStore found ' + str(len(peers)) + ' peers : ') for p in peers: print(' ' + str(p)) print() for i in range(0, 5): h = random.choice(hdrs) msg = m.get_message(h) print('random message retreived as ' + msg.serialize().decode()) msg_test = m.get_message_by_id(h.Iraw()) assert msg == msg_test #print('random message retreived as ' + msg_test.serialize().decode()) print() Apriv = PrivateKey() Apriv.randomize(4) Apub = PublicKey.deserialize(Apriv.serialize_pubkey()) Bpriv = PrivateKey() Bpriv.randomize(4) Bpub = PublicKey.deserialize(Apriv.serialize_pubkey()) mtxt = 'the quick brown fox jumped over the lazy dog' for ver in ['0200']: msg = Message.encode(mtxt, Bpub, Apriv, version=ver) r = m.post_message(msg) print('message posted, server metadata' + str(r)) print()
def run_test4(): with CTClient() as c: # syncronous call m.refresh() print('MsgStore opened as ' + str(m)) print() Apriv = PrivateKey() Apriv.randomize(4) Apub = PublicKey.deserialize(Apriv.serialize_pubkey()) Bpriv = PrivateKey() Bpriv.randomize(4) Bpub = PublicKey.deserialize(Apriv.serialize_pubkey()) # asynchronous calls for ver in ['0200']: mtxt = 'the quick brown fox jumped over the lazy dog' msgs = [] print('Encoding messages ') print() for i in range(0, 5): msg = Message.encode(mtxt, Bpub, Apriv, version=ver) msgs.append(msg) print('Posting messages') print() slist = [] for msg in msgs: h = MessageHeader.deserialize(msg.serialize_header()) r = yield m.post_message(msg, callback=register_message) print('sent async post for ' + h.serialize().decode()) print() mtxt += 'the quick brown fox jumped over the lazy dog'
def run_test10(): with CTClient() as c: # synchronous onion post m.refresh() m2.refresh() peers = m.get_peers() hdrs = m.get_headers() onions = [] for p in peers: onion = MsgStore(p['host'], p['port']) onion.refresh() if onion.Pkey is not None: onions.append(onion) nonion = len(onions) print('found ' + str(nonion) + ' onion hosts') for o in onions: print(' ' + str(o)) onion._sync_headers() Apriv = PrivateKey() Apriv.randomize(4) Apub = PublicKey.deserialize(Apriv.serialize_pubkey()) Bpriv = PrivateKey() Bpriv.randomize(4) Bpub = PublicKey.deserialize(Apriv.serialize_pubkey()) # asynchronous calls for ver in ['0200']: mtxt = 'the quick brown fox jumped over the lazy dog' msgs = [] print('Encoding messages ') print() for i in range(0, 5): msg = Message.encode(mtxt, Bpub, Apriv, version=ver) msgs.append(msg) for msg in msgs: h = MessageHeader.deserialize(msg.serialize_header()) orand = random.sample(onions, min(nonion - 1, 3)) print('posting via onions') for o in orand: print(' ' + str(o)) print() r = yield orand[0].post_message(msg, nak=nak, onions=orand[1:], callback=register_message) # conf = m.post_message(msg, nak=nak, onions=[m, m2]) # conf = m2.post_message(msg, nak=nak, onions=[m2]) print('sent post for header ' + h.serialize().decode()) print() # msg = m.get_message(h, nak=nak, onions=[m, m2])
def run_test10(): with CTClient() as c: # synchronous onion post m.refresh() m2.refresh() peers = m.get_peers() hdrs = m.get_headers() onions = [] for p in peers: onion = MsgStore(p['host'], p['port']) onion.refresh() if onion.Pkey is not None: onions.append(onion) nonion = len(onions) print('found ' + str(nonion) + ' onion hosts') for o in onions: print(' ' + str(o)) onion._sync_headers() Apriv = PrivateKey() Apriv.randomize(4) Apub = PublicKey.deserialize(Apriv.serialize_pubkey()) Bpriv = PrivateKey() Bpriv.randomize(4) Bpub = PublicKey.deserialize(Apriv.serialize_pubkey()) # asynchronous calls for ver in ['0200']: mtxt = 'the quick brown fox jumped over the lazy dog' msgs = [] print('Encoding messages ') print() for i in range(0,5): msg = Message.encode(mtxt, Bpub, Apriv, version=ver) msgs.append(msg) for msg in msgs: h = MessageHeader.deserialize(msg.serialize_header()) orand = random.sample(onions, min(nonion-1,3)) print('posting via onions') for o in orand: print(' ' + str(o)) print() r = yield orand[0].post_message(msg, nak=nak, onions=orand[1:], callback=register_message) # conf = m.post_message(msg, nak=nak, onions=[m, m2]) # conf = m2.post_message(msg, nak=nak, onions=[m2]) print('sent post for header ' + h.serialize().decode()) print()# msg = m.get_message(h, nak=nak, onions=[m, m2])
import sys sys.setrecursionlimit(512) alice = PrivateKey(name='Alice') alice.set_metadata('phone', '555-555-1212') print('name =', alice.name) print('phone=', alice.get_metadata('phone')) bob = PrivateKey() for i in range(100): alice.randomize(4) bob.randomize(4) print('p= ' + str(alice)) ex = alice.serialize_pubkey() print('P=', str(ex)) print('\n') apub = PublicKey.deserialize(ex) print('Q=', apub.serialize_pubkey()) ex = alice.serialize_privkey() print(ex) apriv = PrivateKey.deserialize(ex) print('q=', apriv.serialize_privkey()) assert alice.serialize_privkey() == apriv.serialize_privkey() assert alice.serialize_pubkey() == apub.serialize_pubkey() ex = bob.serialize_pubkey() bpub = PublicKey.deserialize(ex) for j in range(100): future = int(random.randint(int(time.time()), 0x7fffffff)) z = alice.current_privkey_val(future) Z = alice.current_pubkey_point(future) W = (_G_Pt * z) assert Z == W
from ciphrtxt.message import Message from argparse import ArgumentParser import sys parser = ArgumentParser( description= 'read message plaintext from stdin and write encoded message to stdout') parser.add_argument('recipient', help='recipient public key (hint: starts with P0100)') parser.add_argument('--sender', default=None, help='sender private key (optional, omit for anonymous)') clargs = parser.parse_args() f_key = None if clargs.sender: f_key = PrivateKey.deserialize(clargs.sender) if f_key is None: print('Error: unable to parse sender key', file=sys.stderr) exit() t_key = PublicKey.deserialize(clargs.recipient) if t_key is None: print('Error: unable to parse recipient key', file=sys.stderr) exit() ptext = sys.stdin.read() msg = Message.encode(ptext, t_key, f_key) sys.stdout.write(msg.serialize().decode())
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. from ciphrtxt.keys import PrivateKey, PublicKey from ciphrtxt.message import Message from argparse import ArgumentParser import sys parser = ArgumentParser(description='read encoded message from stdin and write message plaintext to stdout') parser.add_argument('recipient', default='', help='recipient private key (hint: starts with p0100)') parser.add_argument('--sender', default=None, help='sender public key (optional for signature verification)') clargs = parser.parse_args() f_key = None if clargs.sender: f_key = PublicKey.deserialize(clargs.sender) if f_key is None: print('Error: unable to parse sender key', file=sys.stderr) exit() t_key = PrivateKey.deserialize(clargs.recipient) if t_key is None: print('Error: unable to parse recipient key', file=sys.stderr) exit() ctext = sys.stdin.read() msg = Message.deserialize(ctext) if not msg.decode(t_key): print('Error: cannot decrypt message', file=sys.stderr) exit()
def progress(status): print("hash = %x, %d bits, %d, %d iterations" % (status['besthash'], status['bestbits'], status['nhash'], status['nhash2'])) pkey = [] Pkey = [] test_keys = 1500 test_msgs = 1500 print('creating alice keys') alice = PrivateKey() alice.randomize(4) aliceP = PublicKey.deserialize(alice.serialize_pubkey()) print('creating bob keys') bob = PrivateKey() bob.randomize(4) bobP = PublicKey.deserialize(bob.serialize_pubkey()) print('keys complete') mtxt = 'the quick brown fox jumped over the lazy dog' msg1 = Message.encode(mtxt, bobP, alice, progress_callback=progress, version="0100") print('message1 = ' + str(msg1)) print(' header ' + str(msg1.serialize_header())) print(' hash ' + str(sha256(msg1.serialize_header()).hexdigest())) msg1a = Message.deserialize(msg1.serialize()) print('message1a = ' + str(msg1a)) print(' header ' + str(msg1a.serialize_header())) print(' hash ' + str(sha256(msg1a.serialize_header()).hexdigest()))
def progress(status): print("hash = %x, %d bits, %d, %d iterations" % (status['besthash'], status['bestbits'], status['nhash'], status['nhash2'])) pkey = [] Pkey = [] test_keys = 1500 test_msgs = 1500 print('creating alice keys') alice = PrivateKey() alice.randomize(4) aliceP = PublicKey.deserialize(alice.serialize_pubkey()) print('creating bob keys') bob = PrivateKey() bob.randomize(4) bobP = PublicKey.deserialize(bob.serialize_pubkey()) print('keys complete') mtxt = 'the quick brown fox jumped over the lazy dog' msg1 = Message.encode(mtxt, bobP, alice, progress_callback=progress, version="0100") print('message1 = ' + str(msg1)) print(' header ' + str(msg1.serialize_header())) print(' hash ' + str(sha256(msg1.serialize_header()).hexdigest()))
parser = ArgumentParser( description= 'read encoded message from stdin and write message plaintext to stdout') parser.add_argument('recipient', default='', help='recipient private key (hint: starts with p0100)') parser.add_argument( '--sender', default=None, help='sender public key (optional for signature verification)') clargs = parser.parse_args() f_key = None if clargs.sender: f_key = PublicKey.deserialize(clargs.sender) if f_key is None: print('Error: unable to parse sender key', file=sys.stderr) exit() t_key = PrivateKey.deserialize(clargs.recipient) if t_key is None: print('Error: unable to parse recipient key', file=sys.stderr) exit() ctext = sys.stdin.read() msg = Message.deserialize(ctext) if not msg.decode(t_key): print('Error: cannot decrypt message', file=sys.stderr) exit()