def s_des_encrypt(bitstring, key1, key2, decrypt=False):
    if decrypt:
        key2,key1=key1,key2
    bitstring=gf.permute_key(bitstring, pa.en_IP)
    left,right=complex_function(bitstring[:4], bitstring[4:], key1)
    left,right=complex_function(right, left, key2)
    return gf.permute_key(left+right, pa.en_IP_inverse)
def MappingF(input_bitstring, keystring):
    expanded_bitstring=gf.permute_key(input_bitstring, pa.mp_EP)
    bitstring=bin(int(expanded_bitstring, 2)^int(keystring, 2))[2:].zfill(8)
    left_bits=bitstring[:4]
    right_bits=bitstring[4:]
    left_out=SBox(left_bits, pa.mp_matrix_s0)
    right_out=SBox(right_bits, pa.mp_matrix_s1)
    return gf.permute_key(left_out+right_out, pa.mp_P4)
Beispiel #3
0
def s_des_keygen(key):
    primary_key=gf.create_keystring(key, 10)
    primary_key=gf.permute_key(primary_key, pa.kg_P10)
    primary_key=gf.left_shift(primary_key[:5], 1) + gf.left_shift(primary_key[5:], 1)
    key1=gf.permute_key(primary_key, pa.kg_P8)
    primary_key=gf.left_shift(primary_key[:5], 2) + gf.left_shift(primary_key[5:], 2)
    key2=gf.permute_key(primary_key, pa.kg_P8)
    return key1,key2