byte1 = [True,False,False,True,True,False,False,False] byte2 = [False,False,False,True,True,False,True,False] def convertbyte(x): return x[7]+2*x[6]+4*x[5]+8*x[4]+16*x[3]+32*x[2]+64*x[1]+128*x[0] def converttobyte(n): return [1==n%256/128,1==n%128/64,1==n%64/32,1==n%32/16,1==n%16/8,1==n%8/4,1==n%4/2,1==n%2] def addc(a,b,c): bit = (a and not b and not c) or (not a and b and not c) or (not a and not b and c) or (a and b and c) carry = (a and b and not c) or (a and not b and c) or (not a and b and c) or (a and b and c) return([carry, bit]) def addbyte(x,y): z = [0]*8 sum7 = addc(x[7],y[7],0) z[7] = sum7[1] sum6 = addc(x[6],y[6],sum7[0]) z[6] = sum6[1] sum5 = addc(x[5],y[5],sum6[0]) z[5] = sum5[1] sum4 = addc(x[4],y[4],sum5[0]) z[4] = sum4[1] sum3 = addc(x[3],y[3],sum4[0]) z[3] = sum3[1] sum2 = addc(x[2],y[2],sum3[0]) z[2] = sum2[1] sum1 = addc(x[1],y[1],sum2[0]) z[1] = sum1[1] sum0 = addc(x[0],y[0],sum1[0]) z[0] = sum0[1] return z # input is a list of 5 bytes def DE(numlist): [a1,b1,c1,d1,e1] = numlist e2 = e1 d2 = addbyte(d1,e1) c2 = addbyte(c1,d1) b2 = addbyte(b1,c1) a2 = addbyte(a1,b1) return [a2,b2,c2,d2,e2] # [convertbyte(b) for b in DE(DE(DE([converttobyte(1),converttobyte(2),converttobyte(1),converttobyte(0),converttobyte(0)])))]