#C2.txt, Jan. 22, 2024 Help:=proc(): print(` NextPrime1(n),MakeRSAkey(D1), ME1s(a,e,n), ME1(a,e,n) `): end: #NextPrime1(n): inputs a pos. integer n #and outputs the first prime >=n NextPrime1:=proc(n) local i: for i from n while not isprime(i) do od: i: end: #MakeRSAkey: The key [n,e]: a->a^e mod n #n must be a product of two primes #inputs D1 and outputs an RSA key #[n,e], where n is a product of two primes #with D1 digits. Try: #MakeRSAkey(100); MakeRSAkey:=proc(D1) local n: n:=NextPrime1(rand(10^(D1-1)..10^D1-1)())* NextPrime1(rand(10^(D1-1)..10^D1-1)()): n: end: #ME1s(a,e,n): a^e mod n,the stupid way ME1s:=proc(a,e,n) local i,s: s:=1: for i from 1 to e do s:=s*a mod n: od: s: end: #ME1(a,e,n): a^e mod n,the smart way ME1:=proc(a,e,n) local i,s: if e=1 then RETURN(a mod n): fi: if e mod 2=0 then RETURN(ME1(a,e/2,n)^2 mod n): else RETURN(ME1(a,e-1,n)*a mod n): fi: end: