Example #1
0
def main():
        if len(sys.argv) < 3:
                key = SAMPLE_KEY
                filename = SAMPLE_FILENAME
        else:
                key = sys.argv[1]
                filename = sys.argv[2]

        f = open(filename, "r")
        ciphertext = ""
        for line in f:
                ciphertext += common.b64decode(line.rstrip())

        print common.aes_cbc_decrypt(ciphertext, key, "\x00" * 16)
        
        
        if False:
                for _ in range(1000):
                        key = common.randbytes(16)
                        pt = common.randbytes(random.randint(1, 64))
                        iv = common.randbytes(16)

                        AFTER = binascii.hexlify(common.aes_cbc_decrypt(common.aes_cbc_encrypt(pt, key, iv), key, iv))

                        PT = binascii.hexlify(common.pkcs7_pad(pt, len(pt) + (16 - (len(pt) % 16))))

                        print PT == AFTER
Example #2
0
def encryption_oracle(pt):
        key = common.randbytes(16)
        pt = common.randbytes(random.randint(5, 10)) + pt + common.randbytes(random.randint(5, 10))

        if random.randint(0, 1) == 1:
                print "actually doing ECB"
                ret = common.aes_ecb_encrypt(pt, key)
        else:
                print "actually doing CBC"
                ret = common.aes_cbc_encrypt(pt, key, common.randbytes(16))

        return ret
def main():
        ct = aes_ctr_encrypt("HELLO" * 50, "YELLOW SUBMARINE", 0)
        pt = aes_ctr_decrypt(ct, "YELLOW SUBMARINE", 0)
        print aes_ctr_decrypt(common.b64decode(target), "YELLOW SUBMARINE", 0)

        for _ in range(100):
                # print "boop"
                key = common.randbytes(16)
                nonce = random.randint(0, 2**64 - 1)
                pt = common.randbytes(random.randint(3, 1000))
                ct = aes_ctr_encrypt(pt, key, nonce)
                if pt != aes_ctr_decrypt(ct, key, nonce):
                        print "mismatch: pt = %s, ct = %s, key = %s, nonce = %d" % (binascii.hexlify(pt), binascii.hexlify(ct), binascii.hexlify(key), nonce)
                        break
def get_target():
    global key
    IV = common.randbytes(16)
    text = common.b64decode(random.choice(choices))

    ct = common.aes_cbc_encrypt(text, key, IV)
    return ct, IV
def get_target():
        global key
        IV = common.randbytes(16)
        text = common.b64decode(random.choice(choices))

        ct = common.aes_cbc_encrypt(text, key, IV)
        return ct, IV
Example #6
0
def main():
    ct = aes_ctr_encrypt("HELLO" * 50, "YELLOW SUBMARINE", 0)
    pt = aes_ctr_decrypt(ct, "YELLOW SUBMARINE", 0)
    print aes_ctr_decrypt(common.b64decode(target), "YELLOW SUBMARINE", 0)

    for _ in range(100):
        # print "boop"
        key = common.randbytes(16)
        nonce = random.randint(0, 2**64 - 1)
        pt = common.randbytes(random.randint(3, 1000))
        ct = aes_ctr_encrypt(pt, key, nonce)
        if pt != aes_ctr_decrypt(ct, key, nonce):
            print "mismatch: pt = %s, ct = %s, key = %s, nonce = %d" % (
                binascii.hexlify(pt), binascii.hexlify(ct),
                binascii.hexlify(key), nonce)
            break
def setup():
    global ct_list
    global KEY

    KEY = common.randbytes(16)

    for p in pt_encoded:
        ct_list.append(common.aes_ctr_encrypt(common.b64decode(p), KEY, NONCE))
def setup():
        global ct_list
        global KEY

        KEY = common.randbytes(16)
        
        for p in pt_encoded:
                ct_list.append(common.aes_ctr_encrypt(common.b64decode(p), KEY, NONCE))
def setup():
    global ct_list
    global KEY

    KEY = common.randbytes(16)

    f = open(INPATH, "r")
    for line in f:
        ct_list.append(
            common.aes_ctr_encrypt(common.b64decode(line.rstrip()), KEY,
                                   NONCE))
def main():
        if len(sys.argv) < 2:
                s = SAMPLE_STRING
        else:
                s = sys.argv[1]

        assert s == base64_to_hex(hex_to_base64(s))

        # print "hex encoded string: " + s
        # print "base64 encoding: " + hex_to_base64(s)
        # print "hex encoding of base64 encoding: " + base64_to_hex(hex_to_base64(s))

        for _ in range(100):
                t = common.randbytes(random.randint(1, 40))
                if t != b64decode(b64encode(t)):
                        print binascii.hexlify(t)
                        print b64encode(t)
                        print binascii.hexlify(b64decode(b64encode(t)))
                        print "-----"
Example #11
0
def main():
    if len(sys.argv) < 2:
        s = SAMPLE_STRING
    else:
        s = sys.argv[1]

    assert s == base64_to_hex(hex_to_base64(s))

    # print "hex encoded string: " + s
    # print "base64 encoding: " + hex_to_base64(s)
    # print "hex encoding of base64 encoding: " + base64_to_hex(hex_to_base64(s))

    for _ in range(100):
        t = common.randbytes(random.randint(1, 40))
        if t != b64decode(b64encode(t)):
            print binascii.hexlify(t)
            print b64encode(t)
            print binascii.hexlify(b64decode(b64encode(t)))
            print "-----"
def encryption_oracle(pt):
    global key
    return common.aes_ecb_encrypt(
        common.randbytes(random.randint(2, 50)) + pt +
        common.b64decode(TARGET_PT), key)
def setup_oracle():
        global key
        key = common.randbytes(16)
Example #14
0
def setup_oracle():
    global key
    global IV

    key = common.randbytes(16)
    IV = common.randbytes(16)
def setup_oracle():
    global key
    key = common.randbytes(16)
def encryption_oracle(pt):
        global key
        return common.aes_ecb_encrypt(common.randbytes(random.randint(2, 50)) + pt + common.b64decode(TARGET_PT), key)
def setup_oracle():
        global key
        global IV

        key = common.randbytes(16)
        IV = common.randbytes(16)