Beispiel #1
0
def test_crypt():
	key = b'key'
	message = b'abc'
	key2, message2 = prepare_message(key, message)
	plaintext = [b'abc', [b'', b'pqr']]
	for i in range(100):
		plaintext.append(bytes([randrange(256) for j in range(15)]))
		plaintext.append([b'ab', b'cde'])
	plaintext.append(b'stuv')
	assert decode_and_decrypt_message(key, pack_and_encode_messages([(key2, message2)], plaintext)) == message
Beispiel #2
0
def test_crypt():
    key = b"key"
    message = b"abc"
    key2, message2 = prepare_message(key, message)
    plaintext = [b"abc", [b"", b"pqr"]]
    for i in range(100):
        plaintext.append(bytes([randrange(256) for j in range(15)]))
        plaintext.append([b"ab", b"cde"])
    plaintext.append(b"stuv")
    assert decode_and_decrypt_message(key, pack_and_encode_messages([(key2, message2)], plaintext)) == message
Beispiel #3
0
def encode(preparefunc):
    f = open(argv[1], 'br')
    p = f.read()
    f.close()
    messages = [prepare_message(argv[i].encode('utf-8'), argv[i+1].encode('utf-8')) for i in range(2, len(argv), 2)]
    m = pack_and_encode_messages(messages, preparefunc(p))
    if m is None:
        print('Error')
    else:
        f = open(argv[1], 'bw')
        f.write(m)
        f.close()
Beispiel #4
0
def encode(preparefunc):
    f = open(argv[1], 'br')
    p = f.read()
    f.close()
    messages = [prepare_message(argv[i].encode('utf-8'), argv[i+1].encode('utf-8')) for i in range(2, len(argv), 2)]
    m = pack_and_encode_messages(messages, preparefunc(p))
    if m is None:
        print('Error')
    else:
        f = open(argv[1], 'bw')
        f.write(m)
        f.close()
Beispiel #5
0
def encode(preparefunc):
    f = open(argv[1], "br")
    p = f.read()
    f.close()
    messages = [prepare_message(argv[i].encode("utf-8"), argv[i + 1].encode("utf-8")) for i in range(2, len(argv), 2)]
    m = pack_and_encode_messages(messages, preparefunc(p))
    if m is None:
        print("Error")
    else:
        f = open(argv[1], "bw")
        f.write(m)
        f.close()