Esempio n. 1
0
def decrypt(file, save_as, schema, base_path):
    if schema == 'AES':
        pickle_in = open(base_path + 'en-de/aes.p', 'rb')
        passwd = pickle.load(pickle_in)
        pickle_in.close()
        AES.decrypt_AES(file, passwd, save_as)
    elif schema == 'RSA':
        pickle_in = open(base_path + 'en-de/rsa.p', 'rb')
        code = pickle.load(pickle_in)
        pickle_in.close()
        RSA.decrypt_RSA(file, code, save_as, base_path)
    elif schema == 'DES':
        pickle_in = open(base_path + 'en-de/des.p', 'rb')
        passwd = pickle.load(pickle_in)
        pickle_in.close()
        DES.decrypt_DES(file, passwd, save_as)
    elif schema == 'BF':
        pickle_in = open(base_path + 'en-de/bf.p', 'rb')
        passwd = pickle.load(pickle_in)
        pickle_in.close()
        bf.decrypt_bf(file, passwd, save_as)
    else:
        print('pending')
        sys.exit(2)
Esempio n. 2
0
def incremental_update_genrate_hash(key_tag, tag,
                                    indices_to_update_list_sorted,
                                    original_message_list,
                                    updated_messages_list_ac_indices):
    ### TAG IS OF STR TYPE
    ### 2nd argument should be str type
    h = DES.decrypt_DES(key_tag, tag)
    print("From em module line 56 h we have decrypted", h)
    h = int(h, 16)

    R = randomize_blocks(original_message_list)
    R_new = randomize_blocks(updated_messages_list_ac_indices)

    ### str type
    N = len(R)
    #visited =[0]*N
    nb = len(indices_to_update_list_sorted)

    for i in range(nb):
        j = indices_to_update_list_sorted[i]
        if (j != 0 & j != N - 1):
            h = h ^ f1(hex(int(R[j], 2))[2:], R[j + 1]) ^ f1(
                hex(int(R[j - 1], 2))[2:], R[j])
            R[j] = R_new[i]
            h = h ^ f1(hex(int(R[j], 2))[2:], R[j + 1]) ^ f1(
                hex(int(R[j - 1], 2))[2:], R[j])
        if (j == 0):
            h = h ^ f1(hex(int(R[0], 2))[2:], R[1]) ^ f1(
                hex(int(R[N - 1], 2))[2:], R[0])
            R[j] = R_new[i]
            h = h ^ f1(hex(int(R[0], 2))[2:], R[1]) ^ f1(
                hex(int(R[N - 1], 2))[2:], R[0])
        if (j == N - 1):
            h = h ^ f1(hex(int(R[N - 2], 2))[2:], R[N - 1]) ^ f1(
                hex(int(R[N - 1], 2))[2:], R[0])
            R[j] = R_new[i]
            h = h ^ f1(hex(int(R[N - 2], 2))[2:], R[N - 1]) ^ f1(
                hex(int(R[N - 1], 2))[2:], R[0])

    tag_updated = DES.encrypt_DES(key_tag, hex(h))
    return tag_updated, hex(h)