REM Modular Exponentiation using Russian Peasant Method REM Robert Campbell, 970629 DECLARE FUNCTION powmod& (number&, exponent&, modulus&) PRINT "Enter numbers for powmod computation:" INPUT " Base: ", number& INPUT " Exponent: ", exponent& INPUT " Modulus: ", modulus& temp& = powmod&(number&, exponent&, modulus&) PRINT "powmod(", number&, ", ", exponent&, ", ", modulus&, ") = ", temp& END FUNCTION powmod& (number&, exponent&, modulus&) e& = exponent& accum& = 1 pow2& = number& WHILE (e& > 0) IF ((e& MOD 2) = 1) THEN accum& = (accum& * pow2&) MOD modulus& pow2& = (pow2& * pow2&) MOD modulus& e& = e& \ 2 WEND powmod& = accum& EXIT FUNCTION END FUNCTION