Data update

This commit is contained in:
Ingy döt Net 2026-04-30 12:34:36 -04:00
parent 4bb20c9b71
commit cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions

View file

@ -0,0 +1,26 @@
with Ada.Text_IO, Ada.Command_Line, Crypto.Types.Big_Numbers;
procedure Mod_Exp is
A: String :=
"2988348162058574136915891421498819466320163312926952423791023078876139";
B: String :=
"2351399303373464486466122544523690094744975233415544072992656881240319";
D: constant Positive := Positive'Max(Positive'Max(A'Length, B'Length), 40);
-- the number of decimals to store A, B, and result
Bits: constant Positive := (34*D)/10;
-- (slightly more than) the number of bits to store A, B, and result
package LN is new Crypto.Types.Big_Numbers (Bits + (32 - Bits mod 32));
-- the actual number of bits has to be a multiple of 32
use type LN.Big_Unsigned;
function "+"(S: String) return LN.Big_Unsigned
renames LN.Utils.To_Big_Unsigned;
M: LN.Big_Unsigned := (+"10") ** (+"40");
begin
Ada.Text_IO.Put("A**B (mod 10**40) = ");
Ada.Text_IO.Put_Line(LN.Utils.To_String(LN.Mod_Utils.Pow((+A), (+B), M)));
end Mod_Exp;

View file

@ -0,0 +1,16 @@
with Ada.Text_IO; use Ada.Text_IO;
with Unbounded_Unsigneds; use Unbounded_Unsigneds;
with Strings_Edit.Unbounded_Unsigned_Edit;
use Strings_Edit.Unbounded_Unsigned_Edit;
procedure Modular_Exponent is
begin
Put_Line
( Image
( Mod_Pow
( Value ("2988348162058574136915891421498819466320163312926952423791023078876139"),
Value ("2351399303373464486466122544523690094744975233415544072992656881240319"),
From_Half_Word (10) ** 40
) ) );
end Modular_Exponent;

View file

@ -0,0 +1 @@
2988348162058574136915891421498819466320163312926952423791023078876139 SPC 10 SPC 40 ^ C-u -5 v p 2351399303373464486466122544523690094744975233415544072992656881240319 ^ v u DEL

View file

@ -0,0 +1,7 @@
import "dart:math";
void main() {
var a = BigInt.parse("2988348162058574136915891421498819466320163312926952423791023078876139");
var b = BigInt.parse("2351399303373464486466122544523690094744975233415544072992656881240319");
var m = BigInt.from(10).pow(40);
print(a.modPow(b, m));
}

View file

