#Homework Monday, Jan 22, 2024 #Ok to post Help := proc(): print(`Beginner(), EulerThe_(n), MyIfactor(n)`) : end: with(NumberTheory): # Textbook examples with modified changes #------------------------------------------ Beginner := proc() local k,z: Sum(i^3,i=1..5); print(value(%)); z := exp(x^2*y)(sqrt(x^3*y^2+2*y+x^2)); diff(z,x); end: # Euler's Theorem #------------------------------------------ EulerThe_ := proc(n) local A, i, a, phi, status: A := {}: for i from 1 to (n-1) do: if AreCoprime(i, n) then: A := A union {i}: fi: od: phi := nops(A): status := "SUCCESS": for a in A do: if (a^phi mod n) <> 1 then: return 1; fi: od: return 0; end: #Checking to see if my implementation of Euler's Theorem works status := SUCCESS: for i from 1 to 1200 do if EulerThe_(i) = 1 then status := FAILURE: break; fi: od: print(status); # RSA Encryption #____________________________________________ p := nextprime(rand(10^5..10^6-1)()): q := nextprime(rand(10^5..10^6-1)()): n := p * q: do e := nextprime(rand(10^5..10^6-1)()): until AreCoprime(e, n): phi_ := Totient(n): d := e&^(-1) mod phi_; do cipher_message := rand(0..n)(): until AreCoprime(cipher_message, n): message := cipher_message&^(d) mod n; encrypted_message := message&^(e) mod n; print("RSA Encryption is complete"); # Procedure for MyIfactor(n) #------------------------------------------- MyIfactor := proc(n) local p, prime_factors, i, temp: temp := n: prime_factors := []: while (temp <> 1) do p := 0: while (p = 0 or temp mod p <> 0) do p := nextprime(p): od: prime_factors := [op(prime_factors), p]: temp := temp / p: od: return prime_factors; end: # Time Comparison between MyIfactor(n) and ifactor(n) myifactor_time := 0: ifactor_time := 0: for i from 1 to 100000 do myifactor_time := myifactor_time + time(MyIfactor(i)): ifactor_time := ifactor_time + time(ifactor(i)): od: printf("My time: %f\nMaple time: %f\n", myifactor_time, ifactor_time);