def break_random_access_read_write_aes_ctr(ciphertext, encryption_oracle):
    """If the attacker has access to the edit() function to write on the ciphertext,
    then it is easy to decrypt the underlying plaintext:

    Since we know that the edit() function will encrypt the new_text that we give it
    with the same keystream used in the original ciphertext (shifted by offset), we can
    simply set the offset to zero and then overwrite the underlying plaintext of our ciphertext
    to be the ciphertext itself. Because by encrypting the ciphertext again we will basically
    decrypt it (that's how AES CTR works), the edit will return to us the original plaintext!
    """

    # Assume random key is still unknown, the attacker can control only offset and new_text
    # (given the ciphertext).
    return encryption_oracle.edit(ciphertext, 0, ciphertext)