#! /bin/sh # # Exercise script. Throws random numbers under 500 digits at the # multiplier and at baseline(), trying to find values where the # multiplier returns something different from baseline(). # # Generates digit counts by picking a random three-digit number, # dividing it by 4, and adding that to 250. Then, a random digit is # used to select a number of times to divide this by 2. The result is # a random digit count. That many digits are read and used as a # number. After generating two numbers this way, a calc script is # generated which multiplies them both with * and with baseline(), # then subtracting the one from the other; this script is run, looking # for a nonzero output. # # 2^197=200867255532373784442745261542645325315275374222849104412672 loops=0 while : do d=`skipcat 0 25 < /dev/urandom | hexdump -v -e '1/1 "%02x"' | cvtbase -m200 x b | sed -e 's/^...//' | cvtbase -m60 b d` case $d in 2*) ;; *) echo $d | sed -e 's/./& /g' -e 's/ $//' | tr \ \\n;; esac done | ( exec 3<&0 while : do loops=$(($loops+1)) read h 0<&3 read t 0<&3 read u 0<&3 dc1=$((((1$h$t$u-1000)/4)+250)) read s 0<&3 case $s in 0|1) dc1=$(($dc1/4));; 2|3|4) dc1=$(($dc1/2));; esac read h 0<&3 read t 0<&3 read u 0<&3 dc2=$((((1$h$t$u-1000)/4)+250)) read s 0<&3 case $s in 0|1) dc2=$(($dc2/4));; 2|3|4) dc2=$(($dc2/2));; esac n1=`skipcat 0 $(($dc1*2)) 0<&3 | tr -dc 0-9` n2=`skipcat 0 $(($dc2*2)) 0<&3 | tr -dc 0-9` diff=` ( echo \?p1023 echo a=$n1\; echo b=$n2\; echo '(a*b)-baseline(a,b)' ) | calc -q | tail -1 ` echo $loops case $diff in 0) ;; *) echo $n1 echo $n2 echo $diff exit 1 ;; esac done )