26
Algebra.sagews 1. lipnja 2014. Sadržaj 1 Linearna algebra 1 1.0.1 Vektorski prostori i vektori ................................. 1 1.0.2 Matrice ............................................ 2 2 Algebarske strukture 8 2.0.3 Permutacije, grupe ...................................... 8 2.0.4 Prsteni polinoma ....................................... 11 2.0.5 Elementarna teorija brojeva ................................. 13 3 Kombinatorika 14 4 Teorija grafova 19 5 Kriptografija 25 5.0.6 RSA .............................................. 25 1 Linearna algebra 1.0.1 Vektorski prostori i vektori R3 = VectorSpace(QQ, 3) (b1, b2, b3) = R3.basis() b1, b2, b3 vector1 = R3([-1, 2, 7]) vector2 = R3([4, -9, 2]) var( ’a b’ ) a * vector1 + b * vector2 ((1, 0, 0), (0, 1, 0), (0, 0, 1)) (a, b) (-a + 4*b, 2*a - 9*b, 7*a + 2*b) sqrt(vector1 * vector1) vector1.norm() vector1.norm(2) vector1.norm(Infinity) 1

Algebra.sagews - PMFweb.math.pmf.unizg.hr/nastava/matsoft/Algebra.pdf · 3*sqrt(6) 3*sqrt(6) 3*sqrt(6) 7 2 * vector1 vector1 * vector2 vector1.dot_product(vector2) vector1.cross_product(vector2)

  • Upload
    others

  • View
    17

  • Download
    0

Embed Size (px)

Citation preview

Algebra.sagews

1. lipnja 2014.

Sadržaj1 Linearna algebra 1

1.0.1 Vektorski prostori i vektori . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.0.2 Matrice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

2 Algebarske strukture 82.0.3 Permutacije, grupe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82.0.4 Prsteni polinoma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112.0.5 Elementarna teorija brojeva . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

3 Kombinatorika 14

4 Teorija grafova 19

5 Kriptografija 255.0.6 RSA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

1 Linearna algebra

1.0.1 Vektorski prostori i vektori

R3 = VectorSpace(QQ, 3)(b1 , b2 , b3) = R3.basis()b1 , b2 , b3

vector1 = R3([-1, 2, 7])vector2 = R3([4, -9, 2])var(’a b’)a * vector1 + b * vector2((1, 0, 0), (0, 1, 0), (0, 0, 1))(a, b)(-a + 4*b, 2*a - 9*b, 7*a + 2*b)

sqrt(vector1 * vector1)vector1.norm()vector1.norm (2)vector1.norm(Infinity)

1

3*sqrt(6)3*sqrt(6)3*sqrt(6)7

2 * vector1vector1 * vector2vector1.dot_product(vector2)vector1.cross_product(vector2)(-2, 4, 14)-8-8(67, 30, 1)

Naredba VectorSpace kreira vektorski prostor gdje je prvi parametar polje a drugi dimenzija. Tipičan izborsu ZZ, QQ, RQ i CC, no Sage podržava izuzetno velik broj polja.

u = vector(QQ, [1, 2/7, 10/3])u[1]2/7

I ostali načini pristupanja elementima naravno funkcioniraju.

u[:2](1, 2/7)

u[2] = numerical_approx(pi , digits =5)u(1, 2/7, 355/113)

1.0.2 Matrice

M4 = MatrixSpace(QQ, 4)show(M4.identity_matrix ())

1 0 0 00 1 0 00 0 1 00 0 0 1

M34 = MatrixSpace(QQ , 3, 4)show(M34.basis()) 1 0 0 0

0 0 0 00 0 0 0

,

0 1 0 00 0 0 00 0 0 0

,

0 0 1 00 0 0 00 0 0 0

,

0 0 0 10 0 0 00 0 0 0

,

0 0 0 01 0 0 00 0 0 0

,

0 0 0 00 1 0 00 0 0 0

,

0 0 0 00 0 1 00 0 0 0

,

0 0 0 00 0 0 10 0 0 0

,

0 0 0 00 0 0 01 0 0 0

,

0 0 0 00 0 0 00 1 0 0

,

0 0 0 00 0 0 00 0 1 0

,

0 0 0 00 0 0 00 0 0 1

A = M4.matrix ([[0, -1, -1, 1], [1, 1, 1, 1], [2, 4, 1, -2],

[3, 1, -2, 2]])b = vector(QQ, [0, 6, -1, 3])show(A)

2

show(b)A.solve_right(b)A\b

0 −1 −1 11 1 1 12 4 1 −23 1 −2 2

(0, 6, −1, 3)

(2, -1, 3, 2)(2, -1, 3, 2)

A[1](1, 1, 1, 1)

A[:,0][0][1][2][3]

A[:,1] = vector ([1,1,1,0])A[ 0 1 -1 1][ 1 1 1 1][ 2 1 1 -2][ 3 0 -2 2]

A.row(2)A.column (2)(2, 1, 1, -2)(-1, 1, 1, -2)

A.submatrix(2, 2, 2, 2)[ 1 -2][-2 2]

A = Matrix(QQ, [[1, 2, 3], [4, 5, 6], [7, 8, 9]])A.rescale_row (1, 2)A[ 1 2 3][ 8 10 12][ 7 8 9]

A.swap_rows(0, 1)A[ 8 10 12][ 1 2 3][ 7 8 9]

A.add_multiple_of_row (0, 1 ,3)A

3

[14 22 30][ 1 2 3][ 7 8 9]

A.echelon_form () #Gaussova eliminacija[ 1 0 -1][ 0 1 2][ 0 0 0]

M3 = MatrixSpace(QQ, 2, 3)A = M3.matrix ([[3, 2, 1], [4, 5, 6]])B = M3.matrix ([[2, 2, 2], [1, 2, 3]])show(A+B)show (1/2*A) (

5 4 35 7 9

)(

32 1 1

22 5

2 3

)

var(’a b c d e f’)C = Matrix(QQ, [[4, 2, 1], [5, 3, 7]])D = Matrix(SR, [[a, b], [c, d], [e, f]])show(C * D)(a, b, c, d, e, f) (

4 a+ 2 c+ e 4 b+ 2 d+ f5 a+ 3 c+ 7 e 5 b+ 3 d+ 7 f

)

type(D)<type ’sage.matrix.matrix_symbolic_dense.Matrix_symbolic_dense’>

