# This expect script runs the NIST tests automatically and saves the data. for {set k 0} {$k <= 1} {incr k 1} { set timeout -1 set underscore "_" # !!!!! FIX ME TO POINT TO YOUR SOURCE FILES and NIST DIRECTORY !!!! set bitfile_src_dir "./" set results_src_dir "experiments/AlgorithmTesting" if { $k == 0 } { set bitfile "$bitfile_src_dir/xyz_TGV.txt" set results_dest_dir "./" } else { if { $k == 1 } { set bitfile "$bitfile_src_dir/xyz_TCD.txt" set results_dest_dir "./" }} # Get the bit stream length and the number of bit streams (number of chips). # Wait for get_bit_stream_length to terminate (wait -i $I) spawn "get_bit_stream_length.pl" $bitfile set I $spawn_id wait -i $I expect -re "(.*)X(.*)" set bit_stream_len $expect_out(1,string) set num_chips $expect_out(2,string) expect -re "(.*) >" puts stdout "Bit string length: $bit_stream_len" puts stdout "Number of chips: $num_chips" # See MinimumBitLengths.txt file # 1) Frequency 2) BlockFrequency 3) CumulativeSums 4) Runs 5) LongestRun # 6) Rank 7) FFT 8) NonOverlappingTemplate 9) OverlappingTemplate 10) Universal # 11) Approx. Entropy 12) RandomExcursions 13) RandomExcursionsVariant 14) Serial 15) LinearComplexity # If the number of bits available is greater than 1M, run all tests. if { $bit_stream_len > 1000000 } { set NIST_test_spec "111111111111111" set adjust_params 0 } else { # If greater than 387,840 bits, (determined by Universal), drop 1000000 bit tests -- NOTE: I'm ignoring the requirement # for NonOverlappingTemplate that there be more than 1M bits if { $bit_stream_len > 387840 } { set NIST_test_spec "111111110110010" set adjust_params 0 } else { # If greater than 38,912 bits, (determined by Rank), drop Universal if { $bit_stream_len > 38912 } { # Appears Universal is the ONLY one that REQUIRES a couple hundred thousand bits. set NIST_test_spec "111111110010010" set adjust_params 0 } else { # If greater than 1000 bits, (determine by DFT), drop Rank -- KEEP Approx Entropy but adjust the block length parameter if { $bit_stream_len > 1000 } { set NIST_test_spec "111110110010010" set adjust_params 1 # If less than 1000 bits, keep only Freq, Block Freq, CummulativeSums, Runs, LongestRuns and Serial } else { set NIST_test_spec "111110000000010" set adjust_params 0 }}}} # cd into the assess binary directory cd ../sts-2.1.1 # Remove the data from all subdirectories. NOTE: We need to do this because some analysis are NOT # run (depends on the size of the bit string), so when we do the copy below, we need to be sure # data from a previous analysis is not copied into the current results directory. spawn rm_assess_files.pl $results_src_dir set I $spawn_id wait -i $I # Start up assess spawn "./assess" $bit_stream_len set I $spawn_id # Enter '0' for the input choice expect -re "(.*) Choice: " send -i $I "0\n" # Send the file above as the input file expect -re "(.*) File: " send -i $I "$bitfile\n" # Tests specification -- this is largely determined by the number of bits available -- use '0' to specify tests and '1' for ALL expect -re "(.*) Choice: " send -i $I "0\n" # Output the tests to be applied expect -re "(.*) 012345" send -i $I "$NIST_test_spec\n" # ============================================================================== # Parameter adjustments # !!!!!!!!!!!!!!!!!!!! DEPENDENCY WITH ABOVE 'if stmt' !!!!!!!!!!!!!!!!!!!!!!!! # [1] Block Frequency Test - block length(M): 128 # [2] NonOverlapping Template Test - block length(m): 9 # [3] Overlapping Template Test - block length(m): 9 # [4] Approximate Entropy Test - block length(m): 10 # [5] Serial Test - block length(m): 16 # [6] Linear Complexity Test - block length(M): 500 expect -re "(.*)Select(.*)" if { $adjust_params == 0 } { send -i $I "0\n" # ADJUST ONLY Approx Entropy block length for now. NOTE: IT IS element 3 (NOT 4) because # we do NOT run all tests in this condition. } else { send -i $I "3\n" expect -re "(.*)Approximate(.*)" send -i $I "8\n" expect -re "(.*)Select(.*)" send -i $I "0\n" } # ============================================================================== # Number of bitstreams expect -re "(.*)bitstreams(.*)" send -i $I "$num_chips\n" # Input file format expect -re "(.*)mode(.*)" send -i $I "0\n" # ========================================================== # OKAY -- NOW WAIT for the statistical testing to complete. expect -re "(.*)Statistical Testing Complete(.*)" wait -i $I # Copy the results to the results directory -- wait for 'cp' to terminate # spawn cp -r spawn copy_files.pl $results_src_dir $results_dest_dir set I $spawn_id wait -i $I }