Example #1
0
File: main.py Project: MS103/studia
def destinguisher(key, iv, msg_list, enc_msg):
    iv2 = increment_iv(iv)
    encryptor = OpenSSL('cbc')
    for i, m in enumerate(msg_list):
        xored = xor_strings(xor_strings(iv, iv2), m)
        enc_m = encryptor.encrypt(xored, key, iv2)
        if enc_m == enc_msg:
            return i, enc_m
Example #2
0
n = 24  # len(msg)
# N = pow(2, n)  # len(secrets)
N = 1000

# Placeholder
msgs = []
keys = []
secrets = []
start = time.time()
# ALICE (Encryption)
for i in range(0, N):
    secret = str(randint(1000000000000000000000000, 9999999999999999999999999))
    key = str(randint(1000, 9999))

    enc_suite = OpenSSL('cbc')
    msg = enc_suite.encrypt('0' * (n - s) + secret, key * 4, key * 4)

    msgs.append(msg)
    keys.append(key)
    secrets.append(secret)

# ALICE sends "msgs" Block to BOB

# BOB (Brute force Decryption)
decrypted_msg = ''
rand_msg_solve = randint(0, N - 1)

print("Start decrypting at {}".format(time.time() - start))
keys = [str(x) for x in range(1000, 9999)]
while not decrypted_msg[:(n - s)] == '0' * (n - s):
    if len(keys) == 0:
Example #3
0
from openssl import OpenSSL

command_line_parser = CommandLineParser()
parsed_args = command_line_parser.parse_arguments(sys.argv[1:])

key_store = jks.KeyStore.load(parsed_args['keystore_path'],
                              parsed_args['password'])
key = key_store.private_keys['alias_name'].pkey[:32]

num_of_success = 0
msg_to_enc = 'x'
types_of_enc = ['ofb', 'cbc', 'ctr']
if True:
    for enc_type in types_of_enc:
        print('Sprawdzam szyfrowanie i deszyfrowanie dla ', enc_type.upper())
        openssl = OpenSSL(enc_type)
        iv = '0' * 16
        enc_m = openssl.encrypt(msg_to_enc, key, iv)
        dec_m = openssl.decrypt(enc_m, key, iv).rstrip(b'\x00')
        try:
            dec_m = dec_m.decode()
            if_success = msg_to_enc == dec_m
        except UnicodeDecodeError as e:
            print("Wystąpił błąd!", e)
            if_success = 0
        num_of_success += if_success
        print('Sprawdzam czy {a} == {b}. Rezultat to {c}\n'.format(
            a=msg_to_enc, b=dec_m, c=if_success))
    print('Stosunek sukcesów do prób to {a}/{b}'.format(a=num_of_success,
                                                        b=len(types_of_enc)))
Example #4
0
File: main.py Project: MS103/studia
openssl = OpenSSL(enc_type)
iv = '0' * 16
key_store = jks.KeyStore.load(parsed_args['keystore_path'],
                              parsed_args['password'])
key = key_store.private_keys['alias_name'].pkey[:32]

f = open(parsed_args['input_path'], 'r')
input_ms = [x for x in f]
f = open(r'C:\Users\Latitude\Desktop\output.txt', 'w')

if len(input_ms) == 0:
    raise IOError('Za mało danych wejściowych')
elif len(input_ms) == 2:
    msg_list = [x[:16] for x in input_ms]
    random_msg = msg_list[randint(0, 1)]

    enc_m = openssl.encrypt(random_msg, key, iv)
    f.write(str(enc_m) + '\n')
    print('Szyfruje {a} w {b}'.format(a=random_msg, b=enc_m))

    if enc_type == 'cbc':
        print('\n\nProgram uruchamia destinguisher\n\n')
        dec_m, cipher = destinguisher(key, iv, msg_list, enc_m)
        print('{a} zaszyfrowano w {b}'.format(a=msg_list[dec_m], b=cipher))
else:

    for m in input_ms:
        enc_m = openssl.encrypt(m, key, iv)
        f.write(str(enc_m) + '\n')
        print('Szyfruje {a} w {b}'.format(a=m, b=enc_m))