30 lines
858 B
Plaintext
30 lines
858 B
Plaintext
include builtins/mpfr.e
|
|
|
|
mpz n = mpz_init("9516311845790656153499716760847001433441357"),
|
|
e = mpz_init("65537"),
|
|
d = mpz_init("5617843187844953170308463622230283376298685"),
|
|
pt = mpz_init(),
|
|
ct = mpz_init()
|
|
|
|
string plaintext = "Rossetta Code" -- matches C/zkl
|
|
-- "Rosetta Code" -- matches D/FreeBasic/Go/Icon/J/Kotlin/Seed7.
|
|
|
|
mpz_import(pt, length(plaintext), 1, 1, 0, 0, plaintext)
|
|
|
|
if mpz_cmp(pt, n)>0 then ?9/0 end if
|
|
|
|
mpz_powm(ct, pt, e, n);
|
|
printf(1,"Encoded: %s\n", {mpz_get_str(ct)})
|
|
|
|
mpz_powm(pt, ct, d, n);
|
|
printf(1,"Decoded: %s\n", {mpz_get_str(pt)})
|
|
|
|
integer size =floor((mpz_sizeinbase(pt,2)+7)/8)
|
|
atom pMem = allocate(size,true)
|
|
integer count = mpz_export(pMem, 1, 1, 0, 0, pt)
|
|
if count>size then ?9/0 end if
|
|
|
|
printf(1,"As String: %s\n", {peek({pMem,count})})
|
|
|
|
{pt, ct, n, e, d} = mpz_free({pt, ct, n, e, d})
|