#!/usr/bin/python3
# Python 3 version of calling out to hw2 binaries.
# These functions take and return bytearrays as arguments

import subprocess

path_to_next_iv = '/project/web-classes/Fall-2025/csci5471/hw2/next_iv'
# get_iv : unit -> bytearray
def get_iv():
    with subprocess.Popen(path_to_next_iv,stdout=subprocess.PIPE,stdin=subprocess.DEVNULL) as niv:
        iv = niv.stdout.read(16)
    return iv

path_to_encrypt = '/project/web-classes/Fall-2025/csci5471/hw2/encrypt'
# encrypt : bytearray -> bytearray
def encrypt(s):
    with subprocess.Popen(path_to_encrypt,stdin=subprocess.PIPE,stdout=subprocess.PIPE) as enc:
        enc.stdin.write(s);
        enc.stdin.close();
        ctxt = enc.stdout.read()
    return ctxt
