Beispiel #1
0
def random_ciphertext_iv():
    plaintext = base64.b64decode(
        random.choice(open('17.txt', 'r').read().splitlines()))
    key = open('unknown_key.txt', 'r').read().splitlines()[0]
    plaintext = pad_multiple(plaintext, AES.block_size)
    iv = Random.new().read(AES.block_size)
    cipher = AES.new(key, AES.MODE_CBC, iv)
    return [cipher.encrypt(plaintext), iv]
def random_ciphertext_iv():
    plaintext = base64.b64decode(random.choice(
        open('17.txt', 'r').read().splitlines()
    ))
    key = open('unknown_key.txt', 'r').read().splitlines()[0]
    plaintext = pad_multiple(plaintext, AES.block_size)
    iv = Random.new().read(AES.block_size)
    cipher = AES.new(key, AES.MODE_CBC, iv)
    return [cipher.encrypt(plaintext), iv]
Beispiel #3
0
def get_keyiv_ciphertext():
    key = open('unknown_key.txt', 'r').read().splitlines()[0]
    my_iv = key
    cipher = AES.new(key, AES.MODE_CBC, IV=my_iv)
    blocksize = 16

    message = """Don't call it a comeback
I've been here for years
I'm rocking my peers
Puttin' suckers in fear
Makin' the tears rain down like a monsoon
Listen to the bass go boom
Explosions, overpowerin'
Over the competition I'm towerin'
Wrecking shop when I write these lyrics
That'll make you call the cops
Don't you dare stare, you better move
Don't ever compare
Me to the rest that'll all get sliced and diced
Competition's payin' the price
"""

    message = pad_multiple(message, blocksize)
    return cipher.encrypt(message)
def get_keyiv_ciphertext():
    key = open('unknown_key.txt', 'r').read().splitlines()[0]
    my_iv = key
    cipher = AES.new(key, AES.MODE_CBC, IV = my_iv)
    blocksize = 16

    message = """Don't call it a comeback
I've been here for years
I'm rocking my peers
Puttin' suckers in fear
Makin' the tears rain down like a monsoon
Listen to the bass go boom
Explosions, overpowerin'
Over the competition I'm towerin'
Wrecking shop when I write these lyrics
That'll make you call the cops
Don't you dare stare, you better move
Don't ever compare
Me to the rest that'll all get sliced and diced
Competition's payin' the price
"""

    message = pad_multiple(message, blocksize)
    return cipher.encrypt(message)
Beispiel #5
0
            word = ''
    print


#### tests, CTR ####

assert len(ctr_nonce) == 8
assert len(ctr_ciphertext) == len(plain)
assert plain.splitlines()[9] == "To just let it flow, let my concepts go "
cryptopals.warn("Passed assertions:", __file__)

#### tests ####

_plaintext = "YELLOW SUB"
_key = open('unknown_key.txt', 'r').read().splitlines()[0]
_plaintext = pad_multiple(_plaintext, AES.block_size)
_iv = Random.new().read(AES.block_size)
_cipher = AES.new(_key, AES.MODE_CBC, _iv)
_ciphertext = _cipher.encrypt(_plaintext)

assert (padding_is_valid(_ciphertext, _iv))

_plaintext = "YELLOW SUBMAR\x04\x04\x04"
_key = open('unknown_key.txt', 'r').read().splitlines()[0]
# Note that we skip the padding in order to give this _plaintext bad padding.
_iv = Random.new().read(AES.block_size)
_cipher = AES.new(_key, AES.MODE_CBC, _iv)
_ciphertext = _cipher.encrypt(_plaintext)

assert (not padding_is_valid(_ciphertext, _iv))
Beispiel #6
0
c4_end = ciphertext[4 * blocksize:]
mod_ciphertext = c0 + ("\x00" * blocksize) + c0 + c4_end

try:
    check_ciphertext(mod_ciphertext)
except BadCharacter as badchar_obj:
    mod_decrypt = str(badchar_obj)
    p0 = mod_decrypt[0:blocksize]
    p2 = mod_decrypt[2 * blocksize:3 * blocksize]
    key_recovered = xor_str(p0, p2)
    print "Found that key is", key_recovered

att_cipher = AES.new(key_recovered, AES.MODE_CBC, IV=key_recovered)

admin = """
     THE BEARER OF THIS TOKEN IS A GENUINE AND AUTHORIZED ADMIN.
                      So please Treat Ver Right.
                            GOOD FOREVER.
"""

admin = pad_multiple(admin, blocksize)
att_ctext = att_cipher.encrypt(admin)
modified_is_admin = check_ciphertext(att_ctext)

#### tests, if any ####
key = open('unknown_key.txt', 'r').read().splitlines()[0]
assert key_recovered == key
assert not untainted_is_admin
assert modified_is_admin
warn("Passed assertions:", __file__)
            word = ''
    print


#### tests, CTR ####

assert len(ctr_nonce)==8
assert len(ctr_ciphertext) == len(plain)
assert plain.splitlines()[9] == "To just let it flow, let my concepts go "
cryptopals.warn("Passed assertions:", __file__)

#### tests ####

_plaintext = "YELLOW SUB"
_key = open('unknown_key.txt', 'r').read().splitlines()[0]
_plaintext = pad_multiple(_plaintext, AES.block_size)
_iv = Random.new().read(AES.block_size)
_cipher = AES.new(_key, AES.MODE_CBC, _iv)
_ciphertext = _cipher.encrypt(_plaintext)

assert(padding_is_valid(_ciphertext, _iv))

_plaintext = "YELLOW SUBMAR\x04\x04\x04"
_key = open('unknown_key.txt', 'r').read().splitlines()[0]
# Note that we skip the padding in order to give this _plaintext bad padding.
_iv = Random.new().read(AES.block_size)
_cipher = AES.new(_key, AES.MODE_CBC, _iv)
_ciphertext = _cipher.encrypt(_plaintext)

assert(not padding_is_valid(_ciphertext, _iv))
Beispiel #8
0
c4_end = ciphertext[4 * blocksize : ]
mod_ciphertext = c0 + ("\x00" * blocksize) + c0 + c4_end

try:
    check_ciphertext(mod_ciphertext)
except BadCharacter as badchar_obj:
    mod_decrypt = str(badchar_obj)
    p0 = mod_decrypt[0:blocksize]
    p2 = mod_decrypt[2*blocksize : 3*blocksize]
    key_recovered = xor_str(p0, p2)
    print "Found that key is", key_recovered

att_cipher = AES.new(key_recovered, AES.MODE_CBC, IV = key_recovered)

admin = """
     THE BEARER OF THIS TOKEN IS A GENUINE AND AUTHORIZED ADMIN.
                      So please Treat Ver Right.
                            GOOD FOREVER.
"""

admin = pad_multiple(admin,blocksize)
att_ctext = att_cipher.encrypt(admin)
modified_is_admin = check_ciphertext(att_ctext)

#### tests, if any ####
key = open('unknown_key.txt', 'r').read().splitlines()[0]
assert key_recovered == key
assert not untainted_is_admin
assert modified_is_admin
warn("Passed assertions:", __file__)