add challenge scripts
This commit is contained in:
33
js/03_are_you_still_doing_this_by_hand.js
Normal file
33
js/03_are_you_still_doing_this_by_hand.js
Normal file
@@ -0,0 +1,33 @@
|
||||
const p = 12345679943n;
|
||||
|
||||
function onClick() {
|
||||
if(n >= 30000n) {
|
||||
return;
|
||||
}
|
||||
n++;
|
||||
x = log(42n, 1n + (x+n) % (p-1n), p);
|
||||
}
|
||||
|
||||
function log(g, b, m) {
|
||||
const s = Math.ceil(Number(m)**.5);
|
||||
const r = new Map();
|
||||
let a = b % m;
|
||||
if(a == 1n) {
|
||||
return 0n;
|
||||
}
|
||||
for(let i = 0; i < s; i++) {
|
||||
r.set(a, i);
|
||||
a *= g;
|
||||
a %= m;
|
||||
}
|
||||
const gs = pow(g, BigInt(s), m);
|
||||
a = gs;
|
||||
for(let j = 1; j <= s; j++) {
|
||||
const i = r.get(a);
|
||||
if(i !== undefined) {
|
||||
return BigInt(j*s-i);
|
||||
}
|
||||
a *= gs;
|
||||
a %= m;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user