Skip to content

Instantly share code, notes, and snippets.

View tagoro9's full-sized avatar

Victor Mora tagoro9

View GitHub Profile
@tagoro9
tagoro9 / solinas.rb
Created May 8, 2013 15:59
Little ruby script to check if a given number is a Solinas prime, that is, a prime number of the form 2^a +/- 2^b +/- 1, where 0 < b < a. It is not efficient (4 nested loops) but works.
#Check if a prime number is a solinas prime
#ModPow and Miller Rabin test extracted from http://en.literateprograms.org/Miller-Rabin_primality_test_(Ruby)
MAX_EXPONENT = 160
#Modular arithmetic power
def modPow(x, r, m)
y = r
z = x
v = 1