Compare commits
No commits in common. "pages" and "master" have entirely different histories.
2 changed files with 66 additions and 103 deletions
12
README.md
12
README.md
|
@ -1,12 +0,0 @@
|
||||||
# infohash ↔ base64 tool
|
|
||||||
|
|
||||||
You can check the tool at
|
|
||||||
<https://magmaus3.codeberg.page/infohash2base64/> (requires javascript)
|
|
||||||
|
|
||||||
This tool was made to work with
|
|
||||||
[an suggestion posted by @toxictenement@lemmy.dbzer0.com](https://lemmy.dbzer0.com/post/1009713)
|
|
||||||
by [magmaus3](https://magmaus3.eu.org).
|
|
||||||
|
|
||||||
You can check the source code by downloading the page
|
|
||||||
(everything is stored in a single html file),
|
|
||||||
by going to your browser's devtools or on [Codeberg](https://codeberg.org/magmaus3/infohash2base64).
|
|
157
index.html
157
index.html
|
@ -1,55 +1,74 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<title>infohash ↔ base64</title>
|
<title></title>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<script>
|
<script>
|
||||||
// @license http://www.wtfpl.net/txt/copying/ WTFPL
|
/*
|
||||||
function infohashToBase64(infohash) {
|
* TODO:
|
||||||
// Converts an hex infohash into base64.
|
* - [ ] rewrite functions to not use copied functions
|
||||||
|
* - [x] add UI
|
||||||
// Convert hex into an byte array
|
* - [x] add style
|
||||||
let byteArray = infohash.replace(/[^0-9a-fA-F]/g, '')
|
* - [ ] make everything not look like made at 0:41 on a phone
|
||||||
|
*/
|
||||||
|
function hexToBytes(hexdata) {
|
||||||
|
// https://stackoverflow.com/a/39396866
|
||||||
|
var arr = hexdata.replace(/[^0-9a-fA-F]/g, '')
|
||||||
.match(/[0-9a-fA-F]{2}/g);
|
.match(/[0-9a-fA-F]{2}/g);
|
||||||
for(var i = 0; i<byteArray.length; i++) {
|
for(var i = 0; i<arr.length; i++) {
|
||||||
byteArray[i] = parseInt(byteArray[i], 16);
|
arr[i] = parseInt(arr[i], 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert byteArray into base64
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
function bytesToBase64(byteArray) {
|
||||||
|
// https://stackoverflow.com/a/11562550
|
||||||
return btoa(
|
return btoa(
|
||||||
String.fromCharCode.apply(
|
String.fromCharCode.apply(
|
||||||
null, new Uint8Array(byteArray)
|
null, new Uint8Array(byteArray)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
function base64ToInfohash(b64) {
|
|
||||||
// Converts a base64 value into a infohash (in a hex form)
|
function base64ToArray(base64) {
|
||||||
|
// https://stackoverflow.com/a/21797381
|
||||||
// Convert base64 into an byteArray
|
var binaryString = atob(base64);
|
||||||
let binaryString = atob(b64);
|
var bytes = new Uint8Array(binaryString.length);
|
||||||
let byteArray = new Uint8Array(binaryString.length);
|
|
||||||
for (var i = 0; i < binaryString.length; i++) {
|
for (var i = 0; i < binaryString.length; i++) {
|
||||||
byteArray[i] = binaryString.charCodeAt(i);
|
bytes[i] = binaryString.charCodeAt(i);
|
||||||
}
|
}
|
||||||
// Convert byteArray into hex values
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
function bytesToHex(byteArray) {
|
||||||
|
// https://stackoverflow.com/a/34310051
|
||||||
return Array.from(byteArray, function(byte) {
|
return Array.from(byteArray, function(byte) {
|
||||||
return ('0' + (byte & 0xFF).toString(16)).slice(-2);
|
return ('0' + (byte & 0xFF).toString(16)).slice(-2);
|
||||||
}).join('');
|
}).join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function infohashToBase64(infohash) {
|
||||||
|
return bytesToBase64(
|
||||||
|
hexToBytes(infohash)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
function base64ToInfohash(b64) {
|
||||||
|
return bytesToHex(
|
||||||
|
base64ToArray(b64)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Everything for the UI itself
|
// Everything for the UI itself
|
||||||
|
|
||||||
// Holds the state of tabs.
|
// Holds the state of tabs.
|
||||||
// Intended values are "encode", "decode" and "about"
|
// Intended values are "encode" and "decode"
|
||||||
let tabOpen = "encode"
|
let tabOpen = "encode"
|
||||||
|
|
||||||
function switchTab(name) {
|
function switchTab(name) {
|
||||||
// Switches the tab
|
// Switches the tab
|
||||||
// only "encode","decode" and "about" values are supported
|
// only "encode","decode" and "about" values are supported
|
||||||
let url = new URL(window.location)
|
|
||||||
url.searchParams.set("tab", name)
|
|
||||||
window.history.replaceState(null, "", url.href)
|
|
||||||
if (name === "encode") {
|
if (name === "encode") {
|
||||||
document.getElementById("encode").style.display = "block"
|
document.getElementById("encode").style.display = "block"
|
||||||
document.getElementById("decode").style.display = "none"
|
document.getElementById("decode").style.display = "none"
|
||||||
|
@ -87,40 +106,33 @@
|
||||||
document.getElementById("decodeResult").innerText = base64ToInfohash(urlParams.get("base64value"))
|
document.getElementById("decodeResult").innerText = base64ToInfohash(urlParams.get("base64value"))
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// @license-end
|
|
||||||
</script>
|
</script>
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
width: 100vw; height: 100vh;
|
|
||||||
margin: 0; padding: 0;
|
|
||||||
display: flex; flex-direction: column;
|
display: flex; flex-direction: column;
|
||||||
justify-content: center;
|
justify-content: center; text-align: center;
|
||||||
align-items: center;
|
|
||||||
background-color: #10101a;
|
background-color: #10101a;
|
||||||
color: white;
|
color: white;
|
||||||
font-family: monospace;
|
font-family: monospace;
|
||||||
}
|
}
|
||||||
main {
|
main {
|
||||||
background-color: #202025;
|
|
||||||
padding: 1em;
|
padding: 1em;
|
||||||
border: 1px solid white;
|
border: 1px solid white;
|
||||||
border-radius: 1em;
|
width: 50%; border-radius: 1em;
|
||||||
box-shadow: 0px 5px 15px black, 0px 1px 15px black inset;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
input {
|
input {
|
||||||
color: white;
|
color: white;
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
border: 1px solid white;
|
border: 1px solid #50505a;
|
||||||
}
|
}
|
||||||
label {
|
label {
|
||||||
margin-right: 0.5rem;
|
margin-right: 0.5rem;
|
||||||
}
|
}
|
||||||
.tab {
|
.tab {
|
||||||
|
display: none; /* Default value to keep tabs hidden when JS is not available */
|
||||||
border: 1px solid white;
|
border: 1px solid white;
|
||||||
padding: 1em;
|
padding: 0.5em;
|
||||||
border-radius: 0em 0em 1em 1em;
|
border-radius: 0em 1em 1em 1em;
|
||||||
box-shadow: 0px 5px 15px black, 0px 1px 15px black inset;
|
|
||||||
}
|
}
|
||||||
.result:empty { display: none;}
|
.result:empty { display: none;}
|
||||||
.result {
|
.result {
|
||||||
|
@ -130,52 +142,36 @@
|
||||||
border: 1px solid gray;
|
border: 1px solid gray;
|
||||||
border-radius: 1em;
|
border-radius: 1em;
|
||||||
}
|
}
|
||||||
.tab, .tabBar {
|
.tabBar {
|
||||||
display: none; /* Default value to keep tabs hidden when JS is not available */
|
display: none; /* Default value to keep tabs hidden when JS is not available */
|
||||||
|
border-collapse: collapse;
|
||||||
}
|
}
|
||||||
.button {
|
.button {
|
||||||
flex: 1;
|
|
||||||
text-align: center;
|
|
||||||
padding: 0.5em;
|
padding: 0.5em;
|
||||||
border: 1px solid white;
|
border: 1px solid white;
|
||||||
border-bottom: none;
|
border-bottom: none;
|
||||||
transition: box-shadow 200ms ease;
|
transition: box-shadow 200ms ease;
|
||||||
}
|
}
|
||||||
.leftButton {
|
|
||||||
border-radius: 1em 0em 0em 0em;
|
|
||||||
}
|
|
||||||
.rightButton {
|
|
||||||
border-radius: 0em 1em 0em 0em;
|
|
||||||
}
|
|
||||||
.button:hover {
|
.button:hover {
|
||||||
box-shadow: 0px 5px 25px black;
|
box-shadow: 1px 5px 15px black;
|
||||||
}
|
}
|
||||||
.button:active {
|
.button:active {
|
||||||
background-color: rgba(255,255,255, 0.2);
|
background-color: rgba(255,255,255, 0.2);
|
||||||
}
|
}
|
||||||
a { color: cyan; text-decoration: none;}
|
a { color: cyan; text-decoration: none;}
|
||||||
ul > li {
|
|
||||||
margin-bottom: 1em;
|
|
||||||
}
|
|
||||||
#about, .noscript {
|
|
||||||
display: block;
|
|
||||||
max-width: 40rem;
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<main>
|
<main>
|
||||||
<h1>infohash ↔ base64</h1>
|
<h1>infohash ↔ base64</h1>
|
||||||
<noscript>
|
<noscript>
|
||||||
<div class="noscript">
|
This tool requires JavaScript to function.
|
||||||
<p>This tool requires JavaScript to function.</p>
|
You can use DevTools in your browser to look at the code (it's intended to be easily readable).
|
||||||
<p>You can use DevTools in your browser to look at the code (it's intended to be easily readable).</p>
|
|
||||||
</div>
|
|
||||||
</noscript>
|
</noscript>
|
||||||
<div class="tabBar">
|
<div class="tabBar">
|
||||||
<div onclick="switchTab('encode')" class="button leftButton">Encode</div>
|
<div onclick="switchTab('encode')" class="button">Encode</div>
|
||||||
<div onclick="switchTab('decode')" class="button">Decode</div>
|
<div onclick="switchTab('decode')" class="button">Decode</div>
|
||||||
<div onclick="switchTab('about')" class="button rightButton">About</div>
|
<div onclick="switchTab('about')" class="button">About</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="tab" id="encode">
|
<div class="tab" id="encode">
|
||||||
<form>
|
<form>
|
||||||
|
@ -196,39 +192,18 @@
|
||||||
<div class="result" id="decodeResult"></div>
|
<div class="result" id="decodeResult"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="tab" id="about">
|
<div class="tab" id="about">
|
||||||
<h2>About</h2>
|
<form>
|
||||||
<p>
|
<h2>About</h2>
|
||||||
This tool was made to work with <a href="https://lemmy.dbzer0.com/post/1009713">an suggestion posted by @toxictenement@lemmy.dbzer0.com</a>
|
<p>
|
||||||
by <a href="https://magmaus3.eu.org">magmaus3</a>.
|
This tool was made to work with <a href="https://lemmy.dbzer0.com/post/1009713">an suggestion posted by @toxictenement@lemmy.dbzer0.com</a>
|
||||||
</p>
|
by <a href="https://magmaus3.eu.org">magmaus3</a>.
|
||||||
<p>
|
</p>
|
||||||
You can check the source code by downloading the page (everything is stored in a single html file),
|
<p>
|
||||||
by going to your browser's devtools or on <a href="https://codeberg.org/magmaus3/infohash2base64">Codeberg</a>.
|
You can check the source code by downloading the page (everything is stored in a single html file),
|
||||||
</p>
|
by going to your browser's devtools or on codeberg.
|
||||||
<h3>License</h3>
|
</p>
|
||||||
<p>Copyright © 2023 magmaus3 <magmaus3@disroot.org></p>
|
</form>
|
||||||
<p>This work is free. You can redistribute it and/or modify it under the
|
<div class="result" id="decodeResult"></div>
|
||||||
terms of the Do What The Fuck You Want To Public License, Version 2,
|
|
||||||
as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.</p>
|
|
||||||
<h3>How to copy</h3>
|
|
||||||
<ul>
|
|
||||||
<li>
|
|
||||||
On Firefox/Chromium:
|
|
||||||
<ol>
|
|
||||||
<li>Right-click on the page</li>
|
|
||||||
<li>Select <i>Save Page as...</i> or <i>Save as...</i> (or simillar option)</li>
|
|
||||||
<li>Choose file type as <i>HTML Only</i></li>
|
|
||||||
<li>Profit!</li>
|
|
||||||
</ol>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
Using git:
|
|
||||||
<ol>
|
|
||||||
<li><code>git clone https://codeberg.org/magmaus3/infohash2base64</code></li>
|
|
||||||
<li>Profit!</li>
|
|
||||||
</ol>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
</body>
|
</body>
|
||||||
|
|
Loading…
Reference in a new issue