This does the job, but is not especially elegant.
What is the preferred Pythonic idiom to my childish nests?
def bytexor(a, b):
res = ""
for x, y in zip(a, b):
if (x == "1" and y == "0") or (y =="1" and x == "0"):
res += "1"
else:
res += "0"
return res
def get_all():
res = []
bit = ["0","1"]
for i in bit:
for j in bit:
for k in bit:
for l in bit:
res.append(i+j+k+l)
return res
if __name__=="__main__":
for k0 in get_all():
for k1 in get_all():
for k2 in get_all():
for k3 in get_all():
for k4 in get_all():
if bytexor(bytexor(k0, k2), k3) == "0011":
if bytexor(bytexor(k0, k2), k4) == "1010":
if bytexor(bytexor(bytexor(k0,k1),k2),k3) == "0110":
print k0, k1, k2, k3, k4
print bytexor(bytexor(bytexor(k0, k1),k2),k4)