There are better ways to generate prime numbers than using openssl.
If you are really tuned for this method, use something like this (a call with a range number to check):
#!/bin/bash # Usage: $0 <starting_number> <final_number> N=$1 while (( N <= $2 )); do # use bc to convert hex to decimal openssl prime $N | awk '/is prime/ {print "ibase=16;"$1}' | bc let N++ done
If you want to do this with random numbers generated using openssl, use this (call with the number of attempts):
#!/bin/bash # Usage: $0 <count> N=$1 while (( N-- > 0 )); do # use bc to convert hex to decimal openssl rand -hex 256 | xargs openssl prime -hex | awk '/is prime/ {print "ibase=16;"$1}' | bc done
If you don't care about the decimal value, replace awk '/is prime/ {print "ibase=16;"$1}' | bc awk '/is prime/ {print "ibase=16;"$1}' | bc on awk '/is prime/ {print $1}'
Adapted from: http://www.madboa.com/geek/openssl/#prime
source share