var(’x1 x2 x3’)X = vector ([x1,x2,x3])show(C * X)(x1, x2, x3)

(4x1 + 2x2 + x3, 5x1 + 3x2 + 7x3)

A = matrix(QQ, [[2, 5, 4], [3, 1, 2], [5, 4, 6]])A.det()A.rank()A.transpose ()A.adjoint ()A.inverse ()-163[2 3 5][5 1 4][4 2 6][ -2 -14 6][ -8 -8 8][ 7 17 -13]

4

[ 1/8 7/8 -3/8][ 1/2 1/2 -1/2][ -7/16 -17/16 13/16]

A.adjoint ()/A.det() == A.inverse ()True

A.norm (1)A.norm()A.norm(’frob’)12.011.346960138611.6619037897

A = matrix ([[1 ,2] ,[3 ,4]]) #ako ne specificiramo polje , bit će odabrano \najmanje koje sadrži sve elemente matrice

type(A)<type ’sage.matrix.matrix_integer_dense.Matrix_integer_dense’>

show(block_matrix ([[A,-A],[2*A, A^2]]))1 2 −1 −23 4 −3 −42 4 7 106 8 15 22

A = matrix ([[1 ,2 ,3] ,[4 ,5 ,6]])show(block_matrix ([1,A,0,0,-A,2], ncols =3))

1 0 1 2 3 0 00 1 4 5 6 0 00 0 −1 −2 −3 2 00 0 −4 −5 −6 0 2

A = matrix(3,3,range (9))A[0 1 2][3 4 5][6 7 8]

R.<x> = PolynomialRing(GF(5),’x’)A = random_matrix(R,2,3)A[ 2*x + 1 0 x^2 + 3*x + 4][ 4*x^2 + 4 4*x^2 + 2*x + 3 4*x^2 + 4*x + 4]

Spektar matrica

A = Matrix(QQ, [[2, -3, 1], [1, -2, 1], [1, -3, 2]])ev = A.eigenvectors_right ()for v in ev:

show(v[0]) # sv. vrijednostifor v in ev:

5

show(v[1]) # sv. vektorifor v in ev:

show(v[2]) # kratnosti0

1

[(1, 1, 1)]

[(1, 0, −1) , (0, 1, 3)]

1

2

A.eigenvalues ()[0, 1, 1]

D, P = A.eigenmatrix_right ()show(D)show(P)A*P == P*D 0 0 0

0 1 00 0 1

1 1 0

1 0 11 −1 3

True

A = Matrix(RDF , [[1, -1, 4], [1, 4, -2], [1, 4, 2], [1, -1, 0]])type(A)<type ’sage.matrix.matrix_real_double_dense.Matrix_real_double_dense’>

Q, R = A.QR()show(Q)show(R)

−0.5 0.5 −0.5 −0.5−0.5 −0.5 0.5 −0.5−0.5 −0.5 −0.5 0.5−0.5 0.5 0.5 0.5

−2.0 −3.0 −2.00.0 −5.0 2.00.0 0.0 −4.00.0 −0.0 −0.0

U, Sigma , V = A.SVD()show(U)show(Sigma)show(V)

6

−0.313279120424 0.771564156303 −0.237791811076 −0.50.748087126775 −0.146888948344 −0.4108397347 −0.50.569322205509 0.61893410742 0.206864199386 0.5−0.134514199158 0.00574110053924 −0.855495745162 0.5

6.00328466876 0.0 0.00.0 4.9112061916 0.00.0 0.0 1.356697066190.0 0.0 0.0

0.14485670107 0.254387693609 −0.956192155111

0.952383730605 0.226191965094 0.204456412486−0.268294177787 0.940278733285 0.209509278787

A = matrix(QQ, [[2,4,3],[-4,-6,-3],[3,3,1]])A.characteristic_polynomial ()A.minimal_polynomial ().factor ()x^3 + 3*x^2 - 4(x - 1) * (x + 2)^2

show(A.jordan_form ()) 1 0 00 −2 10 0 −2

show(A.jordan_form(transformation=True)) 1 0 0

0 −2 10 0 −2

,

1 1 1−1 −1 01 0 −1

A = matrix(QQ, [[1, -1/2] ,[-1/2 ,-1]])A.jordan_form ()Error in lines 2-2Traceback (most recent call last):

File "/projects/66d9f5ce-4356-433a-9d13-31043d9bbbc9/.sagemathcloud/sage_server.py",line 733, in execute

exec compile(block+’\n’, ’’, ’single’) in namespace, localsFile "", line 1, in <module>File "matrix2.pyx", line 9110, in sage.matrix.matrix2.Matrix.jordan_form

(sage/matrix/matrix2.c:45693)RuntimeError: Some eigenvalue does not exist in Rational Field.

A.minimal_polynomial ()x^2 - 5/4

R = QQ[sqrt (5)]A = A.change_ring(R)show(A.jordan_form(transformation=True , subdivide=False))((

12sqrt5 0

0 − 12sqrt5

),

(1 1

−sqrt5 + 2 sqrt5 + 2

))

7

2 Algebarske strukture

2.0.3 Permutacije, grupe

S5 = SymmetricGroup (5)S5.cardinality ()S5.list() #ciklička notacija!120

