2
\$\begingroup\$

This is my DDT (for DES) code. I just wonder how to be more efficient... I've just started cryptography and I'm not good enough.

def SboxProcess_hex(self, r_exp):
    sub_blocks = separate(r_exp, 6)
    result = list()
    for i in range(len(sub_blocks)):
        block = sub_blocks[i]
        row = int(str(block[0]) + str(block[5]), 2)
        column = int(''.join([str(x) for x in block[1:][:-1]]), 2)
        value = Sbox[i][row][column]
        binary = hex_char_to_binary(value)
        result += [int(x) for x in binary]
    return result

This is my SboxProcess code. This is in the class.

input_length = 6
output_length = 4
def DDT_search(start1, start2, num):
    for i in range(64):
        a = bin(start1)[2:].zfill(6)
        for j in range(64):
            b = bin(start2)[2:].zfill(6)
            row = int(str(a[0]) + str(a[5]), 2)
            column = int(''.join([str(x) for x in a[1:][:-1]]), 2)
            a_out_1 = Sbox[num][row][column]
            a_out = bin(a_out_1)[2:].zfill(6)

            row = int(str(b[0]) + str(b[5]), 2)
            column = int(''.join([str(x) for x in b[1:][:-1]]), 2)
            b_out_1 = Sbox[num][row][column]
            b_out = bin(b_out_1)[2:].zfill(6)

            a_xor_b_out = int(a_out, 2) ^ int(b_out, 2) #output XOR 계산

            DDT[i^j][a_xor_b_out] += 1

            b = int(b,2)
            start2 += 1

        start2 = 0
        a = int(a,2)
        start1 += 1

DDTs =[]
for i in range(8):
    DDT = [[0 for x in range(pow(2,output_length))] for x in range(pow(2,input_length))]
    print(DDT)
    a=0
    b=0
    DDT_search(a, b, i)
    print(DDT)
    DDTs.append(DDT)
print(DDTs)
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy