Exemplo n.º 1
0
def send_message_B(ciphertext, iv):
    global s_B, A_B, b, p
    s_B = pow(A_B, b, p)
    key = hashes.SHA1(util.int_to_bytes(s_B))
    key = util.get_ith_block(key, 0, BLOCK_SIZE)
    plaintext = util.cbc_decrypt(ciphertext, key, iv)
    assert plaintext == MESSAGE
    iv = util.random_byte_string(BLOCK_SIZE)
    return (util.cbc_encrypt(plaintext, key, iv), iv)
Exemplo n.º 2
0
def send_message_A(B):
    global s_A, a, p, B_A
    B_A = B
    s_A = pow(B_A, a, p)
    msg = MESSAGE
    key = hashes.SHA1(util.int_to_bytes(s_A))
    key = util.get_ith_block(key, 0, BLOCK_SIZE)
    iv = util.random_byte_string(BLOCK_SIZE)
    return (util.cbc_encrypt(msg, key, iv), iv)
def ecb_cbc_oracle(data):
    prefix = util.random_byte_string(random.randint(5, 10))
    suffix = util.random_byte_string(random.randint(5, 10))
    key = util.random_byte_string(16)
    data = util.padding(prefix + data + suffix, 16)
    mode = random.randint(0, 1)
    if mode == 1:
        return util.ecb_encrypt(data, key), mode
    else:
        iv = util.random_byte_string(16)
        return util.cbc_encrypt(data, key, iv), mode
Exemplo n.º 4
0
def block_encrypt(p):
    key = util.random_byte_string(16)
    iv = util.random_byte_string(16)
    return util.cbc_encrypt(p, key, iv=iv)
def cbc_encrypt():
  plaintext = b'The quick brown fox jumps over a lazy dog.'
  return util.cbc_encrypt(plaintext, key, iv = key)
def cbc_encrypt_surround(chosen):
  prefix = b'comment1=cooking%20MCs;userdata='
  secret = b';comment2=%20like%20a%20pound%20of%20bacon'
  chosen = chosen.replace(b';', b'').replace(b'=',b'')
  return util.cbc_encrypt(prefix + chosen + secret, key)
def cbc_encrypt_special():
    chosen = plaintext_list[random.randint(0, len(plaintext_list) - 1)]
    chosen = base64.b64decode(chosen)
    return util.cbc_encrypt(chosen, key, iv)