[(), (4,5), (3,4), (3,4,5), (3,5,4), (3,5), (2,3), (2,3)(4,5), (2,3,4), (2,3,4,5),(2,3,5,4), (2,3,5), (2,4,3), (2,4,5,3), (2,4), (2,4,5), (2,4)(3,5), (2,4,3,5), (2,5,4,3),(2,5,3), (2,5,4), (2,5), (2,5,3,4), (2,5)(3,4), (1,2), (1,2)(4,5), (1,2)(3,4),(1,2)(3,4,5), (1,2)(3,5,4), (1,2)(3,5), (1,2,3), (1,2,3)(4,5), (1,2,3,4), (1,2,3,4,5),(1,2,3,5,4), (1,2,3,5), (1,2,4,3), (1,2,4,5,3), (1,2,4), (1,2,4,5), (1,2,4)(3,5),(1,2,4,3,5), (1,2,5,4,3), (1,2,5,3), (1,2,5,4), (1,2,5), (1,2,5,3,4), (1,2,5)(3,4),(1,3,2), (1,3,2)(4,5), (1,3,4,2), (1,3,4,5,2), (1,3,5,4,2), (1,3,5,2), (1,3), (1,3)(4,5),(1,3,4), (1,3,4,5), (1,3,5,4), (1,3,5), (1,3)(2,4), (1,3)(2,4,5), (1,3,2,4), (1,3,2,4,5),(1,3,5,2,4), (1,3,5)(2,4), (1,3)(2,5,4), (1,3)(2,5), (1,3,2,5,4), (1,3,2,5), (1,3,4)(2,5),(1,3,4,2,5), (1,4,3,2), (1,4,5,3,2), (1,4,2), (1,4,5,2), (1,4,2)(3,5), (1,4,3,5,2),(1,4,3), (1,4,5,3), (1,4), (1,4,5), (1,4)(3,5), (1,4,3,5), (1,4,2,3), (1,4,5,2,3),(1,4)(2,3), (1,4,5)(2,3), (1,4)(2,3,5), (1,4,2,3,5), (1,4,2,5,3), (1,4,3)(2,5),(1,4)(2,5,3), (1,4,3,2,5), (1,4)(2,5), (1,4,2,5), (1,5,4,3,2), (1,5,3,2), (1,5,4,2),(1,5,2), (1,5,3,4,2), (1,5,2)(3,4), (1,5,4,3), (1,5,3), (1,5,4), (1,5), (1,5,3,4),(1,5)(3,4), (1,5,4,2,3), (1,5,2,3), (1,5,4)(2,3), (1,5)(2,3), (1,5,2,3,4), (1,5)(2,3,4),(1,5,3)(2,4), (1,5,2,4,3), (1,5,3,2,4), (1,5)(2,4,3), (1,5,2,4), (1,5)(2,4)]

S5.identity ()()

S5.random_element ()(2,3,5)

r = S5.random_element ()rr.domain ()(1,4,3)(2,5)[4, 5, 1, 3, 2]

s = S5(’(1,3)(2,4)’)s.domain ()[3, 4, 1, 2, 5]

t = S5([1,5,4,3,2])t.domain ()[1, 5, 4, 3, 2]

t*s(1,3,2,5,4)

8

t.order()2

t*t()

t.sign()1

S4 = SymmetricGroup (4)S4.is_subgroup(S5)True

S4.normal_subgroups ()[Subgroup of (Symmetric group of order 4! as a permutation group) generated by [()],Subgroup of (Symmetric group of order 4! as a permutation group) generated by [(1,3)(2,4),(1,4)(2,3)], Subgroup of (Symmetric group of order 4! as a permutation group) generated by[(2,4,3), (1,3)(2,4), (1,4)(2,3)], Subgroup of (Symmetric group of order 4! as apermutation group) generated by [(1,2), (1,2,3,4)]]

H = S5.subgroup ([t,s])HSubgroup of (Symmetric group of order 5! as a permutation group) generated by [(2,5)(3,4),(1,3)(2,4)]

H.list()[(), (2,5)(3,4), (1,2)(4,5), (1,2,4,3,5), (1,3)(2,4), (1,3,2,5,4), (1,4)(3,5),(1,4,5,2,3), (1,5,3,4,2), (1,5)(2,3)]

H.is_abelian ()H.is_cyclic ()FalseFalse

S3 = SymmetricGroup (3)S3.cayley_table ()* a b c d e f+------------

a| a b c d e fb| b a d c f ec| c e a f b dd| d f b e a ce| e c f a d bf| f d e b c a

S3.cayley_table(names=’elements ’)* () (2,3) (1,2) (1,2,3) (1,3,2) (1,3)+------------------------------------------------

()| () (2,3) (1,2) (1,2,3) (1,3,2) (1,3)(2,3)| (2,3) () (1,2,3) (1,2) (1,3) (1,3,2)

9

(1,2)| (1,2) (1,3,2) () (1,3) (2,3) (1,2,3)(1,2,3)| (1,2,3) (1,3) (2,3) (1,3,2) () (1,2)(1,3,2)| (1,3,2) (1,2) (1,3) () (1,2,3) (2,3)

(1,3)| (1,3) (1,2,3) (1,3,2) (2,3) (1,2) ()

S3.cayley_table(names=[’id’,’u1’,’u3’,’r1’,’r2’,’u2’])* id u1 u3 r1 r2 u2+------------------

id| id u1 u3 r1 r2 u2u1| u1 id r1 u3 u2 r2u3| u3 r2 id u2 u1 r1r1| r1 u2 u1 r2 id u3r2| r2 u3 u2 id r1 u1u2| u2 r1 r2 u1 u3 id

r = ’(1,3)(2,4)(5)’s = ’(1,3,2)’K = PermutationGroup ([r,s])KPermutation Group with generators [(1,3,2), (1,3)(2,4)]

K.order()12

D = DihedralGroup (4)D.list() #prikazana kao podgrupa permutacija[(), (2,4), (1,2)(3,4), (1,2,3,4), (1,3), (1,3)(2,4), (1,4,3,2), (1,4)(2,3)]

D.subgroups ()[Subgroup of (Dihedral group of order 8 as a permutation group) generated by [()],Subgroup of (Dihedral group of order 8 as a permutation group) generated by [(1,3)(2,4)],Subgroup of (Dihedral group of order 8 as a permutation group) generated by [(2,4)],Subgroup of (Dihedral group of order 8 as a permutation group) generated by [(1,3)],Subgroup of (Dihedral group of order 8 as a permutation group) generated by [(1,2)(3,4)],Subgroup of (Dihedral group of order 8 as a permutation group) generated by [(1,4)(2,3)],Subgroup of (Dihedral group of order 8 as a permutation group) generated by [(2,4),(1,3)(2,4)], Subgroup of (Dihedral group of order 8 as a permutation group) generated by[(1,2,3,4), (1,3)(2,4)], Subgroup of (Dihedral group of order 8 as a permutation group)generated by [(1,2)(3,4), (1,3)(2,4)], Subgroup of (Dihedral group of order 8 as apermutation group) generated by [(2,4), (1,2,3,4), (1,3)(2,4)]]

D.center ()Subgroup of (Dihedral group of order 8 as a permutation group) generated by [(1,3)(2,4)]

D.center ().list()[(), (1,3)(2,4)]

D.centralizer(D(’(1,3)(2,4)’))Subgroup of (Dihedral group of order 8 as a permutation group) generated by [(1,2,3,4),(1,4)(2,3)]

