extern crate ciphercore_base;
use std::str::FromStr;
use ciphercore_base::data_types::{array_type, ScalarType, BIT};
use ciphercore_base::errors::Result;
use ciphercore_base::graphs::{create_context, Context, Graph};
use ciphercore_utils::execute_main::execute_main;
use clap::Parser;
#[derive(Parser, Debug)]
#[clap(author, version, about, long_about=None)]
struct Args {
#[clap(value_parser)]
k: u32,
#[clap(short, long, value_parser)]
scalar_type: String,
#[clap(long, value_parser)]
inverse: bool,
}
fn gen_a2b_graph(context: Context, k: u32, st: ScalarType) -> Result<Graph> {
let graph = context.create_graph()?;
let n = 2u64.pow(k);
let i = graph.input(array_type(vec![n], st))?;
graph.set_output_node(i.a2b()?)?;
graph.finalize()?;
Ok(graph)
}
fn gen_b2a_graph(context: Context, k: u32, st: ScalarType) -> Result<Graph> {
let graph = context.create_graph()?;
let n = 2u64.pow(k);
let i = graph.input(array_type(vec![n, st.size_in_bits()], BIT))?;
graph.set_output_node(i.b2a(st)?)?;
graph.finalize()?;
Ok(graph)
}
fn main() {
env_logger::init();
execute_main(|| -> Result<()> {
let args = Args::parse();
let st = ScalarType::from_str(&args.scalar_type)?;
let context = create_context()?;
let graph = if args.inverse {
gen_a2b_graph(context.clone(), args.k, st)
} else {
gen_b2a_graph(context.clone(), args.k, st)
}?;
context.set_main_graph(graph)?;
context.finalize()?;
println!("{}", serde_json::to_string(&context)?);
Ok(())
});
}