Using Pari/GP for Cryptography

Here are some notes on the features of Pari/GP that I have found demonstrated in cryptography class. Don't forget that the entire manual and a tutorial are available on-line in pdf format.

Built-in functions

Most of these commands are documented on pages 46-54 and 62-72 of the user's guide.

add, subtract, multiply a and ba+b, a-b, a*b
integer quotient when a is divided by ba\b
integer remainder when a is divided by b (i.e. a mod b) a%b
a raised to the power b (see powermod below)a^b
assign a the value ba=b
compare a to ba<b, a>b, a<=b, a!=b a==b
a `and' b, a `or' b, `not' a a &&b, a||b, !a
convert a to an element of ZnMod(a,n)
convert an element x of Zn to an integer (see note) lift(x)
binary expansion of abinary(a)
nth bit of abittest(a,n)
random integer between 0 and n-1random(n)
highest power of p dividing avaluation(a,p)
greatest common divisor of a and bgcd(a,b) and bezout(a,b)
chinese remainder theorem applied to x and y (note)chinese(x,y)
φ(n)eulerphi(n)
factor the integer afactorint(a)
is p a prime integer?isprime(p)
first prime larger or smaller than anextprime(a), precprime(a)
nth prime numberprime(n)
discrete log of x to the base g (note)znlog(x,g)
multiplicative order of x in Zn znorder(x)
find a primitive root modulo pznprimroot(p)
Legendre symbol of a over bkronecker(a,b)
define an elliptic curve E E=ellinit([0,0,0,a,b])
add/subtract z and w on elliptic curve E elladd(E,z,w) ellsub(E,z,w)
multiply z by k on elliptic curve E ellpow(E,z,k)
quit gp\q or quit

Other useful devices