10

A4 = AlternatingGroup (4)A4.cardinality ()12

g1 = A4(’(1,4)(3,2)’) ; g2 = A4(’(2,4)(1,3)’)H = A4.subgroup ([g1 ,g2]);H.is_normal(A4);True

Hd = A4.cosets(H, side = ’right’)Hl = A4.cosets(H, side = ’left’)print "Hd = ", Hdprint "Hl = ", HlHd = [[(), (1,2)(3,4), (1,3)(2,4), (1,4)(2,3)], [(2,3,4), (1,3,2), (1,4,3), (1,2,4)],[(2,4,3), (1,4,2), (1,2,3), (1,3,4)]]Hl = [[(), (1,2)(3,4), (1,3)(2,4), (1,4)(2,3)], [(2,3,4), (1,2,4), (1,3,2), (1,4,3)],[(2,4,3), (1,2,3), (1,3,4), (1,4,2)]]

A4.conjugacy_classes_representatives ()[(), (1,2)(3,4), (1,2,3), (1,2,4)]

B = DiCyclicGroup (3)A.is_isomorphic(B)False

T = [s for s in S5 if s.order() == 2]T[(4,5), (3,4), (3,5), (2,3), (2,3)(4,5), (2,4), (2,4)(3,5), (2,5), (2,5)(3,4), (1,2),(1,2)(4,5), (1,2)(3,4), (1,2)(3,5), (1,3), (1,3)(4,5), (1,3)(2,4), (1,3)(2,5), (1,4),(1,4)(3,5), (1,4)(2,3), (1,4)(2,5), (1,5), (1,5)(3,4), (1,5)(2,3), (1,5)(2,4)]

2.0.4 Prsteni polinoma

R.<x>= PolynomialRing(ZZ) #x je varijabla polinoma iz polja ZRUnivariate Polynomial Ring in x over Integer Ring

p = 2*x^2 + (1/2)*x + (3/5)parent(p)Univariate Polynomial Ring in x over Rational Field

S.<y>= PolynomialRing(ZZ)(1/2)*y in SFalse

f=x+1g=x^2+x-1h=1/2*x+3/4parent(f), parent(g), parent(h)f+gg-h

11

f*gh^3(Univariate Polynomial Ring in x over Integer Ring, Univariate Polynomial Ring in x overInteger Ring, Univariate Polynomial Ring in x over Rational Field)x^2 + 2*xx^2 + 1/2*x - 7/4x^3 + 2*x^2 - 11/8*x^3 + 9/16*x^2 + 27/32*x + 27/64

f/gparent(f/g)(x + 1)/(x^2 + x - 1)Fraction Field of Univariate Polynomial Ring in x over Integer Ring

f=x^6+x^2+1g=x^3+x+1f // gf % gx^3 - x - 12*x^2 + 2*x + 2

p = x^4 + 2*x^3 + 2*x^2 + 2*x + 1q = x^4 - 1gcd(p,q)x^3 + x^2 + x + 1

(x^3+x+1).is_irreducible ()True

(x^3+1).is_irreducible ()False

R.<x,y,z> = PolynomialRing(QQ, 3)p = -1/2*x - y*z - y + 8*z^2p.monomials ()p.coefficients ()[ a*b for a,b in zip(p.coefficients (),p.monomials ())][y*z, z^2, x, y][-1, 8, -1/2, -1][-y*z, 8*z^2, -1/2*x, -y]

p.lc() #vodeći koeficijentp.lt() #vodeći član-1-y*z

p.total_degree ()p.exponents ()2[(0, 1, 1), (0, 0, 2), (1, 0, 0), (0, 1, 0)]

12

2.0.5 Elementarna teorija brojeva

gcd (2776, 2452)4

a = 633b = 331ext = xgcd(a, b)ext [0] == ext [1]*a + ext [2]*bTrue

factor (2600)prime_divisors (2600)2^3 * 5^2 * 13[2, 5, 13]

inverse_mod (352, 917)508

multiplikativni inverz od 352 mod 917; znači postoji m takav da vrijedi 352*508 == m*917+1

euler_phi (345)176

m = random_prime (10000)n = random_prime (10000)euler_phi(m*n) == euler_phi(m) * euler_phi(n)True

is_prime (14547073)False

p = random_prime (10^21 , True) #bez ‘True ‘ računanje će biti puno brže, uz\malu šansu da broj nije prost

is_prime(p)True

prime_range (500, 550)primes_first_n (20)[503, 509, 521, 523, 541, 547][2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71]

Kongruencije: a ≡ b (mod n). Broj b možemo izračunati pomoću sljedećeg koda: mod(a,n)

mod(23, 5)3

am mod n

power_mod (15, 831, 23)10

13

3 Kombinatorika

boje = Set(["pik", "herc", "karo", "tref"])vrijednosti = Set([2, 3, 4, 5, 6, 7, 8, 9, 10,"luda", "kraljica", "kralj"\

, "as"])karte = CartesianProduct(vrijednosti , boje).map(tuple)karte.random_element ()(5, ’karo’)

ruke = Subsets(karte , 5)ruke.random_element (){(4, ’karo’), (8, ’herc’), (8, ’karo’), (5, ’pik’), (3, ’karo’)}

ruke.cardinality ()2598960

S = Subsets ([1,2,3,4], 2)S.random_element ()S.cardinality (){1, 3}6

