def sanityCheck2():
    """Tests multi-block DES encryption and decryption"""
    try:
        key = [0x0f, 0x15, 0x71, 0xc9, 0x47, 0xd9, 0xe8, 0x59]
        plaintext = "The quick brown fox jumps over the lazy dog"
        ciphertext = encrypt(key, plaintext)
        assert decrypt(key, ciphertext) == plaintext
    except AssertionError:
        return False
    return True
Ejemplo n.º 2
0
pairs = []	# for caching previous encryptions
keys = []
for i in range(0, 8):
    print "sBox %d keysets:" % (i + 1)
    s = set()
    temp = list(pairs)
    while len(s) != 1:
        if len(temp) != 0:
            x = temp.pop()
            inp = [x[0], x[1]]
            out1 = x[2]
            out2 = x[3]
        else:
            inp = generateRandomDataPair()
            out1 = pyDES.encrypt(inp[0], 3)
            out2 = pyDES.encrypt(inp[1], 3)
        pairs.append([inp[0], inp[1], out1, out2])
        keyset = getKeySetRound3(inp[0], out1, inp[1], out2, i)
        print keyset
        if len(s) == 0:
            s = keyset
        else:
            s.intersection_update(keyset)
    print "intersection: %s \n" % str(s)
    keys.append(s.pop())

print "original key r3: %s " % pyDES.keys[2].to01()
print "found key    r3: %s " % ''.join(i for i in keys)

Ejemplo n.º 3
0
    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


keys = []
for i in range(0,8):
    print "sBox %d keysets:" % (i + 1)
    s = set()
    while len(s) != 1:
        inp = generateRandomData()
        out = pyDES.encrypt(inp, 1)
        keyset = getKeySet(inp, out, i)
        print keyset
        if len(s) == 0:
            s = keyset
        else:
            s.intersection_update(keyset)
    print "intersection: %s \n" % str(s)
    keys.append(s.pop())

print "original key: %s " % pyDES.keys[0].to01()

print "found key   : %s " % ''.join(i for i in keys)

Ejemplo n.º 4
0
    outsBox = ExpandOutput[sBoxNumber * 6 : (sBoxNumber + 1) * 6]
    keyset = set()
    for i in range(0,4):
        keyset.add((outsBox ^ XOROutput[i]).to01())
    return keyset


print "Breaking round 1..\n"

keys = []
for i in range(0,8):
    print "sBox %d keysets:" % (i + 1)
    s = set()
    while len(s) != 1:
        inp = generateRandomData()
        out = pyDES.encrypt(inp, 2)
        keyset = getKeySetRound1(inp, out, i)
        print keyset
        if len(s) == 0:
            s = keyset
        else:
            s.intersection_update(keyset)
    print "intersection: %s \n" % str(s)
    keys.append(s.pop())

foundkeyr1 = ''.join(i for i in keys)

print "original key r1: %s " % pyDES.keys[0].to01()
print "found key r1   : %s\n" % foundkeyr1