September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -0,0 +1,5 @@
|
|||
(defn modpow
|
||||
" b^e mod m (using Java which solves some cases the pure clojure method has to be modified to tackle--i.e. with large b & e and
|
||||
calculation simplications when gcd(b, m) == 1 and gcd(e, m) == 1) "
|
||||
[b e m]
|
||||
(.modPow (biginteger b) (biginteger e) (biginteger m)))
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
! Built-in
|
||||
2988348162058574136915891421498819466320163312926952423791023078876139
|
||||
2351399303373464486466122544523690094744975233415544072992656881240319
|
||||
10 40 ^
|
||||
^mod .
|
||||
1527229998585248450016808958343740453059
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
_powm(b, e, m, r) = (e == 0 ? r : (e % 2 == 1 ? _powm(b * b % m, e / 2, m, r * b % m) : _powm(b * b % m, e / 2, m, r)))
|
||||
powm(b, e, m) = _powm(b, e, m, 1)
|
||||
# Usage
|
||||
print powm(2, 3453, 131)
|
||||
# Where b is the base, e is the exponent, m is the modulus, i.e.: b^e mod m
|
||||
|
|
@ -1,10 +1,12 @@
|
|||
powm :: Integer -> Integer -> Integer -> Integer -> Integer
|
||||
powm b 0 m r = r
|
||||
powm b e m r | e `mod` 2 == 1 = powm (b * b `mod` m) (e `div` 2) m (r * b `mod` m)
|
||||
powm b e m r
|
||||
| e `mod` 2 == 1 = powm (b * b `mod` m) (e `div` 2) m (r * b `mod` m)
|
||||
powm b e m r = powm (b * b `mod` m) (e `div` 2) m r
|
||||
|
||||
main :: IO ()
|
||||
main = putStrLn . show $
|
||||
main =
|
||||
print $
|
||||
powm
|
||||
2988348162058574136915891421498819466320163312926952423791023078876139
|
||||
2351399303373464486466122544523690094744975233415544072992656881240319
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
// version 1.0.6
|
||||
|
||||
import java.math.BigInteger
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val a = BigInteger("2988348162058574136915891421498819466320163312926952423791023078876139")
|
||||
val b = BigInteger("2351399303373464486466122544523690094744975233415544072992656881240319")
|
||||
val m = BigInteger.TEN.pow(40)
|
||||
println(a.modPow(b, m))
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
/* Modular exponentiation */
|
||||
|
||||
numeric digits 100
|
||||
say powerMod(,
|
||||
2988348162058574136915891421498819466320163312926952423791023078876139,,
|
||||
2351399303373464486466122544523690094744975233415544072992656881240319,,
|
||||
1e40)
|
||||
exit
|
||||
|
||||
powerMod: procedure
|
||||
|
||||
use strict arg base, exponent, modulus
|
||||
|
||||
exponent=exponent~d2x~x2b~strip('L','0')
|
||||
result=1
|
||||
base = base // modulus
|
||||
do exponentPos=exponent~length to 1 by -1
|
||||
if (exponent~subChar(exponentPos) == '1')
|
||||
then result = (result * base) // modulus
|
||||
base = (base * base) // modulus
|
||||
end
|
||||
return result
|
||||
|
|
@ -18,9 +18,9 @@ powerMod: procedure; parse arg x,p,n /*fast modular exponentiat
|
|||
if p<0 then do; say '***error*** power is negative:' p; exit 13; end
|
||||
parse value max(x**2,p,n)'E0' with "E" e /*obtain the biggest of the three.*/
|
||||
numeric digits max(20, e*2) /*big enough to handle A². */
|
||||
_=1 /*use this for the first value. */
|
||||
$=1 /*use this for the first value. */
|
||||
do while p\==0 /*perform while P isn't zero.*/
|
||||
if p//2 then _=_*x//n /*is P odd? (is ÷ remainder≡1).*/
|
||||
p=p%2; x=x*x//n /*halve P; calculate x² mod n */
|
||||
if p//2 then $=$ * x // n /*is P odd? (is ÷ remainder≡1).*/
|
||||
p=p%2; x=x * x // n /*halve P; calculate x² mod n */
|
||||
end /*while*/ /* [↑] keep mod'ing 'til equal 0.*/
|
||||
return _
|
||||
return $
|
||||
|
|
|
|||
|
|
@ -1,6 +0,0 @@
|
|||
#lang racket
|
||||
(require math)
|
||||
(define a 2988348162058574136915891421498819466320163312926952423791023078876139)
|
||||
(define b 2351399303373464486466122544523690094744975233415544072992656881240319)
|
||||
(define m (expt 10 40))
|
||||
(modular-expt a b m)
|
||||
|
|
@ -1 +0,0 @@
|
|||
1527229998585248450016808958343740453059
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
var BN=Import("zklBigNum");
|
||||
a:=BN("2988348162058574136915891421498819466320163312926952423791023078876139");
|
||||
b:=BN("2351399303373464486466122544523690094744975233415544072992656881240319");
|
||||
m:=BN(10).pow(40);
|
||||
a.powm(b,m).println();
|
||||
a.powm(b,m) : "%,d".fmt(_).println();
|
||||
Loading…
Add table
Add a link
Reference in a new issue