예제 #1
0
def function(d,key):
    data = xor(E(d),key)
    s_result = ''
    
    for index in range(1,9):
        s = S[index]
        
        B = data[(index-1)*6:(index-1)*6+6]
        
        row = binary2decimal(B[0]+B[5])
        col = binary2decimal(B[1:5])
        
        s_result += decimal2binary(s[row][col],places=4)
    
    return permute(s_result,P)
예제 #2
0
def decode_ECB(data,key):
    keys = gen_keys(key)
    
    decoded = ''
    
    while len(data) > 0:
        ip = permute(data[0:64],IP)
        
        prev_L = ip[:32]
        prev_R = ip[32:]
        
        for x in range(16,0,-1):
            L = prev_R
            R = xor(prev_L,function(prev_R,keys[x-1]))
            
            prev_L = L
            prev_R = R
        
        RL = R + L
        next = permute(RL,IP_INVERSE)
        
        #remove padding
        if len(data) == 64:
            last = next[56:]
            for x in range(binary2decimal(last)):
                next = next[0:len(next)-8]
        
        decoded += next
        
        data = data[64:]
    
    return decoded