E = Set([1,2,3,4])S = Subsets(Subsets(Subsets(E)))S.cardinality ()200352993040684646497907235156025575044782547556975141926501697371089405955631145308950613088093334810103823434290726318182294938211881266886950636476154702916504187191635158796634721944293092798208430910485599057015931895963952486337236720300291696959215610876494888925409080591145703767520850020667156370236612635974714480711177481588091413574272096719015183628256061809145885269982614142503012339110827360384376787644904320596037912449090570756031403507616256247603186379312648470374378295497561377098160461441330869211810248595915238019533103029216280016056867010565164675056803874152946384224484529253736144253361437372908830379460127472495841486491593064725201515569392262818069165079638106413227530726714399815850881129262890113423778270556742108007006528396332215507783121428855167555407334510721311242739956298271976915005488390522380435704584819795639315785351001899200002414196370681355984046403947219401606951769015611972698233789001764151719005113346630689814021938348143542638730653955296969138802415816185956110064036211979610185953480278716720012260464249238511139340046435162386756707874525946467090388654774348321789701276445552940909202195958575162297333357615955239488529757995402847194352991354376370598692891375715374000198639433246489005254310662966916524341917469138963247656028941519977547770313806478134230959619096065459130089018888758808473362595606544488850144733570605881709016210849971452956834406197969056546981363116205357936979140323632849623304642106613620022017578785185740916205048971178182040018728293994344618622432800983732376493181478984811945271300744022076568091037620399920349202390662626449190916798546151577883906039772075927937885224129430101745808686226336928472585140303961555856433038545068865221311481363840838477826379045960718687672850976347127198889068047824323039471865052566097815072986114143030581692792497140916105941718535227588750447759221830115878070197553572224140001954810200566177358978149953232520858975346354700778669040642901676380816174055040511767009367320280454933902799249186730653993164072049223847481528061916690093380573212081635070763435166986962502096902316285935007187419057916124153689751480826190484794657173660100589247665544584083833479054414481768425532720731558634934760513741977952519036503219802010876473836868253102518337753390886142618480037400808223810

14

407646887847164755294532694766170042446106331123802113458869453220011656407632702307429242605158281107038701834532456763562595143003203743274078087905628366340696503084422585596703927186946115851379338647569974856867007982396060439347885086164926030494506174341236582835214480672667684180708375486221140823657980296120002744132443843240233125740354501935242877643088023285085588608996277445816468085787511580701474376386797695504999164399828435729041537814343884730348426190338884149403136613985425763557710533558020662218557706008255128889333222643628198483861323957067619140963853383237434375883085923372228464428799624560547693242899843265267737837317328806321075321123868060467470842805116648870908477029120816110491255559832236624486855665140268464120969498259056551921618810434122683899628307165486852553691485029953967550395493837185340590009618748947399288043249637316575380367358671017578399481847179849824694806053208199606618343401247609663951977802144119975254670408060849934417825628509272652370989865153946219300460736450792621297591769829389236701517099209153156781443979124847570623780460000991829332130688057004659145838720808801688744583555792625846512476308714856631352893416611749061752667149267217612833084527393646924458289257138887783905630048248379983969202922221548614590237347822268252163995744080172714414617955922617508388902007416992623830028228624928418267124340575142418856999427233160699871298688277182061721445314257494401506613946316919762918150657974552623619122484806389003366907436598922634956411466550306296596019972063620260352191777674066877746354937531889958786628212546979710206574723272137291814466665942187200347450894283091153518927111428710837615922238027660532782335166155514936937577846667014571797190122711781278045024002638475878833939681796295069079881712169068692953824852983002347606845411417813911064856023654975422749723100761513187002405391051091381784372179142252858743209852495787803468370333781842144401713868812424998441861812927119853331538256732187042153063119774853521467095533462633661086466733229240987984925669110951614361860154890974024191350962304361219612816595051866602203071561368473236466086890501426391390651506390819937885231836505989729912540447944342516677429965981184923315155527288327402835268844240875281128328998062591267369954624734154333350014723143061275039030739713525206933817384332295070104906186753943313078479801565513038475815568523621801041965025559618193498631591323303609646190599023611268119602344184336333459492763194610171665291382371718239429921627253846177606569454229787707138319881703696458868981186321097690035573588462446483570629145305275710127887202796536447972402540544813274839179412882642383517194919720979714593688753719872913083173803391101612854741537737771595172808411162759718638492422280237344192546999198367219213128703558530796694271341639103388275431861364349010094319740904733101447629986172542442335561223743571582593338280498624389249822278071595176275784710947511903348224141202518268871372819310425347819612844017647953150505711072297431456991522345164312184865757578652819756484350895838472292353455946452121583165775147129870822590929265563883665112068194383690411625266871004456024370420066370900194118555716047204464369693285006004692814050711906926139399390273553454556747031490388602202463994826050176243196930564066636662609020704888743889890749815286544438186291738290105182086993638266186830391527326458128678280660133750009659336462514609172318031293034787742123467911845479131110989779464821692250562939995679348380169915743970053754213448587458685604728675106542334189383909911058646559511364606105515683854121745980180713316361257307961116834386376766730735458349478978831633012924080083635682593915711313097803051644171668251834657367593419808495894794098329250008638977856349469321247342610306271374507728615692259662857385790553324064184901845132828463270926975383086730840914224765947443997334813081098639941737978965701068702673416196719659159958853783482298827012560584236558953969030647496558414798131099715754204325639577607048510088157829140825077773855979012912940730946278594450585941227319481275322515232480150346651904822896140664689030510251091623777044848623022948896671138055560795662073244937337402783676730020301161522700892184351565212137921574820685935692079021450227713309998772945959695281704458218195608096581170279806266989120506156074232568684227130629500986442185347081040712891764690655083612991669477802382250278966784348919940965736170458678624255400694251669397929262471452494540885842272615375526007190433632919637577750217600

15