@ -0,0 +1,175 @@
func[] bn s$ .
i = len s$ - 7 + 1
while i >= -5
r[] &= number substr s$ i 7
i -= 7
.
return r[]
.
func$ str bn[] .
s$ = bn[$]
for i = len bn[] - 1 downto 1
h$ = bn[i]
s$ &= substr "0000000" 1 (7 - len h$) & h$
.
return s$
.
func[] bnmul a[] b[] .
len r[] len a[] + len b[]
if len a[] > len b[] : swap a[] b[]
for ia = 1 to len a[]
h = 0
for ib = 1 to len b[]
h += r[ia + ib - 1] + b[ib] * a[ia]
r[ia + ib - 1] = h mod 10000000
h = h div 10000000
.
r[ia + ib - 1] += h
.
while len r[] > 1 and r[$] = 0 : len r[] -1
return r[]
.
func[] bnadd a[] b[] .
if len b[] > len a[] : swap a[] b[]
len r[] len a[]
for i = 1 to len r[]
v = 0
if i <= len b[] : v = b[i]
h += a[i] + v
r[i] = h mod 10000000
h = h div 10000000
.
if h > 0 : r[] &= h
while r[$] = 0 and len r[] > 1 : len r[] -1
return r[]
.
func bncmp a[] b[] .
if len a[] > len b[] : return 1
if len a[] < len b[] : return -1
for i = len a[] downto 1
if a[i] > b[i] : return 1
if a[i] < b[i] : return -1
.
return 0
.
func[] bnsub a[] b[] .
len r[] len a[]
for i = 1 to len r[]
v = 0
if i <= len b[] : v = b[i]
h = a[i] - v - c
c = 0
if h < 0
h += 10000000
c = 1
.
r[i] = h
.
while r[$] = 0 and len r[] > 1 : len r[] -1
return r[]
.
func[][] bndivmod a[] b[] .
if bncmp a[] b[] < 0 : return [ [ 0 ] a[] ]
lb = len b[]
d = 10000000 div (b[lb] + 1)
if d > 1
for i = 1 to lb
carry += b[i] * d
b[i] = carry mod 10000000
carry = carry div 10000000
.
for i = 1 to len a[]
carry += a[i] * d
a[i] = carry mod 10000000
carry = carry div 10000000
.
.
a[] &= carry
len q[] len a[] - lb
v1 = b[lb]
if lb >= 2 : v2 = b[lb - 1]
for j = len q[] downto 1
u0 = a[j + lb]
u1 = a[j + lb - 1]
u2 = 0
if j + lb >= 2 : u2 = a[j + lb - 2]
if u0 = v1
qhat = 9999999
rhat = u1 + v1
else
h = u0 * 10000000 + u1
qhat = h div v1
rhat = h mod v1
.
while rhat < 10000000 and qhat * v2 > 10000000 * rhat + u2
qhat -= 1
rhat += v1
.
k = 0
for i = 1 to lb
p = qhat * b[i] + k
k = p div 10000000
t = a[j + i - 1] - (p mod 10000000)
if t < 0
t += 10000000
k += 1
.
a[j + i - 1] = t
.
t = a[j + lb] - k
if t < 0
qhat -= 1
k = 0
for i = 1 to lb
t = a[j + i - 1] + b[i] + k
a[j + i - 1] = t mod 10000000
k = t div 10000000
.
a[j + lb] = t + k
else
a[j + lb] = t
.
q[j] = qhat
.
if d > 1
k = 0
for i = lb downto 1
t = k * 10000000 + a[i]
a[i] = t div d
k = t mod d
.
.
len a[] lb
while len q[] > 1 and q[len q[]] = 0 : len q[] len q[] - 1
while len a[] > 1 and a[len a[]] = 0 : len a[] len a[] - 1
return [ q[] a[] ]
.
func[] bnmod a[] n[] .
result[][] = bndivmod a[] n[]
return result[2][]
.
func[] bnpowmod base[] exp[] m[] .
r[] = [ 1 ]
b[] = bnmod base[] m[]
e[] = exp[]
while bncmp e[] [ 0 ] > 0
if e[1] mod 2 = 1
r[] = bnmul r[] b[]
r[] = bnmod r[] m[]
.
h = 0
for i = len e[] downto 1
h = h * 10000000 + e[i]
e[i] = h div 2
h = h mod 2
.
while e[$] = 0 and len e[] > 1 : len e[] -1
b[] = bnmul b[] b[]
b[] = bnmod b[] m[]
.
return r[]
.
a$ = "2988348162058574136915891421498819466320163312926952423791023078876139"
b$ = "2351399303373464486466122544523690094744975233415544072992656881240319"
m$ = "10000000000000000000000000000000000000000"
print str bnpowmod bn a$ bn b$ bn m$

View file

@ -0,0 +1,5 @@
(let ((a "2988348162058574136915891421498819466320163312926952423791023078876139")
(b "2351399303373464486466122544523690094744975233415544072992656881240319"))
;; "$ ^ $$ mod (10 ^ 40)" performs modular exponentiation.
;; "unpack(-5, x)_1" unpacks the integer from the modulo form.
(message "%s" (calc-eval "unpack(-5, $ ^ $$ mod (10 ^ 40))_1" nil a b)))

View file

@ -0,0 +1,16 @@
If Version<14 then Error "Need version >=14"
Function PowerTen(x as BigInteger) {
BigInteger a=10
method a, "intPower", x as a
=a
}
Print PowerTen(40)=10000000000000000000000000000000000000000u ' true
' 1234u is BigInteger literal value.
' so here a and b get type by the first value's type
a=2988348162058574136915891421498819466320163312926952423791023078876139u
b=2351399303373464486466122544523690094744975233415544072992656881240319u
profiler
method a, "modpow", b, PowerTen(40) as result
print timecount
Print result

