xct's notes
Search…
Sage

GCD

1
#!/usr/bin/env sage
2
3
import sys
4
from sage.all import *
5
6
print(gcd(a,b))
Copied!

Extended GCD

1
#!/usr/bin/env sage
2
3
import sys
4
from sage.all import *
5
6
print(xgcd(a,b)) # returns d,u,v
Copied!

Solve Congruence

1
#!/usr/bin/env sage
2
3
import sys
4
from sage.all import *
5
6
var('x') # < symbolic variable, solve for that one
7
print(solve_mod(a == x, b))
Copied!

Solve Power Modulo

1
#!/usr/bin/env sage
2
3
import sys
4
from sage.all import *
5
6
print(power_mod(a,b,c))
Copied!

Multiplicative Inverse

1
#!/usr/bin/env sage
2
3
import sys
4
from sage.all import *
5
6
print(inverse_mod(a,b))
Copied!

Factor Prime

1
#!/usr/bin/env sage
2
3
import sys
4
import hashlib
5
from sage.all import *
6
7
print(factor(a))
Copied!
Last modified 7mo ago