import java.io.IOException;

class CBCHomework {
    static String path = "/project/web-classes/Fall-2025/csci5471/hw2/";

    public static byte[] getIV() throws IOException, InterruptedException {
	Process ivProc = Runtime.getRuntime().exec(path + "next_iv");
	byte[] iv = new byte[16];
	ivProc.getInputStream().read(iv);
	ivProc.waitFor();
	return iv;
    }

    public static byte[] encrypt(byte[] ptxt) throws IOException, InterruptedException {
	int padlen = 0;
	if (ptxt.length % 16 != 0) padlen += (16 - (ptxt.length % 16)); 
	byte[] ctxt = new byte[32 + ptxt.length + padlen];
	Process encProc = Runtime.getRuntime().exec(path + "encrypt");
	encProc.getOutputStream().write(ptxt);
	encProc.getOutputStream().close();
	encProc.getInputStream().read(ctxt);
	encProc.waitFor();
	return ctxt;
    }
}
