> with(numtheory): Warning, the protected name order has been redefined and unprotected > > ## Susthma kruptografhshs RSA > > gen_key:=proc(digits) > local R1,R2,p,q,length,n,e,d,phin,tmp,i: > irem(digits,2,'length'): > R1:=rand(10^(digits-1),10^digits): > p:=nextprime(R1()): > q:=nextprime(R1()): > n:=p*q: > R2:=rand(4..100): > phin:=phi(n): > e:=R2(): > for i from 1 while igcd(e,phin)>1 do > e:=R2() > end do: > igcdex(e,phin,'d','tmp'): > RETURN([[n,d],[n,e]]): > end proc: > > ## Kruptografhsh > encrypt:=proc(m,public) > local c,n,e: > n:=public[1]: > e:=public[2]: > c:=m&^e mod n: > RETURN(c): > end proc: > > ## Apokruptografhsh > decrypt:=proc(c,private) > local n,d,m: > n:=private[1]: > d:=private[2]: > m:=c&^d mod n: > RETURN(m): > end proc: > > key:=gen_key(20); key := [[4214854681266378492006369749407863773, 1978401176920953167773167246032780689], [4214854681266378492006369749407863773, 49]] > private:=key[1]; private := [4214854681266378492006369749407863773, 1978401176920953167773167246032780689] > public:=key[2]; public := [4214854681266378492006369749407863773, 49] > m:=1234567890987654321; m := 1234567890987654321 > igcd(m,public[1]); 1 > ciphertext:=encrypt(m,public); ciphertext := 871949470675522843202481294367281324 > decrypt(ciphertext,private); 1234567890987654321 >