def generateRandomDataPair(sBoxNo): global pairsNeeded data1 = bitarray() data2 = bitarray() binary = bitarray(pyDES.hex_to_binary(inputs[sBoxNo][0])) for item in binary: x = bitarray(str(random.randrange(0,2))) data1.extend(x) y = bitarray("0") if not item else bitarray("1") data2.extend(x ^ y) binary = bitarray(pyDES.hex_to_binary(inputs[sBoxNo][1])) for item in binary: x = bitarray(str(random.randrange(0,2))) data1.extend(x) y = bitarray("0") if not item else bitarray("1") data2.extend(x ^ y) pairsNeeded += 1 return [bitarray(data1), bitarray(data2)]
def getKeySetRound5(o1, o2, sNo): POutputXor = o1[32:64] ^ o2[32:64] ^ bitarray(pyDES.hex_to_binary(inputs[sNo][0])) SOutputXor = pyDES.shuffle(POutputXor, PInverse, "Binary") SOutputXorInt = int(SOutputXor[sNo * 4 : (sNo + 1) * 4].to01(), 2) ExpandOutput1 = pyDES.expand(o1[0:32]) ExpandOutput2 = pyDES.expand(o2[0:32]) SInputXor = ExpandOutput1 ^ ExpandOutput2 SInputXorInt = int(SInputXor[sNo * 6 : (sNo + 1) * 6].to01(), 2) pairs = XORProfile[str(sNo)][str(SInputXorInt)][str(SOutputXorInt)][0] keyset = set() for item in pairs: possibleKey = item[0] ^ int(ExpandOutput1[sNo * 6 : (sNo + 1) * 6].to01(), 2) keyset.add(possibleKey) return keyset