Processing math: 100%

Cryptography and Computer Security

« nazaj

Cryptography and computer security - Tutorial 24.11.2020


Jacobi symbols

Exercise 1

Let p be an odd prime. How many quadratic residues are there in Zp?



Exercise 2

For an integer a and an odd positive integer n=ki=1peii, define the Jacobi symbol:

(an)=ki=1(api)ei,

where

(ap)={0if a0(modp),1if a is a quadratic residue modulo p, and1if a is a quadratic non-residue modulo p

is the Legendre symbol. Prove the following properties for the Jacobi symbol.

  1. If m1m2(modn), then (m1n)=(m2n).

  2. (m1m2n)=(m1n)(m2n).

Assuming aZp:

  1. (m1n)=ki=1(m1pi)ei=ki=1(m2pi)ei=(m2n)
  2. (m1m2n)=0(m1n)=0(m2n)=0assuming m1,m2n:(m1m2n)=ki=1(m1m2pi)ei=ki=1((m1pi)(m2pi))ei=ki=1(m1pi)eiki=1(m2pi)ei=(m1n)(m2n)(m1m2p)(m1m2)(p1)/2(modp)m(p1)/21m(p1)/22(modp)(m1p)(m2p)(modp)

Exercise 3

Using the properties above, and additionally

write an algorithm to evaluate Jacobi symbols. The algorithm should not do any factoring other than dividing out powers of two.


def jacobi(a, n):
    v = 1
    while True:
        a %= n # replace a by its remainder modulo n
        if a == 0:
            return 0
        s = 1 if n % 8 in [1, 7] else -1
        while a % 2 == 0:
            a //= 2
            v *= s
        if a == 1:
            return v
        if a % 4 == 3 and n %% 4 == 3:
            v *= -1
        a, n = n, a

Exercise 4

Calculate (74119283), (209641987) and (123456711111111).