def CBC_encryption_oracle(user_input):
    prepend = "comment1=cooking%20MCs;userdata="
    append = ";comment2=%20like%20a%20pound%20of%20bacon;"
    user_input = user_input.replace(';', '').replace('=', '')
    to_encrypt = s2_1.pad_string_pkcs7(
        (prepend + user_input + append).encode())
    encrypted_string = s2_2.CBC_encrypt(to_encrypt, unkown_key, IV)
    return encrypted_string
def encryption_oracle(input_string):
    key = rand_key_gen()
    app_bef = os.urandom(random.randint(5, 10))
    app_aft = os.urandom(random.randint(5, 10))
    _unencrypted = app_bef + input_string + app_aft
    last_block_len = (len(_unencrypted) % 16)
    last_block = _unencrypted[-last_block_len:]
    to_encrypt = _unencrypted[:-last_block_len] + s2_1.pkcs7_pad(
        last_block, 16)
    mode = random.randint(0, 1)
    print(mode)
    if mode == 0:
        encrypted_string = s2_2.encrypt_AES_ECB(to_encrypt, key)
    else:
        encrypted_string = s2_2.CBC_encrypt(to_encrypt, key)
    return encrypted_string, mode
def main():
    print("Running Client")
    p=37
    g=5
    a=random.randint(0, p)
    A=pow(g, a, p)
    client1=Client()

    print("*Client* | Attempting Connection")
    client1.connectTo(3500, socket.gethostname())
    status=client1.recieve()
    print(str(status))

    client1.send(p.to_bytes(16, 'big'))
    client1.send(g.to_bytes(16, 'big'))
    client1.send(A.to_bytes(16, 'big'))

    B=client1.recieve()
    B=int.from_bytes(B, 'big')
    s=pow(B, a, p)


    message=b"Shh. Issa Secret."
    SHA=s4_4.SHA1()
    CBCkey=bytes.fromhex(SHA.Hash(bytes([s]))[0:32])
    IV=os.urandom(16)
    encrypted_message=s2_2.CBC_encrypt(message, CBCkey, IV)

    client1.send(encrypted_message)
    client1.send(IV)

    bot_message=client1.recieve()
    bot_IV=client1.recieve()


    returned_message=s2_2.CBC_decrypt(bot_message, CBCkey, bot_IV)
    print("*CLIENT* | Echoed Message: " + str(returned_message))
    client1.close()
def CBC_encryption_oracle(user_input):
    to_encrypt=s2_1.pad_string_pkcs7((user_input))
    encrypted_string=s2_2.CBC_encrypt(to_encrypt, unknown_key, IV)
    return encrypted_string
def u_encrypt_cbc(plain_text):
    padded_plain_text = s2_1.pad_string_pkcs7(plain_text)
    cipher_text = s2_2.CBC_encrypt(padded_plain_text, ukey, IV)
    return cipher_text