519580069384763578958687848953687212289855780682651819270363209948015587445557517531273647142129553649408438558661520801211507907506855334448925869328385965301327204697069457154695935365857178889486233329246520273585318853337094845540333656535698817258252891805663548836374379334841184558016833182767683464629199560551347003914787680864032262961664156066750815371064672310846196424753749055374480531822600271021640098058449752602303564003808347205314994117296573678506642140084269649710324191918212121320693976914392336837470922826773870813223668008692470349158684099115309831541206356612318750430546753698323082796645741762080659317726568584168183796610614496343254411170694170022265781735835125982108076910196105222926387974504901925431190062056190657745241619191318753398404934397682331029846589331837301580959252282920682086223033258528011926649631444131644277300323779227471233069641714994553226103547514563129066885434542686978844774298177749371011761465162418361668025481529633530849084994300676365480610294009469375060984558855804397048591444958444507997849704558355068540874516331646411808312307970438984919050658758642581073842242059119194167418249045270028826398305795005734171148703118714283418449915345670291528010448514517605530697144176136858238410278765932466268997841831962031226242117739147720800488357833356920453393595325456489702855858973550575123512953654050284208102278524877660357424636667314868027948605244578267362623085297826505711462484659591421027812278894144816399497388188462276824485162205181707672216986326570165431691974265123004175732990447353767253684579275436541282655358185804684006936771860502007054724754840080553042495185449526724726134731817474218007857469346544713603697588411802940803961674694628854067917213860122541950381970453841726800639882065632879283958270851091995883944829777564715202613287108952616341770715164289948795356485455355314875497813400996485449863582484769059003311696130376612792346432312970662841130742704620203201336835038542536031363676357521260470742531120923340283748294945310472741896928727557202761527226828337674139342565265328306846999759709775000556088993268502504921288406827413988163154045649035077587168007405568572402175868543905322813377070741583075626962831695568742406052772648585305061135638485196591896864959633556821697543762143077866593473045016482243296489127070989807667662567151726906205881554966638257382927418208227896068448822298339481667098403902428351430681376725346012600726926296946867275079434619043999661897961192875051944235640264430327173734159128149605616835398818856948404534231142461355992527233006488162746672352375123431189344211888508507935816384899448754475633168921386967557430273795378526254232902488104718193903722066689470220425883689584093999845356094886994683385257967516188215941098162491874181336472696512398067756194791255795744647142786862405375057610420426714936608498023827468057598259133100691994190465190653117190892607794911921794640735512963386452303567334558803331319708036545718479155043265489955970586288828686660661802188224860214499997312216413817065348017551043840662441282280361664890425737764095632648282525840766904560843949032529052633753231650908768133661424239830953080654966187938194912003391948949406513239881664208008839555494223709673484007264270570116508907519615537018626479745638118785617545711340047381076276301495330973517418065547911266093803431137853253288353335202493436597912934128485497094682632907583019307266533778255931433111096384805394085928398890779621047984791968687653998747709591278872747587443980677982496827827220092644994455938041460877064194181044075826980568803894965461658798390466058764534181028990719429302177451997610449504319684150345551404482092893337865736305283061999007774872692299860827905317169187657886090894181705799340489021844155979109267686279659758395248392673488363474565168701616624064242424122896111801061568234253939218005248345472377921991122859591419187749179382334001007812832650671028178139602912091472010094787875255126337288422235386949006792766451163475810119387531965724212147603828477477457170457861041738574791130190858387789015233434301300528279703858035981518292960030568261209195094373732545417105638388704752895056396102984364136093564163258940813798151169333861979733982167076100460798009601602482309694304380695662012321365014054958625061528258803302290838581247846931572032323360189946943764772672187937682643182838260356452069946863021604887452842436359355862233350623594500289055858161127534178375045593612613085264082805121387317749020024955273873458595640516083058305377073253397155262

16

044470542957353836111367752316997274029294167420442324811387507563131907827218886405337469421384216992886294047963530515056078812636620649723125757901959887304119562622734372890051656111109411174527796548279047125058199907749806382155937688554649882293898540829132512907647838632249478101675349169348928810420301561028338614382737816094634133538357834076531432141715065587754782025245478065730134227747061674424196895261316427410469547462148375628829977180418678508454696561915090869587425118443583730659095146098045124740941137389992782249298336779601101538709612974970556630163730720275073475992294379239382442742118615823616131788639255309511718842129850830723825972914414225157940388301135908333165185823496722125962181250705811375949552502274727467436988713192667076929919908446716122873885845758462272657333075373557282395161696417519867501268174542932373829414382481437713986190671665757294580780482055951188168718807521297183263644215533678775127476694079011705750981957508456356521738954417987507452385445520013357203333237989507439390531291821225525983379090946363020218535384885482506289771561696386071238277172562131346054940177041358173193176337013633225281912754719144345092071184883836681817426334294961187009150304916533946476371776643912079834749462739782217150209067019030246976215127852195614207080646163137323651785397629209202550028896201297014137964003805573494926907353514596120867479654773369295877362863566014376796403843079686413856344780132826128458918489852804804884418082163942397401436290348166545811445436646003249061876303950235640204453074821024136689519664422133920075747912868380517515063466256939193774028351207566626082989049187728783385217852279204577184696585527879044756219266399200840930207567392536373562839082981757790215320210640961737328359849406665214119818381088451545977289516457213189779790749194101314836854463961690460703010759681893374121757598816512700076126278916951040631585763753478742007022205107089125761236165802680681585849985263146587808661680073326467683020639169720306489440562819540619068524200305346315662189132730906968735318164109451428803660599522024824888671155442910472192913424834643870536850864874909917881267056566538719104972182004237149274016446094345984539253670613221061653308566202118896823400575267548610147699368873820958455221157192347968688816085363161586288015039594941852948922707441082820716930338781808493620401825522227101098565344481720747075601924591559943107294957819787859057894005254012286751714251118435643718405356302418122547326609330271039796809106493927272268303541046763259135527968383770501985523462122285841055711992173171796980433931770775075562705604783177984444763756025463703336924711422081551997369137197516324130274871219986340454824852457011855334267526471597831073124566342980522145549415625272402891533335434934121786203700726031527987077187249123449447714790952073476138542548531155277330103034247683586549609372232400715451812973269208105842409055772564580368146223449318970813889714329983134761779967971245378231070373915147387869211918756670031932128189680332269659445928621060743882741691946516226763254066507088107103039417886056489376981673415902592519461182364294565266937220315550470021359884629275801252771542201662995486313032491231102962792372389976641680349714122652793190763632613681414551637665655983978848938173308266877990196288693229659737995193162118721545528739417024366988559388879331674453336311954151840408828381519342123412282003095031334105070476015998798547252919066522247931971544033179483683737322082188577334162385644138070054191353024594391350255453188645479625226025176292837433046510236105758351455073944333961021622967546141578112719700173861149427950141125328062125477581051297208846526315809480663368767014731073354071771087661593585681409821296773075919738297344144525668877085532457088895832099382343210271822411476373279135756861542125284965790333509315277692550584564401055219264450531207375628774499816364633283581614033017581396735942732769044892036188038675495575180689005853292720149392350052584514670698262854825788326739873522045722823929020714482221988558710289699193587307427781515975762076402395124386020203259659625021257834995771008562638611823381331850901468657706401067627861758377277289589274603940393033727187385053691295712671506689668849388088514294360996201296675907922508227531381284985152690293170026313632894209579757795932763553116206675348865131732387243874806351331451264488996758982881292548007642518658649024111112730135719718138160258317850693224400799865663537154408845486639318170839573578079905973083909488180406

17

