Skip to content

Instantly share code, notes, and snippets.

@theNestruo
Created January 16, 2021 15:51
Show Gist options
  • Save theNestruo/041e97024f3e2ef558f71e0eea531a52 to your computer and use it in GitHub Desktop.
Save theNestruo/041e97024f3e2ef558f71e0eea531a52 to your computer and use it in GitHub Desktop.
Stevedore password generator
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- new.css -->
<!-- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@exampledev/new.css@1/new.min.css"> -->
<!-- Water.css light -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/kognise/water.css@latest/dist/light.min.css">
<!-- Water.css dark -->
<!-- <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/kognise/water.css@latest/dist/dark.min.css"> -->
<title>Stevedore password generator</title>
</head>
<body>
<h1>Stevedore password generator</h1>
<form id="form">
<label for="chapters">Chapters unlocked</label>
<input type="text" name="chapters" min="2" max="5" minlength="1" maxlength="1" size="1" value="2" onchange="refresh(); return true;">
<br>
<label>Stars found</label>
<div>
<input id="star1" type="checkbox" name="star1" value="1" onclick="refresh(); return true;"/>
<label for="star1">lighthouse</label>
</div>
<div>
<input id="star2" type="checkbox" name="star2" value="1" onclick="refresh(); return true;"/>
<label for="star2">abandoned ship</label>
</div>
<div>
<input id="star3" type="checkbox" name="star3" value="1" onclick="refresh(); return true;"/>
<label for="star3">shipwreck island</label>
</div>
<div>
<input id="star4" type="checkbox" name="star4" value="1" onclick="refresh(); return true;"/>
<label for="star4">uncanny cave</label>
</div>
<div>
<input id="star5" type="checkbox" name="star5" value="1" onclick="refresh(); return true;"/>
<label for="star5">ancient temple ruins</label>
</div>
<br>
<label>Secret stage</label>
<div>
<input id="secret" type="checkbox" name="secret" value="1" onclick="refresh();return true;"/>
<label for="secret">secret stage</label>
</div>
<br>
<h2>Bytes:</h2>
<tt><input type="text" name="byte1" readonly size="2"/></tt>
<tt><input type="text" name="byte2" readonly size="2"/></tt>
<h2>Passwords:</h2>
<tt><input type="text" name="passwords" readonly size="130"/></tt>
</form>
<script>
var passwordSalt = 0x05;
var byte1 = 0x00;
var byte2 = 0x00;
function refresh() {
// Enforces coherent values
var chapters = parseInt(form.chapters.value);
if (chapters < 2) {
form.chapters.value = "2";
} else if (chapters > 5) {
form.chapters.value = "5";
}
switch (parseInt(form.chapters.value)) {
case 1: form.star1.checked = false; // (should never happen)
case 2: form.star2.checked = false;
case 3: form.star3.checked = false;
case 4: form.star4.checked = false;
form.star5.checked = false;
}
if (form.secret.checked) {
form.chapters.value = "5";
form.star1.checked = true;
form.star2.checked = true;
form.star3.checked = true;
form.star4.checked = true;
form.star5.checked = true;
}
// Parses input
var chapters = "000" + new Number(form.chapters.value).toString(2);
byte1 = parseInt(
(form.secret.checked ? "1" : "0")
+ "0"
+ chapters.substring(chapters.length - 3), 2);
byte2 = parseInt(
(form.star5.checked ? "1" : "0")
+ (form.star4.checked ? "1" : "0")
+ (form.star3.checked ? "1" : "0")
+ (form.star2.checked ? "1" : "0")
+ (form.star1.checked ? "1" : "0"), 2);
// Visual feedback
var byte1string = "00" + byte1.toString(16);
form.byte1.value = byte1string.substring(byte1string.length - 2);
var byte2string = "00" + byte2.toString(16);
form.byte2.value = byte2string.substring(byte2string.length - 2);
// Generates passwords
var passwords = [];
for (var seed = 0x00; seed <= 0x0f; seed++) {
passwords.push(encodePassword(seed));
}
form.passwords.value = passwords.join("\t");
}
function encodePassword(seed) {
// Seed
var digit0 = seed;
var checksum = digit0;
var password = digit0.toString(16);
// Byte 1, low nibble
var digit1 = ((byte1 ^ digit0) + passwordSalt) & 0x0f;
checksum += digit1;
password += digit1.toString(16);
// Byte 1, high nibble
var digit2 = (((byte1 >> 4) ^ digit1) + passwordSalt) & 0x0f;
checksum += digit2;
password += digit2.toString(16);
// Byte 2, low nibble
var digit3 = ((byte2 ^ digit2) + passwordSalt) & 0x0f;
checksum += digit3;
password += digit3.toString(16);
// Byte 2, high nibble
var digit4 = (((byte2 >> 4) ^ digit3) + passwordSalt) & 0x0f;
checksum += digit4;
password += digit4.toString(16);
// Checksum
var digit5 = ((checksum + passwordSalt) & 0x0f);
password += digit5.toString(16);
return password;
}
refresh();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment