#/bin/bash
#
# Copyright (C) Roger G. Doss.  All Rights Reserved.
#
# @file:
#   test_eulerphi.sh
#
# @description:
#   Shell script to test factorings based on Euler Phi method.
#
# @author:
#   Roger G. Doss
#
FACTORING="f.gp";
PRIMES=64;
TRIALS=128;

while [ $TRIALS != 0 ]
do
    p=`java gen_prime $PRIMES`;
    q=`java gen_prime $PRIMES`;
    n=`echo "$p * $q" | bc`;
    if [ -e $FACTORING ]
    then
        rm -f $FACTORING;
    fi
    printf "p=$p\nq=$q\nn=$n\n";
    printf "n=$n;\n" >> $FACTORING;
    printf "phi=eulerphi(n);\n" >> $FACTORING;
    printf "p_plus_q=n-phi+1;\n" >> $FACTORING;
    printf "sq=p_plus_q*p_plus_q;\n" >> $FACTORING;
    printf "t=sq-4*n;\n" >> $FACTORING;
    printf "determinant=sqrt(t);\n" >> $FACTORING;
    printf "p=(p_plus_q+determinant)/2;\n" >> $FACTORING;
    printf "q=(p_plus_q-determinant)/2;\n" >> $FACTORING;
    printf "print (\"factoring: \" n);\n" >> $FACTORING;
    printf "print (\"q: \" q);\n" >> $FACTORING;
    printf "print (\"p: \" p);\n" >> $FACTORING;
    printf "\\q\n" >> $FACTORING;
    gp $FACTORING;
    ((TRIALS=$TRIALS-1));
done
#
# EOF
#