“Sage code: Modular computations” (1_15.sage) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 17 x = 10 mod 50
# xgcd function from exercise 1.14
xgcd(17,50)
> (1, 3, -1)

# 3 is the modular inverse of 17 mod 50
Mod(3*17,50)
> 1

x=Mod(3*10,50); x
> 30

xgcd(35,50)
> (5, 3, -2)

# 35 is not invertible mod 50
# but 5=gcd(35,50) divides 10
# Thus the equation is transformed into 7 x = 2 mod 10
xgcd(7,10)
> (1, 3, -2)

# 3 is the modular inverse of 7 mod 10
Mod(3*7,10)
> 1

x=Mod(3*2,10);x
> 6

# 35 is not invertible mod 50
# but 5=gcd(35,50) does not divide 11
# There is no solution to 35 x = 11 mod 50