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
def getKeySet(input, output, sBoxNumber): POutput = output[32:64] ^ input[0:32] SOutput = pyDES.shuffle(POutput, PInverse, "Binary") XOROutput = mapSBoxInverse(SOutput, sBoxNumber) ExpandOutput = pyDES.expand(input[32:64]) outsBox = ExpandOutput[sBoxNumber * 6 : (sBoxNumber + 1) * 6] keyset = set() for i in range(0,4): keyset.add((outsBox ^ XOROutput[i]).to01()) return keyset
def getKeySetRound3(i1, o1, i2, o2, sNo): POutputXor = o1[32:64] ^ o2[32:64] ^ i1[0:32] ^ i2[0:32] 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) #print XORProfile #print XORProfile[str(sBoxNumber)][str(SInputXorInt)][str(SOutputXorInt)] pairs = XORProfile[str(sNo)][str(SInputXorInt)][str(SOutputXorInt)][0] #print pairs keyset = set() #print SInputXorInt, SOutputXorInt for item in pairs: possibleKey = item[0] ^ int(ExpandOutput2[sNo * 6 : (sNo + 1) * 6].to01(), 2) #print item[0] ^ item[1] #print possibleKey #a = pyDES.mapSBox(constants.sBoxes[sBoxNumber], bitarray(format(item[0], 'b').zfill(6))) #b = pyDES.mapSBox(constants.sBoxes[sBoxNumber], bitarray(format(item[1], 'b').zfill(6))) #print item[0] ^ item[1], int((a ^ b).to01(), 2) keyset.add(format(possibleKey, 'b').zfill(6)) return keyset