Skip to content

Instantly share code, notes, and snippets.

@gjbianco
Created February 9, 2024 01:24
Show Gist options
  • Save gjbianco/07b398c47661af7c86b1a2d9c78a9d2b to your computer and use it in GitHub Desktop.
Save gjbianco/07b398c47661af7c86b1a2d9c78a9d2b to your computer and use it in GitHub Desktop.
<!doctype html>
<html>
<head>
<title>beef converter</title>
<meta name="viewport" content="width=device-width" />
</head>
<body>
<h1>beef converter</h1>
<p>"translates" phrase to hexadecimal (invalid letters removed)</p>
<input type="text" id="phrase" placeholder="Input a phrase" />
<br />
<code id="output"></code>
<script>
(() => {
const phraseEl = document.querySelector("#phrase");
const outputEl = document.querySelector("#output");
const offset = " ".charCodeAt(0);
const charMap =
" ---------------0123456789-------ABCDEF--1--1--0---57-------";
const processPhrase = (phrase) =>
phrase
.toUpperCase()
.split("")
.map((i) => charMap[i.charCodeAt(0) - offset])
.join("")
.replaceAll("-", "");
phraseEl.addEventListener("input", () => {
outputEl.innerHTML = `0x${processPhrase(phraseEl.value)}`;
});
phraseEl.dispatchEvent(new Event("input")); // run on page (re)load
})();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment