Example #1
0
def encrypt(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.encrypt_AES(file, passwd, save_as)

    elif schema == 'RSA':

        RSA.encrypt_RSA(file, 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.encrypt_DES(file, passwd, save_as)
    elif schema == 'BF':
        pickle_in = open(base_path + 'en-de/bf.p', 'rb')
        #print(base_path)
        passwd = pickle.load(pickle_in)
        pickle_in.close()
        bf.encrypt_bf(file, passwd, save_as)

    else:
        print('pending')
        sys.exit(2)
Example #2
0
def f1(key_in_hex, text_in_bin):
    key = key_in_hex
    hash = MD5.new()
    message = text_in_bin.encode('utf-8')
    hash.update(message)
    hash_md5 = hash.hexdigest()
    ### hash_md5 be like 3c1898a00cc4579728e1268191a64bc6
    hash_bin = bin(int(hash_md5, 16))[2:].zfill(128)
    ### hash_bin be like 00111100000110001001100010100000000011001...., type = str
    first_half = int(hash_bin[:64], 2)
    second_half = int(hash_bin[64:], 2)

    inner_des = DES.encrypt_DES(key, hex(first_half)[2:])  ### hex value
    final_input = int(inner_des, 16) ^ second_half
    result = DES.encrypt_DES(key, hex(final_input)[2:])
    return int(result, 16)
Example #3
0
def encrypt_message(key_tag, D):
    R = randomize_blocks(D)
    #    print("Type R[0] ",type(R[0]))
    h = 0
    l = len(R)
    for i in range(l - 1):
        h = h ^ f1(hex(int(R[i], 2))[2:], R[i + 1])
    h = h ^ f1(hex(int(R[l - 1], 2))[2:], R[0])
    #    print("Line 47 h without 0 and 1 ",h^f1( hex(int(R[0],2))[2:] , R[1]))
    #    print("Line 48 h without 0 and 1 ",h^f1( hex(int(R[0],2))[2:] , R[1]))
    tag = DES.encrypt_DES(key_tag, hex(h))
    return tag, hex(h)
Example #4
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)