View file

@ -0,0 +1,12 @@
main :: [sys_message]
main = [Stdout (show answer)]
where a = 2988348162058574136915891421498819466320163312926952423791023078876139
b = 2351399303373464486466122544523690094744975233415544072992656881240319
answer = modpow a b (10^40)
modpow :: num->num->num->num
modpow = mp 1
where mp r b 0 m = r
mp r b p m = mp r' ((b * b) mod m) (p div 2) m
where r' = (r * b) mod m, if p mod 2 = 1
r' = r, otherwise

View file

@ -0,0 +1,6 @@
require "bignum"
local a = bigint.new("2988348162058574136915891421498819466320163312926952423791023078876139")
local b = bigint.new("2351399303373464486466122544523690094744975233415544072992656881240319")
local m = bigint.ten ^ 40
print(bigint.modpow(a, b, m))

View file

@ -0,0 +1,18 @@
Function Invoke-ModuloExponentiation ([BigInt]$Base, [BigInt]$Exponent, $Modulo) {
$Result = 1
$Base = $Base % $Modulo
If ($Base -eq 0) {return 0}
While ($Exponent -gt 0) {
If (($Exponent -band 1) -eq 1) {$Result = ($Result * $Base) % $Modulo}
$Exponent = $Exponent -shr 1
$Base = ($Base * $Base) % $Modulo
}
return ($Result % $Modulo)
}
$a = [BigInt]::Parse('2988348162058574136915891421498819466320163312926952423791023078876139')
$b = [BigInt]::Parse('2351399303373464486466122544523690094744975233415544072992656881240319')
$m = [BigInt]::Pow(10, 40)
Invoke-ModuloExponentiation -Base $a -Exponent $b -Modulo $m

View file

@ -0,0 +1,8 @@
library(gmp)
m <- as.bigz(10)^40
a <- as.bigz("2988348162058574136915891421498819466320163312926952423791023078876139", mod=m)
b <- as.bigz("2351399303373464486466122544523690094744975233415544072992656881240319", mod=m)
last_40 <- `modulus<-`(a^b, NULL)
print(last_40, initLine=FALSE)

View file

@ -0,0 +1,31 @@
$ENTRY Go {
, '2988348162058574136915891421498819466320163312926952423791023078876139': e.A
, '2351399303373464486466122544523690094744975233415544072992656881240319': e.B
= <Prout <Symb <ModPow
(<Numb e.A>) (<Numb e.B>) (<Pow (10) (40)>)>>>;
};
ModPow {
(e.B) (e.P) (e.M) = <ModPow (e.B) (e.P) (e.M) (1)>;
(e.B) (0) (e.M) (e.R) = e.R;
(e.B) (e.P) (e.M) (e.R),
<Divmod (e.P) 2>: (e.P2) s.S,
<Mod (<Mul (e.B) e.B>) e.M>: e.B2,
s.S: {
0 = <ModPow (e.B2) (e.P2) (e.M) (e.R)>;
1, <Mod (<Mul (e.R) e.B>) e.M>: e.R2 =
<ModPow (e.B2) (e.P2) (e.M) (e.R2)>;
};
};
Pow {
(e.B) (e.P) = <Pow (e.B) (e.P) (1)>;
(e.B) (0) (e.R) = e.R;
(e.B) (e.P) (e.R),
<Mul (e.B) e.B>: e.B2,
<Divmod (e.P) 2>: (e.P2) s.S,
s.S: {
0 = <Pow (e.B2) (e.P2) (e.R)>;
1 = <Pow (e.B2) (e.P2) (<Mul (e.B) e.R>)>;
};
};

View file

@ -0,0 +1,19 @@
program ModPow;
a := 2988348162058574136915891421498819466320163312926952423791023078876139;
b := 2351399303373464486466122544523690094744975233415544072992656881240319;
print(modpow(a, b, 10**40));
proc modpow(b, e, m);
r := 1;
loop
init r := 1;
step e div:= 2;
until e = 0 do
if e mod 2 = 1 then
r := (b * r) mod m;
end if;
b := (b * b) mod m;
end;
return r;
end proc;
end program;