use crypto::ntt
use crypto::fieldq

fn main() {
    println("=== Basemul Montgomery factor test ===")
    let mut a = t_zeros(256)
    a = t_index_set(a, 0, 1.0)
    a = t_index_set(a, 1, 2.0)

    let mut b = t_zeros(256)
    b = t_index_set(b, 0, 3.0)
    b = t_index_set(b, 1, 4.0)

    let a_ntt = ntt_forward(a)
    let b_ntt = ntt_forward(b)
    let c_ntt = ntt_basemul(a_ntt, b_ntt)
    let c = ntt_inverse(c_ntt)

    let raw0 = t_index_get(c, 0)
    let raw1 = t_index_get(c, 1)
    let raw2 = t_index_get(c, 2)

    println("Raw (no from_mont):")
    println("  c[0] = " + float_to_str(raw0) + " (expect 3)")
    println("  c[1] = " + float_to_str(raw1) + " (expect 10)")
    println("  c[2] = " + float_to_str(raw2) + " (expect 8)")

    println("1x from_mont:")
    println("  c[0] = " + int_to_str(fq_from_mont(raw0)) + " (expect 3)")
    println("  c[1] = " + int_to_str(fq_from_mont(raw1)) + " (expect 10)")
    println("  c[2] = " + int_to_str(fq_from_mont(raw2)) + " (expect 8)")

    println("2x from_mont:")
    println("  c[0] = " + int_to_str(fq_from_mont(fq_from_mont(raw0))) + " (expect 3)")
    println("  c[1] = " + int_to_str(fq_from_mont(fq_from_mont(raw1))) + " (expect 10)")
    println("  c[2] = " + int_to_str(fq_from_mont(fq_from_mont(raw2))) + " (expect 8)")

    // What IS the factor 169? Check if it's a Montgomery-related value
    println("")
    println("Factor analysis: 507/3 = " + int_to_str(507 / 3))
    println("fq_from_mont(169) = " + int_to_str(fq_from_mont(169)))
    println("fq_to_mont(1) = " + int_to_str(fq_to_mont(1)))
    println("fq_mont() = " + int_to_str(fq_mont()))
    println("fq_mont_r2() = " + int_to_str(fq_mont_r2()))
}
