add better styling and rename pow_client => nojscap

This commit is contained in:
libroot 2025-08-06 18:33:53 +00:00
parent 0a9434be1b
commit 40ee2ea272
3 changed files with 39 additions and 27 deletions

View file

@ -84,9 +84,9 @@ func postHandler(w http.ResponseWriter, r *http.Request) {
hash := sha256.Sum256([]byte(challenge + nonce))
if checkDifficulty(hash[:], difficulty) {
fmt.Fprint(w, "<p>Success! Valid nonce.</p><a href='/'>Try again</a>")
fmt.Fprint(w, "<div style='text-align:center;'><h1>Success! Valid nonce.</h1><a href='/'>Try again</a></div>")
} else {
fmt.Fprint(w, "<p>Invalid nonce.</p><a href='/'>Try again</a>")
fmt.Fprint(w, "<div style='text-align:center;'><p>Invalid nonce.</p><a href='/'>Try again</a></div>")
}
}
@ -104,6 +104,10 @@ var tmpl = template.Must(template.New("page").Parse(`
background: #cacaca;
color: black;
}
::selection {
background: #a60000;
color: white;
}
code {
white-space: break-spaces;
background: black;
@ -143,15 +147,15 @@ var tmpl = template.Must(template.New("page").Parse(`
<p><a href="https://git.libroot.org/libroot/NOJSCAP/" target="_blank">https://git.libroot.org/libroot/NOJSCAP/</a></p>
<p>If you don't already have the <b><em>NOJSCAP</em></b> client:</p>
<code>$ git clone https://git.libroot.org/libroot/NOJSCAP/$ cd NOJSCAP/client/</code>
<p><code>$ python3 pow_client.py {{.Challenge}} {{.Difficulty}}</code></p>
<p><code>$ python3 nojscap.py {{.Challenge}} {{.Difficulty}}</code></p>
<p><strong>Go:</strong></p>
<p><code>$ go run pow_client.go {{.Challenge}} {{.Difficulty}}</code></p>
<p><code>$ go run nojscap.go {{.Challenge}} {{.Difficulty}}</code></p>
<p><strong>Node.js:</strong></p>
<p><code>$ node pow_client.js {{.Challenge}} {{.Difficulty}}</code></p>
<p><code>$ node nojscap.js {{.Challenge}} {{.Difficulty}}</code></p>
<p><strong>Rust:</strong></p>
<p><code>$ rustc pow_client.rs -o pow_client_rs$ pow_client_rs {{.Challenge}} {{.Difficulty}}</code></p>
<p><code>$ rustc nojscap.rs -o nojscap_rs$ nojscap_rs {{.Challenge}} {{.Difficulty}}</code></p>
<p><strong>C:</strong></p>
<p><code>$ gcc -O2 -o pow_client pow_client.c -lssl -lcrypto$ ./pow_client {{.Challenge}} {{.Difficulty}}</code></p>
<p><code>$ gcc -O2 -o nojscap nojscap.c -lssl -lcrypto$ ./nojscap {{.Challenge}} {{.Difficulty}}</code></p>
<form method="POST">
<input type="hidden" name="challenge" value="{{.Challenge}}">
<label class="h">Nonce: <input name="nonce"></label>

View file

@ -39,6 +39,10 @@ def index():
background: #cacaca;
color: black;
}}
::selection {{
background: #a60000;
color: white;
}}
code {{
white-space: break-spaces;
background: black;
@ -81,26 +85,26 @@ def index():
$ cd NOJSCAP/client/</code>
<p><br></p>
<p>
<code>$ python3 pow_client.py {challenge} {DIFFICULTY}</code>
<code>$ python3 nojscap.py {challenge} {DIFFICULTY}</code>
</p>
<p>
<strong>Go:</strong>
</p>
<p>
<code>$ go run pow_client.go {challenge} {DIFFICULTY}</code>
<code>$ go run nojscap.go {challenge} {DIFFICULTY}</code>
</p>
<p>
<strong>Node.js:</strong>
</p>
<p>
<code>$ node pow_client.js {challenge} {DIFFICULTY}</code>
<code>$ node nojscap.js {challenge} {DIFFICULTY}</code>
</p>
<p>
<strong>Rust:</strong>
</p>
<p>
<code>$ rustc pow_client.rs -o pow_client_rs
$ pow_client_rs {challenge} {DIFFICULTY}
<code>$ rustc nojscap.rs -o nojscap_rs
$ nojscap_rs {challenge} {DIFFICULTY}
</code>
<small>Requires Rust and sha2 crate if using the Cargo version.</small>
</p>
@ -108,8 +112,8 @@ $ pow_client_rs {challenge} {DIFFICULTY}
<strong>C:</strong>
</p>
<p>
<code>$ gcc -O2 -o pow_client pow_client.c -lssl -lcrypto
$ ./pow_client {challenge} {DIFFICULTY}
<code>$ gcc -O2 -o nojscap nojscap.c -lssl -lcrypto
$ ./nojscap {challenge} {DIFFICULTY}
</code>
<small>Required: GCC or any C compiler. OpenSSL development libraries (libssl-dev on Debian-based systems)</small>
</p>
@ -130,7 +134,7 @@ def submit():
challenge_store.pop(challenge)
combined = (challenge + nonce).encode()
h = hashlib.sha256(combined).digest()
return "<p>Success! Valid nonce.</p><a href='/'>Try again</a>" if check_difficulty(h, DIFFICULTY) else "<p>Invalid nonce.</p><a href='/'>Try again</a>"
return "<div style='text-align:center;'><h1>Success! Valid nonce.</h1><a href='/'>Try again</a></div>" if check_difficulty(h, DIFFICULTY) else "<div style='text-align:center;'><h1>Invalid nonce.</h1><a href='/'>Try again</a></div>"
app.run(port=3000)

View file

@ -32,7 +32,7 @@ function checkDifficulty(hash: Buffer, bits: number): boolean {
return true;
}
app.get('/', (_req: Request, res: Response) => {
app.get('/NOJSCAP-demo', (_req: Request, res: Response) => {
const challenge = generateChallenge();
challengeStore.set(challenge, Date.now());
res.send(`
@ -49,6 +49,10 @@ app.get('/', (_req: Request, res: Response) => {
background: #cacaca;
color: black;
}
::selection {
background: #a60000;
color: white;
}
code {
white-space: break-spaces;
background: black;
@ -94,36 +98,36 @@ $ cd NOJSCAP/client/</code>
<strong>Python:</strong>
</p>
<p>
<input type="text" value="python3 pow_client.py ${challenge} ${DIFFICULTY}">
<input type="text" value="python3 nojscap.py ${challenge} ${DIFFICULTY}">
</p>
<p>
<strong>Go:</strong>
</p>
<p>
<input type="text" value="go run pow_client.go ${challenge} ${DIFFICULTY}">
<input type="text" value="go run nojscap.go ${challenge} ${DIFFICULTY}">
</p>
<p>
<strong>Node.js:</strong>
</p>
<p>
<input type="text" value="node pow_client.js ${challenge} ${DIFFICULTY}">
<input type="text" value="node nojscap.js ${challenge} ${DIFFICULTY}">
</p>
<p>
<strong>Rust:</strong>
</p>
<p>
<details><summary>Show compilation commands</summary><code>$ rustc pow_client.rs -o pow_client_rs</code>
<details><summary>Show compilation commands</summary><code>$ rustc nojscap.rs -o nojscap_rs</code>
<small>Requires Rust and sha2 crate if using the Cargo version.</small><br></details>
<input type="text" value="pow_client_rs ${challenge} ${DIFFICULTY}">
<input type="text" value="nojscap_rs ${challenge} ${DIFFICULTY}">
</p>
<p>
<strong>C:</strong>
</p>
<p>
<details><summary>Show compilation commands</summary><code>$ gcc -O2 -o pow_client pow_client.c -lssl -lcrypto</code>
<details><summary>Show compilation commands</summary><code>$ gcc -O2 -o nojscap nojscap.c -lssl -lcrypto</code>
<small>Required: GCC or any C compiler. OpenSSL development libraries (libssl-dev on Debian-based systems)</small><br></details>
<input type="text" value="./pow_client ${challenge} ${DIFFICULTY}">
<input type="text" value="./nojscap ${challenge} ${DIFFICULTY}">
</p>
<form method="POST">
@ -136,7 +140,7 @@ $ cd NOJSCAP/client/</code>
`);
});
app.post('/', (req: Request, res: Response) => {
app.post('/NOJSCAP-demo', (req: Request, res: Response) => {
const { challenge, nonce } = req.body as { challenge?: string; nonce?: string };
if (!challenge || !nonce || !challengeStore.has(challenge)) {
return res.send('Invalid input.');
@ -145,10 +149,10 @@ app.post('/', (req: Request, res: Response) => {
challengeStore.delete(challenge);
const hash = hashSha256(challenge + nonce);
if (checkDifficulty(hash, DIFFICULTY)) {
res.send('<p>Success! Valid nonce.</p><a href="/">Try again</a>');
res.send('<div style="text-align:center;"><h1>Success! Valid nonce.</h1><a href="?">Try again</a></div>');
} else {
res.send('<p>Invalid nonce.</p><a href="/">Try again</a>');
res.send('<div style="text-align:center;"><h1>Invalid nonce.</h1><a href="?">Try again</a></div>');
}
});
app.listen(3000, () => console.log('Server running at http://localhost:3000'));
app.listen(3000, () => console.log('/NOJSCAP-demo server running at http://localhost:3000'));