示例#1
0
def encode_ECB(data,key):
    keys = gen_keys(key)
    
    encoded = ''
    
    padded = False
    while not padded:
        #PADDING
        if len(data) < 64:
            remaining = len(data) / 8
            for x in range(remaining):
                data += decimal2binary(remaining,places=8)
                
            padded = True
            
        ip = permute(data[0:64],IP)
        
        prev_L = ip[:32]
        prev_R = ip[32:]
        
        for x in range(0,16):
            L = prev_R
            R = xor(prev_L,function(prev_R,keys[x]))
            
            prev_L = L
            prev_R = R
        
        RL = R + L
        next = permute(RL,IP_INVERSE)
        encoded += next
        
        data = data[64:]
    
    return encoded
示例#2
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)