0935959190907473960904410150516321749681412100765719177483767355751000733616922386537429079457803200042337452807566153042929014495780629634138383551783599764708851349004856973697965238695845994595592090709058956891451141412684505462117945026611750166928260250950770778211950432617383223562437601776799362796099368975191394965033358507155418436456852616674243688920371037495328425927131610537834980740739158633817967658425258036737206469351248652238481341663808061505704829059890696451936440018597120425723007316410009916987524260377362177763430621616744884930810929901009517974541564251204822086714586849255132444266777127863728211331536224301091824391243380214046242223349153559516890816288487989988273630445372432174280215755777967021666317047969728172483392841015642274507271779269399929740308072770395013581545142494049026536105825409373114653104943382484379718606937214444600826798002471229489405761853892203425608302697052876621377373594394224114707074072902725461307358541745691419446487624357682397065703184168467540733466346293673983620004041400714054277632480132742202685393698869787607009590048684650626771363070979821006557285101306601010780633743344773073478653881742681230743766066643312775356466578603715192922768440458273283243808212841218776132042460464900801054731426749260826922155637405486241717031027919996942645620955619816454547662045022411449404749349832206807191352767986747813458203859570413466177937228534940031631599544093684089572533438702986717829770373332806801764639502090023941931499115009105276821119510999063166150311585582835582607179410052528583611369961303442790173811787412061288182062023263849861515656451230047792967563618345768105043341769543067538041113928553792529241347339481050532025708728186307291158911335942014761872664291564036371927602306283840650425441742335464549987055318726887926424102147363698625463747159744354943443899730051742525110877357886390946812096673428152585919924857640488055071329814299359911463239919113959926752576359007446572810191805841807342227734721397723218231771716916400108826112549093361186780575722391018186168549108500885272274374212086524852372456248697662245384819298671129452945515497030585919307198497105414181636968976131126744027009648667545934567059936995464500558921628047976365686133316563907395703272034389175415267500915011198856872708848195531676931681272892143031376818016445477367518353497857924276463354162433601125960252109501612264110346083465648235597934274056868849224458745493776752120324703803035491157544831295275891939893680876327685438769557694881422844311998595700727521393176837831770339130423060958999137314684569010422095161967070506420256733873446115655276175992727151877660010238944760539789516945708802728736225121076224091810066700883474737605156285533943565843756271241244457651663064085939507947550920463932245202535463634444791755661725962187199279186575490857852950012840229035061514937310107009446151011613712423761426722541732055959202782129325725947146417224977321316381845326555279604270541871496236585252458648933254145062642337885651464670604298564781968461593663288954299780722542264790400616019751975007460545150060291806638271497016110987951336633771378434416194053121445291855180136575558667615019373029691932076120009255065081583275508499340768797252369987023567931026804136745718956641431852679054717169962990363015545645090044802789055701968328313630718997699153166679208958768572290600915472919636381673596673959975710326015571920237348580521128117458610065152598883843114511894880552129145775699146577530041384717124577965048175856395072895337539755822087777506072339445587895905719156736

C = SetPartitions ([1,2,3])C.list()[{{1, 2, 3}}, {{1}, {2, 3}}, {{1, 3}, {2}}, {{1, 2}, {3}}, {{1}, {2}, {3}}]

[[ binomial(n,i) for i in range(n+1)] for n in range (10)][[1], [1, 1], [1, 2, 1], [1, 3, 3, 1], [1, 4, 6, 4, 1], [1, 5, 10, 10, 5, 1], [1, 6, 15,20, 15, 6, 1], [1, 7, 21, 35, 35, 21, 7, 1], [1, 8, 28, 56, 70, 56, 28, 8, 1], [1, 9, 36,84, 126, 126, 84, 36, 9, 1]]

18

C = Permutations (4)CStandard permutations of 4

C.list()[[1, 2, 3, 4], [1, 2, 4, 3], [1, 3, 2, 4], [1, 3, 4, 2], [1, 4, 2, 3], [1, 4, 3, 2], [2,1, 3, 4], [2, 1, 4, 3], [2, 3, 1, 4], [2, 3, 4, 1], [2, 4, 1, 3], [2, 4, 3, 1], [3, 1, 2,4], [3, 1, 4, 2], [3, 2, 1, 4], [3, 2, 4, 1], [3, 4, 1, 2], [3, 4, 2, 1], [4, 1, 2, 3],[4, 1, 3, 2], [4, 2, 1, 3], [4, 2, 3, 1], [4, 3, 1, 2], [4, 3, 2, 1]]

C = Compositions (5)C.list()list(Compositions (5, max_length =2))[[1, 1, 1, 1, 1], [1, 1, 1, 2], [1, 1, 2, 1], [1, 1, 3], [1, 2, 1, 1], [1, 2, 2], [1, 3,1], [1, 4], [2, 1, 1, 1], [2, 1, 2], [2, 2, 1], [2, 3], [3, 1, 1], [3, 2], [4, 1], [5]][[5], [4, 1], [3, 2], [2, 3], [1, 4]]

C = Combinations(range (4))C.list()[[], [0], [1], [2], [3], [0, 1], [0, 2], [0, 3], [1, 2], [1, 3], [2, 3], [0, 1, 2], [0, 1,3], [0, 2, 3], [1, 2, 3], [0, 1, 2, 3]]

Combinations ([1,2,2,3]).list()[[], [1], [2], [3], [1, 2], [1, 3], [2, 2], [2, 3], [1, 2, 2], [1, 2, 3], [2, 2, 3], [1,2, 2, 3]]

C = CartesianProduct(Compositions (8), Permutations (20))CCartesian product of Compositions of 8, Standard permutations of 20

C.cardinality ()311411457046609920000

D = Derangements (4)D.list()[[2, 3, 4, 1], [4, 3, 1, 2], [2, 4, 1, 3], [3, 4, 2, 1], [3, 1, 4, 2], [4, 1, 2, 3], [4,3, 2, 1], [3, 4, 1, 2], [2, 1, 4, 3]]

4 Teorija grafova

Nađite najveći podskup prirodnih brojeva manjih od 100 takvih da za svaki par (a, b) vrijedi da a − b nijekvadrat prirodnog broja?

n = 100g=Graph(n)kvadrati = [i*i for i in range(sqrt(n))]bridovi = [(i,j) for (i,j) in CartesianProduct(range(n),range(n)) if (i!=\

j and abs(i-j) in kvadrati)]g.add_edges(bridovi)g.independent_set ()

19

