RosettaCodeData/Task/RSA-code/11l/rsa-code.11l

24 lines
591 B
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

V n = BigInt(9516311845790656153499716760847001433441357)
V e = BigInt(65537)
V d = BigInt(5617843187844953170308463622230283376298685)
V txt = Rosetta Code
print(Plain text: txt)
V txtN = txt.reduce(BigInt(0), (a, b) -> a * 256 + b.code)
print(Plain text as a number: txtN)
V enc = pow(txtN, e, n)
print(Encoded: enc)
V dec = pow(enc, d, n)
print(Decoded: dec)
V decTxt =
L dec != 0
decTxt = Char(code' dec % 256)
dec I/= 256
print(Decoded number as text: reversed(decTxt))