add challenge scripts

This commit is contained in:
2025-09-12 11:19:05 +02:00
parent 81fea4865e
commit 7f33c43169
10 changed files with 321 additions and 0 deletions

7
js/01_welcome.js Normal file
View File

@@ -0,0 +1,7 @@
function onClick() {
if(n >= 10000n) {
return;
}
n++;
x = n % 7n;
}

View File

@@ -0,0 +1,21 @@
const m = 14004392365098131090160062970945115111185775413941111064876648140973294115502980816410773368597517292734034227298996122159833675150497554142801209096513652073059992938078366061434391648276904643753267405058183481162693381822800709938988762923n;
let h;
async function prepare() {
if(n == 10000n) {
h = await sha256(name);
}
}
function onClick() {
if(n >= 20000n) {
return;
}
if(n == 10000n) {
x += h;
}
n++;
for(let i = 0; i < 100; i++) {
x = pow(x, 65537n, m);
}
}

View 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;
}
}

View File

@@ -0,0 +1,10 @@
function onClick() {
if(n >= 10n**8n) {
return;
}
n++;
for(let i = 0; i < 10000; i++) {
x += 41n;
x ^= 42n;
}
}

11
js/05_what_the_bf.js Normal file
View File

@@ -0,0 +1,11 @@
const f = ((ο)=>((o)=>o(((o(((ο*o([!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+[+[]]+[!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+[+[]]+[!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+[+[]]+[!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+[+[]]+[!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+[+[]]+[!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+[+!+[]]))+[])[(![]+[])[!+[]+!+[]+!+[]]+(![]+[])[!+[]+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+([][(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]](-[+!+[]]+[!+[]+!+[]]))*o([+!+[]]+[+[]]+[+[]]+[+[]]+[+[]]+[+[]]+[+[]]+[+[]]+[+[]]+[+[]]+[+[]]+[+[]]+[+[]]-([+!+[]]+[+!+[]]))+o([+!+[]]+[+[]]+[+[]]+[+[]]+[+[]]+[+[]]+[+[]]+[+[]]+[+[]]+[+[]]+[+[]]+[+[]]+[+[]]-+!+[]))+[])[(![]+[])[!+[]+!+[]+!+[]]+(![]+[])[!+[]+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+([][(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]](+[],-[+!+[]]+[!+[]+!+[]])))(BigInt));
function onClick() {
if(n >= 10n**12n) {
return;
}
n++;
for(let i = 0; i < 100; i++) {
x = f(x);
}
}

View File

@@ -0,0 +1,14 @@
const m = 14004392365098131090160062970945115111185775413941111064876648140973294115502980816410773368597517292734034227298996122159833675150497554142801209096513652073059992938078366061434391648276904643753267405058183481162693381822800709938988762923n;
function onClick() {
if(n >= 10n**16n) {
return;
}
n++;
const a = pow(n, 65537n, m);
if(a % 1466928606874115117499939299261n == 49119078231137394008451554322n) {
x += x;
}
x += a;
x %= m;
}

View File

@@ -0,0 +1,15 @@
let f;
async function prepare() {
const get = fetch('07_weird_assembly_machine.wasm');
const obj = await WebAssembly.instantiateStreaming(get);
f = obj.instance.exports.f;
}
function onClick() {
if(n >= 10n**18n) {
return;
}
n++;
x = BigInt.asUintN(64, f(x, n));
}

Binary file not shown.

View File

@@ -0,0 +1,59 @@
const m = [
1434008120931012805118743381511953470053626771934922366720474361817092344508461315782084314493561729943207476618986862630642339876124303277669871276872966561372584096756184146218943438497504108129008248947186295903702650936563195517405177267n,
2279983661166952569412337967792106681853682761140508555222469060830820310854240357968620360297575902950280777825697828457195462861233847516393870602678279643129330544204145040751369969379909048248974150190225328726111083312867874886821021103n,
2403618920217682814630057320815015451780244245370783386150600183266752801851444036459202928614238339117073052233115617730895326577436837775969446809467396763885076993639257102975158794586432834588823770619549927566204909745661463923650207527n,
2211546667714470043261801539278553165605603776798179390251801872528197206642136833266100994696226928008915728096531663182964211466279822828133246114741263620898853542511659005977098742505685248155022513107926722707345462354618444663133511693n,
5010303295979029720953954773805463848657367496896667256925387074631207128976445011411567186128665343367664557600927865746013809617850756247038364977849593298370638415538050617717579812040063809050466079467593876757904967054587247239775981173n,
3643715306191323974849750185026376664803002052031009917919146298629124228139669830885418351414368670190933608901908463160313491829979902265661425377942098542786579385118688686530379428281500432090209857512031899193610942009997666480141622931n,
4241834355731759088612098900889150480486830356437779625635656124158632786788891567665015370346587717023382467402755844902551269466840016945251052520143748217810459016980596787260934741544681783243577436529017346762263051435128563504848147047n,
2523900322512898153092283527555686191954886966926984043710614987380057039954266050243558368595618000310491183390298731322739555708825633335455707335046252155477145429505231996976303780687577721717937956727462248609588253109048826912219512233n,
1171824891807552748899024459763353345756465570610286429518292854539955442689370561445213645478177496112486904608544314008088766463602198222556565269084818799872887643847609538261074418353385510616209919715913997563223016102524218731609073989n,
46143420546617745197213974992864349706110841054938173439888506485894731816049443533063388738883948066474775508317079165731544093393852672679526902040341664165103617856112836137307481490757786503309809660177211850194917302104601047445901953n,
752940078968697502678967384415617976772053933529596207932495368245135279916303315035371282640886295210962243111798224672106391175631921911566406669776741217206089188001565916873143077167066022880702036063882903129906642676129495022972131209n,
1520329335648026567766367275046307578542257991128853001791455552493665632232325588405913221176897049790060536801309884790312144713538875231774340342847186215385917144874277668809985499482994078141272859278475075285977463657736734963652987373n,
50017625495288818782435924507013834110031999034643307338382821405698791610778877531830614693405608386655072058895222505909833754916862533905752631274852366748935792253442598350951461591550736346237955863906449458952663228800927140320157667n,
38401610206931167080264498597398870802860254093725730772991011582569894725813373580324866968569176388369611982707097825344506655231925447764442769351345178318652542550409150557352343943618674608946011463309394821673565650165744273097849949n,
184608244646942021323366304782439538668746375277959348413634650687235587234614717772753935753287722857766192563391263109670280253185426161046298354787439672044497169888140233752555779424149969713422475505388807903963252621863734032956280519n,
351257593287654452522276916291373563742090233637383104641821340906564637280571336214002417682603763101501053115051814027840290224795605063148356403544846161606884919930269677277921998672949839936317112237896436966630449023178621753921263019n,
17776213033029898042736097216007742758258673720676143715791913350512342764629944960235747926785035898455679245982654344139524841812891998487061291841045102881105147645119091822393445581339563032411679270141022474438218196237858872902098301n,
1119968749281206669187118962426182039471518541839452651714133200569385292395928211155932154512551823867768143506831179697150725335729082336884390018097450391780455129434304717766108240883676474188676687895688014005390129134060293445952714131n,
2380359028703143565637146811469828781458088476878403649995644924026273963767396041207843943179863650694243979825010501084343724584937371440937331372027478732522369607122724766608383356158192256503987385487068417019456480384653228271517184073n,
936391425922485612330507260988001138454208806035318063315033628148710609664547188763477146808759892616317103092432173093713978381604382096301822456981993396860893433866194478210978043268587964153688806562028136539787248761208718402921714823n,
2391922140661526942794958081614866503484666510987906109575239558478076826463675970540222364377429236018134610321177838404492145979186686367103845387306040811399772932134010203596245485657848849575365830819533003431899529331962049972105422829n,
964374520562152761892099701871246383149820707812540579294812519029773619714236033304961754196611532652288982150226191973613367922123899620952613834335606606286016170579235167587934724407287026718339208674781371124584567946455593866472142439n,
661248789387918195968343456268415015655227429901485551376733649662534559008900836450733880455467249525009566343824739697592753526891306540092946639656510220832776564628364080959055214446202095345118415029995831071367289505624996230686042743n,
1495554819407996415862156847203243369888937825574835272994697401723776375381219545680004526750874917248129621701075619516487125846492717688083196840105055779039883420765261872964729328338142922514236283019345885773272705802789375709371531891n,
2050623645029219438127819922659780851370739111321093329697282080391534071710675160727304612357988694773734599338417354100409517400415116108045288729878347023871908849359856487326222636295170968226843328973460491743192554642495605580203827647n,
5300307462410213577667480837938258777512352583051978520467068441893175668391866168747583454129771867041290645051627565118578602725370687799533406736037648231124221590788082333656018605599589489800640114935804161182962684573894987008279375881n,
3704327655413180273494896105414341120264540967426618385392149993686601012341448146813701061680592497964083943234912731844161335477856719778925685202496984827468326099066276955751929212099287128630393090960611662156345752418189491108549779761n,
4293873523905537531247339274016468845613818921758414861106911431522285730431627111776083755372250902094439575944006556178967448926801694819806680902651676479412361255593771594300163105918014188734865473316383051363586442734877422424944476487n,
1589457356017416267968030208391225107392251829332800185708809994594071680629191862623870630995580949827174233852065931316179886989972734453310743029959684374385051032958116409820646011612627461794497048612013500205304829106740521813279065839n,
677060499756811014115027316973737658993937681267671378751091515074444191639222306675859985253758266662687011882335084637681850124628916282787941181661248429412152192230660554583653075199720096784977912362093898785710927643429800554309996621n,
4556683258594822402855414380362620295231673046713752880933967889771646856051745784462468117575177892006513392693685616569935833357648393898915677206732580748330214938398411668157941515847730087263301030154072458063812554524260405671629754999n,
1602074580348123931489241137005511885150980182400049992026659585131187985620536794154659820191316264063547338262596211651955802983450000900446591221580949545163434870046188079786417621515405352023176920247457687361358148356208096808525338397n,
2561993755606565068035375148802286812072711717323441363005149722023895797027723216764951149251447180880317275019544062589806987036712157902709291674934493635207098007981128987753281766285445399631018190456476459604899786219806829862034503919n,
1457054801380350736800076081677201400665406203824020727471775641174383980331187058211832905604880205627938232136048301389594977658775329490376467311636742994730009572046684919498881836580821362806591224089188354188782107744327550013385898679n,
63236406531205434317594389945524553066650347945711034187542626293222184231786980314347573971609802315464270916666042219689326463061892323637662557342398379414478296594450374661462435994098294952191568682470529143295022566680404002417824407n,
197584207289801721640320350702781512605131263686515431131918340568997783498811538104924263177220361290500812540231048642224996620094592927292942263102162109623392197130698355962984228640696217934383302653006588137949636000986800801778335657n,
107646974355805618130192750841008263946998235997036512644246089806483971253986128403392278299190598483359268422291624377225409658571257936659998943160556099228016404911568061972541462863973742808216138653302666989981023076627131009019648093n,
1339338638103691041488101095975795624888087363910833767941545495164307897693922886889431835980515628174298063795556722365483994582432076986194090322659335982083818451837412988740007497627907154682332316972997765904572884621671832534078952307n,
4434008847683596023521080910694307462609680232648893208331172489192536036999251664058651161016448705529504803145115341661351913895515662510503514243928030586139092055076376059786525834604160882940981043706619590945099008097035756330871176929n,
2861034394438211841574954026003099819138101239247590122220350015475642835378420417008259980687528330087930738069620032709655292858712710050922359392413494086067180601383341612168193292772028605966992134213209023470256124404157207490432001519n,
2192496740130688243467014868961425982524426805724142867736885035473886629020046845749143690992453345556925544037271383038390660805714030629830845497904446979103911346917405936472233104694103049940390437540539269358666128436739707024829933171n,
4729254672091433598483706976591610165407510022326154887172965802144851945337220063633854456109688411742113721031379206359782182729020553179365019549633309936476652959201812418790254033614677768930428905990768941807243900642422321011756634063n
];
function onClick() {
if(n >= 10n**20n) {
return;
}
n++;
const w = x % 42n;
let y = x / 42n;
for(let i = 0; i < 100; i++) {
y = pow(y, 65537n, m[w]);
}
x = 42n * y + w;
}
/* Lbh pna punatr gur pbybe bs lbhe anzr jvgubhg punatvat lbhe anzr. */

151
js/common_v=2.js Normal file
View File

@@ -0,0 +1,151 @@
/*
NOTE: this just contains user interface logic;
there is probably not much interesting stuff here
*/
let name, n, x, n_old, n_last;
async function init() {
const params = (new URL(document.URL)).searchParams;
if(params.has('name')) {
name = params.get('name');
} else {
/* missing name, redirect to start screen */
location.replace('.');
return;
}
/* people can do more than 2^53 button clicks, so we need big integers */
if(params.has('n') && params.has('x')) {
n = BigInt(params.get('n'));
x = BigInt(params.get('x'));
} else {
n = 0n;
x = 0n;
}
n_old = 0n;
n_last = -1n;
if(typeof prepare == 'function') {
await prepare();
}
const button = document.querySelector('button');
button.textContent = n;
button.addEventListener('click', onClick);
setInterval(() => {
if(n > n_last) {
/* to spare the browser, we do this at most 10 times per second */
const params = new URLSearchParams({name, n, x});
history.replaceState(null, '', '?' + params);
button.textContent = n;
n_last = n;
}
}, 100);
communicate();
}
document.addEventListener('DOMContentLoaded', init);
async function communicate() {
const error = document.querySelector('#error');
try {
/* only submit increased click counts, otherwise just fetch scores */
const path = 'server.php' + ((n_last > n_old) ? location.search : '');
const result = await fetch(path);
if(!result.ok) {
throw new Error(`${result.status} ${result.statusText}`);
}
if(n_last > n_old) {
n_old = n_last;
}
const json = await result.json();
if(json.flag && !location.pathname.endsWith('/' + json.flag)) {
/* advance to next level */
location.replace(json.flag + location.search);
return;
}
if(json.scores) {
displayScores(json.scores, json.time);
}
if(json.error) {
throw new Error(json.error);
}
const timeStr = new Date(json.time * 1000).toLocaleTimeString('de-DE');
error.textContent = `Zuletzt aktualisiert: ${timeStr}`;
} catch(e) {
console.warn(e);
error.textContent = e;
}
setTimeout(communicate, 1000);
}
function displayScores(scores, time) {
const table = document.querySelector('table');
while(table.rows.length > 1) {
table.deleteRow(-1);
}
scores.sort((a, b) => {
const n_a = BigInt(a.n);
const n_b = BigInt(b.n);
if(n_a > n_b) {
return -1;
}
if(n_a < n_b) {
return 1;
}
if(a.time < b.time) {
return -1;
}
if(a.time > b.time) {
return 1;
}
return 0;
});
scores.forEach((entry) => {
const row = table.insertRow();
const nameCell = row.insertCell();
/* protect against unicode bidi control characters */
const bdi = document.createElement('bdi');
bdi.textContent = entry.name;
nameCell.appendChild(bdi);
nameCell.title = entry.name;
const timeCell = row.insertCell();
const date = new Date(entry.time * 1000);
if(time - entry.time < 86400) {
timeCell.textContent = date.toLocaleTimeString('de-DE');
} else {
timeCell.textContent = date.toLocaleDateString('de-DE');
}
timeCell.title = date.toLocaleString('de-DE');
const nCell = row.insertCell();
nCell.textContent = entry.n;
nCell.title = entry.n;
});
}
/* compute SHA-256 digest represented as integer (big endian) */
async function sha256(str) {
const msg = new TextEncoder().encode(str);
const buffer = await crypto.subtle.digest('SHA-256', msg);
const bytes = new Uint8Array(buffer);
let val = 0n;
for(const b of bytes) {
val = (val << 8n) | BigInt(b);
}
return val;
}
/* compute a^k modulo m */
function pow(a, k, m) {
let b = 1n;
for(; k; k >>= 1n) {
if(k & 1n) {
b *= a;
b %= m;
}
a *= a;
a %= m;
}
return b;
}