CoCalc Public FilesDES.sagews
Views : 84
Compute Environment: Ubuntu 20.04 (Default)
key="110110010"
message="101010110101"
BDESoneRound(message,key,4)

10010110 '110101101110'
key = "010011001"
EightBitsKey(key,2)

00110010 '00110010'

key="110110010"
message="101010110101"
L0 = Ln(message)
R0 = Rn(message)
ER0 = Expander(R0)
k1= EightBitsKey(key,0)
SboxInputs=XORnbits(ER0,k1,8)
L0
R0
ER0
k1
SboxInputs

11011001 '101010' '110101' '11101001' '11011001' '00110000'

test ={"0110" : "111", "1110" : "101", "0000" : "101", "1001" : "100", "1100" : "000", "0010" : "001", "0111" : "000", "1111" : "011", "1010" : "110", "0100" : "011", "0101" : "100", "1101" : "111", "0001" : "010", "1000" : "001", "1011" : "010", "0011" : "110"}

test['0110']

'111'

key="110011101"
message="101010110101"
Encr=BDES(message,key,6)
out = BDESdecr(Encr,key,6)
out==message
out

True


k1="000000000"
k2="111111111"
DoubleBDES("110101010010",k1,k2,512)

110101010010 66
numcorrect=0
numwrong=0
for i in xrange(0,(2^9)):
#key="110011101"
key =format(i, '#011b')
message="101010110101"
Encr=BDES(message,key,6)
out = BDESdecr(Encr,key,6)
if out!=message:
print key
numwrong+=1
else:
numcorrect+=1
numcorrect
numwrong