24 lines
591 B
Text
24 lines
591 B
Text
|
|
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))
|