[3, 5, 8, 10, 15, 20, 22, 25, 27, 32, 37, 42, 49, 55, 60, 70, 75, 77, 82, 87, 92, 94, 97,99]

g = graphs.CompleteGraph (5)_=latex.eval(latex(g)) #https :// github.com/sagemath/cloud/wiki/FAQ#tikz

G = Graph ()G.add_vertices(range (10))G.add_cycle(range (10))_=latex.eval(latex(G))

20

D = DiGraph ()D.add_cycle(range (4))_=latex.eval(latex(D))

d = {0: [1,4,5], 1: [2,6], 2: [3,7], 3: [4,8], 4: [9], 5: [7,8], 6: \[8,9], 7: [9]}

G = Graph(d)_=latex.eval(latex(G))

G.add_vertices ([10 ,11 ,12])G.vertices ()[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]

21

G.adjacency_matrix ()[0 1 0 0 1 1 0 0 0 0 0 0 0][1 0 1 0 0 0 1 0 0 0 0 0 0][0 1 0 1 0 0 0 1 0 0 0 0 0][0 0 1 0 1 0 0 0 1 0 0 0 0][1 0 0 1 0 0 0 0 0 1 0 0 0][1 0 0 0 0 0 0 1 1 0 0 0 0][0 1 0 0 0 0 0 0 1 1 0 0 0][0 0 1 0 0 1 0 0 0 1 0 0 0][0 0 0 1 0 1 1 0 0 0 0 0 0][0 0 0 0 1 0 1 1 0 0 0 0 0][0 0 0 0 0 0 0 0 0 0 0 0 0][0 0 0 0 0 0 0 0 0 0 0 0 0][0 0 0 0 0 0 0 0 0 0 0 0 0]

g = graphs.CompleteGraph (5)g.average_degree ()4

RandomGNP(n,p) vraća slučajan graf s n vrhova, s time da je svaki brid ubačen s vjerojatnošću p.

g = graphs.RandomGNP (20 ,0.5)g.min_spanning_tree () #default je Kriskalov algoritam[(0, 1, None), (0, 2, None), (0, 3, None), (0, 4, None), (0, 6, None), (0, 7, None), (0,8, None), (0, 9, None), (0, 13, None), (0, 14, None), (0, 15, None), (0, 16, None), (1, 5,None), (1, 11, None), (1, 17, None), (1, 18, None), (2, 12, None), (3, 19, None), (4, 10,None)]

g = graphs.CompleteGraph (5)tezina = lambda e: 1 / ((e[0] + 1) * (e[1] + 1))g.min_spanning_tree(algorithm=’Prim_fringe ’, starting_vertex =2, \

weight_function=tezina) #Primov algoritam[(2, 4), (4, 3), (4, 1), (4, 0)]

D = DiGraph ({0 : [1, 3], 1 : [2], 2 : [3], 4 : [5, 6], 5 : [6]})D.connected_components_number ()D.connected_components ()2[[0, 1, 2, 3], [4, 5, 6]]

P = graphs.PetersenGraph ()P.degree (5)P.degree ()3[3, 3, 3, 3, 3, 3, 3, 3, 3, 3]

G = graphs.CompleteGraph (19)G.size()G.delete_edges( [ (5, 6), (7, 8) ] )G.size()171

22

169

G = graphs.CycleGraph (9)_=latex.eval(latex(G))

G.distance (0,5)4

G = graphs.CompleteGraph (7)G.is_eulerian ()G.eulerian_circuit(labels=False)True[(0, 6), (6, 5), (5, 4), (4, 6), (6, 3), (3, 5), (5, 2), (2, 4), (4, 3), (3, 2), (2, 6),(6, 1), (1, 5), (5, 0), (0, 4), (4, 1), (1, 3), (3, 0), (0, 2), (2, 1), (1, 0)]

g = G.random_subgraph (0.25)_=latex.eval(latex(g))

23

g = graphs.CubeGraph (4)g.is_planar ()False

g = graphs.CubeGraph (3)g.is_planar ()True

G = Graph( { 0 : [1, 2], 1 : [2], 3 : [4, 5], 4 : [5] } )_=latex.eval(latex(G))

24

G.is_connected ()False

G.add_edge (0,3)G.is_connected ()True

D = graphs.DodecahedralGraph ()D.shortest_path (4, 9)[4, 17, 16, 12, 13, 9]

n = 11G = graphs.CompleteGraph(n)ST = G.spanning_trees_count ()ST == n^(n-2)True

5 Kriptografija5.0.6 RSA

Neka su p, q (veliki) prosti brojevi. Neka je n = p ∗ q. Znamo ϕ(n) = (p− 1)(q − 1).Neka je e tzv. enkripcijski eksponent, bilo koji broj koji je relativno prost s ϕ(n). Kako su e i ϕ(n)

relativno prosti, postoji multiplikativni inverz d: ed ≡ 1 (mod ϕ(n)). Broj d zovemo dekripcijski eksponent.Parametar (n, e) je javan, dok su faktorizacija n = pq te broj d tajni. Dekripcija se obavlja funkcijomf(x) = xe a enkripcija funkcijom g(y) = yd mod n (pretpostavljamo x < n).

Par (n, e) zovemo javni ključ a trojku (p, q, d) privatni ključ.

p = (2^31) - 1is_prime(p)True

q = (2^61) - 1is_prime(q)True

n = p * qn4951760154835678088235319297

phi = (p - 1)*(q - 1)phi4951760152529835076874141700

e = ZZ.random_element(phi)while gcd(e, phi) != 1:

e = ZZ.random_element(phi)

e4124334359281736885907994237

25

e < nTrue

ed ≡ 1 (mod ϕ(n)) je ekvivalentno s de− kϕ(b) = 1, pa d možemo odrediti Euklidovim algoritmom.

b = xgcd(e, phi)d = Integer(mod(b[1], phi))d4335296058468185697429612373

mod(d * e, phi)1

(n,e) #javni ključ(4951760154835678088235319297, 4124334359281736885907994237)

(p,q,d) #privatni ključ(2147483647, 2305843009213693951, 4335296058468185697429612373)

x = "ZDRAVO!" #želimo šifriratim = map(ord , x)m[90, 68, 82, 65, 86, 79, 33]

m = ZZ(list(reversed(m)), 100)m90688265867933

c = power_mod(m, e, n)c #šifrirani tekst358182658345234025641464040

power_mod(c, d, n) == mTrue

26