home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CP/M
/
CPM_CDROM.iso
/
cpm
/
cug
/
softt-12.lbr
/
PWRMOD.RAT
< prev
next >
Wrap
Text File
|
1984-07-05
|
768b
|
24 lines
#-h- pwrmod.r 860 local 01/05/81 21:33:56
# pwrmod --- calculate an exponential, modulo a given modulus
# (function result is p ** E mod n)
long_int function pwrmod (p, E, n)
long_int p, E, n
integer i
long_int result
define(bit_i,rt (rs (E, BITS_PER_LONG_WORD - i), 1)) # i'th bit of E
# 'rt' is right-truncate, 'rs' is right-shift
result = 1
for (i = 1; i <= BITS_PER_LONG_WORD; i += 1)
if (bit_i == 0)
result = mod (result * result, n)
else
result = mod (mod (result * result, n) * p, n)
return (result)
end
#-t- pwrmod.r 860 local 01/05/81 21:33:56
#-t- pwrmod 1867 local 01/05/81 21:38:53