def getInputOutput(sNo, input, output):
    inpbin = bitarray("0" * sNo * 6 + format(input, 'b').zfill(6)
                      + "0" * (7 - sNo) * 6)
    rhs_xor = pyDES.shuffle(inpbin, collapse, "Binary")
    outbin = bitarray("0" * sNo * 4 + format(output, 'b').zfill(4)
                      + "0" * (7 - sNo) * 4)
    lhs_xor = pyDES.shuffle(outbin, constants.perm, "Binary")
    return (("%0.8X" % int(lhs_xor.to01(), 2)),
            ("%0.8X" % int(rhs_xor.to01(), 2)))
Example #2
0
def decryptAux(s, teamname):
    b = bitarray(convert(s))

    y = pyDES.shuffle(b, IPINVI, 'binary')

    message_bitarray = pyDES.decryptDES(y, 6, keys[teamname])

    mbs = pyDES.shuffle(message_bitarray, IPI, 'binary')

    message_binary = mbs.to01()
    return convert_inv(message_binary)
Example #3
0
def encryptAux(s, teamname):
    # convert input to bitarray
    b = bitarray(convert(s))

    # apply initial permutation
    y = pyDES.shuffle(b, constants.ip, 'binary')

    # encrypt
    message_bitarray = pyDES.encryptDES(y, 6, keys[teamname])

    # apply initial permutation inverse
    mbs = pyDES.shuffle(message_bitarray, constants.ipinv, 'binary')

    # convert bitarray to string
    message_binary = mbs.to01()

    # convert to our format and return
    return convert_inv(message_binary)
Example #4
0
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
Example #5
0
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
Example #6
0
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