Exemplo n.º 1
0
def testAES128Decrypt():
    output = hex2bytes("00112233445566778899aabbccddeeff")
    key = hex2bytes("000102030405060708090a0b0c0d0e0f")
    input = hex2bytes("69c4e0d86a7b0430d8cdb78070b4c55a")
    assert output == AES128Decrypt(input, key), "Failed testAES128Decrypt()"

    print("Passed testAES128Decrypt()")
Exemplo n.º 2
0
def testAddRoundKey():
    a = hex2bytes("3243f6a8885a308d313198a2e0370734")
    b = hex2bytes("2b7e151628aed2a6abf7158809cf4f3c")
    s = hex2bytes("193de3bea0f4e22b9ac68d2ae9f84808")

    assert s == AddRoundKey(a, b), "Failed testAddRoundKey"
    print("Passed testAddRoundKey")
Exemplo n.º 3
0
def testShiftRows():
    vector1 = hex2bytes("a761ca9b97be8b45d8ad1a611fc97369")
    solution1 = hex2bytes("a7be1a6997ad739bd8c9ca451f618b61")
    assert solution1 == ShiftRows(vector1), "Failed testShiftRows() with v1"

    vector2 = hex2bytes("2dfb02343f6d12dd09337ec75b36e3f0")
    solution2 = hex2bytes("2d6d7ef03f33e334093602dd5bfb12c7")
    assert solution2 == ShiftRows(vector2), "Failed testShiftRows() with v2"

    vector3 = hex2bytes("5411f4b56bd9700e96a0902fa1bb9aa1")
    solution3 = hex2bytes("54d990a16ba09ab596bbf40ea111702f")
    assert solution3 == ShiftRows(vector3), "Failed testShiftRows() with v3"

    print("Passed testShiftRows()")
Exemplo n.º 4
0
def testSubBytes():
    vector1 = hex2bytes("00102030405060708090a0b0c0d0e0f0")
    solution1 = hex2bytes("63cab7040953d051cd60e0e7ba70e18c")
    assert solution1 == SubBytes(vector1), "Failed testSubBytes() with v1"

    vector2 = hex2bytes("89d810e8855ace682d1843d8cb128fe4")
    solution2 = hex2bytes("a761ca9b97be8b45d8ad1a611fc97369")
    assert solution2 == SubBytes(vector2), "Failed testSubBytes() with v2"

    vector3 = hex2bytes("c81677bc9b7ac93b25027992b0261996")
    solution3 = hex2bytes("e847f56514dadde23f77b64fe7f7d490")
    assert solution3 == SubBytes(vector3), "Failed testSubBytes() with v3"

    print("Passed testSubBytes()")
Exemplo n.º 5
0
def testMixColumns():
    vector1 = hex2bytes("2d6d7ef03f33e334093602dd5bfb12c7")
    solution1 = hex2bytes("6385b79ffc538df997be478e7547d691")
    assert solution1 == MixColumns(vector1), "Failed testMixColumns() with v1"

    vector2 = hex2bytes("36339d50f9b539269f2c092dc4406d23")
    solution2 = hex2bytes("f4bcd45432e554d075f1d6c51dd03b3c")
    assert solution2 == MixColumns(vector2), "Failed testMixColumns() with v2"

    vector3 = hex2bytes("54d990a16ba09ab596bbf40ea111702f")
    solution3 = hex2bytes("e9f74eec023020f61bf2ccf2353c21c7")
    assert solution3 == MixColumns(vector3), "Failed testMixColumns() with v3"

    print("Passed testMixColumns()")
Exemplo n.º 6
0
def testInvShiftRows():
    vector1 = hex2bytes("7ad5fda789ef4e272bca100b3d9ff59f")
    solution1 = hex2bytes("7a9f102789d5f50b2beffd9f3dca4ea7")
    assert solution1 == InvShiftRows(
        vector1), "Failed testInvShiftRows() with v1"

    vector2 = hex2bytes("b458124c68b68a014b99f82e5f15554c")
    solution2 = hex2bytes("b415f8016858552e4bb6124c5f998a4c")
    assert solution2 == InvShiftRows(
        vector2), "Failed testInvShiftRows() with v2"

    vector3 = hex2bytes("a7be1a6997ad739bd8c9ca451f618b61")
    solution3 = hex2bytes("a761ca9b97be8b45d8ad1a611fc97369")
    assert solution3 == InvShiftRows(
        vector3), "Failed testInvShiftRows() with v3"

    print("Passed testInvShiftRows()")
Exemplo n.º 7
0
def testInvMixColumns():
    vector1 = hex2bytes("c57e1c159a9bd286f05f4be098c63439")
    solution1 = hex2bytes("b458124c68b68a014b99f82e5f15554c")
    assert solution1 == InvMixColumns(
        vector1), "Failed testInvMixColumns() with v1"

    vector2 = hex2bytes("6385b79ffc538df997be478e7547d691")
    solution2 = hex2bytes("2d6d7ef03f33e334093602dd5bfb12c7")
    assert solution2 == InvMixColumns(
        vector2), "Failed testInvMixColumns() with v2"

    vector3 = hex2bytes("5f72641557f5bc92f7be3b291db9f91a")
    solution3 = hex2bytes("6353e08c0960e104cd70b751bacad0e7")
    assert solution3 == InvMixColumns(
        vector3), "Failed testInvMixColumns() with v3"

    print("Passed testInvMixColumns()")
Exemplo n.º 8
0
from libs.utils import hexdump, hex2bytes
from libs.analysis import detectECB
import base64

# Read File
file = open("Set1/Set1Challenge8.txt", "r")
i = 0
for line in file:
    ciphertext = hex2bytes(line[:-1])
    score = detectECB(ciphertext)

    if score > 0:
        hexdump(
            ciphertext,
            title="Detected ECB-Encrypted Ciphertext with score={0}".format(
                score))
    i += 1
key = bytearray("YELLOW SUBMARINE", "utf-8")
Exemplo n.º 9
0
# https://cryptopals.com/sets/1/challenges/2

from libs.utils import hex2bytes, bytes2hex, hexdump
from libs.crypto.xor import fixedXOR

buffer1 = hex2bytes("1c0111001f010100061a024b53535009181c")
buffer2 = hex2bytes("686974207468652062756c6c277320657965")
result = fixedXOR(buffer1, buffer2)

hexdump(buffer1)
hexdump(buffer2)
print("== equals ==")
hexdump(result)

if result == hex2bytes("746865206b696420646f6e277420706c6179"):
    print("Challenge 2 successful!")
else:
    print("Challenge 2 failed miserably")
Exemplo n.º 10
0
# https://cryptopals.com/sets/1/challenges/3

from libs.utils import hex2bytes, bytes2hex, hexdump
from libs.analysis import scoreEnglish
from libs.crypto.xor import breakSingleByteXOR

ciphertext = hex2bytes(
    "1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736")
p, k, s = breakSingleByteXOR(ciphertext)

hexdump(ciphertext)
print("Broke it with with k={1}:".format(ciphertext, k))
hexdump(p)
Exemplo n.º 11
0
# https://cryptopals.com/sets/1/challenges/5

from libs.utils import hexdump, hex2bytes
from libs.crypto.xor import repeatingKeyXOR

plaintext = bytearray(
    "Burning 'em, if you ain't quick and nimble\nI go crazy when I hear a cymbal", "utf-8")
key = bytearray("ICE", "utf-8")

solution = hex2bytes(
    "0b3637272a2b2e63622c2e69692a23693a2a3c6324202d623d63343c2a26226324272765272a282b2f20430a652e2c652a3124333a653e2b2027630c692b20283165286326302e27282f")
ciphertext = repeatingKeyXOR(plaintext, key)

print("Plaintext:")
hexdump(plaintext)
print("Encrypted with k={0}".format(key))
hexdump(ciphertext)

if ciphertext == solution:
    print("Challenge 5 successful!")
else:
    print("Challenge 5 failed miserably")
Exemplo n.º 12
0
# https://cryptopals.com/sets/1/challenges/4

from libs.utils import hex2bytes, bytes2hex, hexdump
from libs.analysis import scoreEnglish
from libs.crypto.xor import breakSingleByteXOR

file = open("Set1/Set1Challenge4.txt", "r")
bestScore = 0
bestKey = None
bestPlaintext = None
bestCiphertext = None
for line in file:
    ciphertext = hex2bytes(line[:-1])  # ommit \n
    plaintext, key, score = breakSingleByteXOR(ciphertext)

    if bestScore < score:
        bestScore = score
        bestKey = key
        bestPlaintext = plaintext
        bestCiphertext = ciphertext

print("Ciphertext:")
hexdump(bestCiphertext)
print("Broke it with with k={0}:".format(bestKey))
hexdump(bestPlaintext)