68 lines
2.2 KiB
HTML
68 lines
2.2 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<title></title>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<script>
|
|
/*
|
|
* TODO:
|
|
* - rewrite functions to not use copied functions
|
|
* - add UI
|
|
* - add style
|
|
* - make everything not look like made at 0:41 on a phone
|
|
*/
|
|
function hex2Bytes(hexdata) {
|
|
// https://stackoverflow.com/a/39396866
|
|
|
|
var arr = hexdata.replace(/[^0-9a-fA-F]/g, '')
|
|
.match(/[0-9a-fA-F]{2}/g);
|
|
for(var i = 0; i<arr.length; i++) {
|
|
arr[i] = parseInt(arr[i], 16);
|
|
}
|
|
|
|
return arr;
|
|
}
|
|
|
|
function bytes2Base64(byteArray) {
|
|
// https://stackoverflow.com/a/11562550
|
|
return btoa(
|
|
String.fromCharCode.apply(
|
|
null, new Uint8Array(byteArray)
|
|
)
|
|
);
|
|
}
|
|
|
|
function base64ToArray(base64) {
|
|
// https://stackoverflow.com/a/21797381
|
|
var binaryString = atob(base64);
|
|
var bytes = new Uint8Array(binaryString.length);
|
|
for (var i = 0; i < binaryString.length; i++) {
|
|
bytes[i] = binaryString.charCodeAt(i);
|
|
}
|
|
return bytes;
|
|
}
|
|
|
|
function bytes2Hex(byteArray) {
|
|
// https://stackoverflow.com/a/34310051
|
|
return Array.from(byteArray, function(byte) {
|
|
return ('0' + (byte & 0xFF).toString(16)).slice(-2);
|
|
}).join('');
|
|
}
|
|
|
|
function infohash2Base64(infohash) {
|
|
return bytes2Base64(
|
|
hex2Bytes(infohash)
|
|
);
|
|
}
|
|
function base642Infohash(b64) {
|
|
return bytes2Hex(
|
|
base64ToArray(b64)
|
|
);
|
|
}
|
|
</script>
|
|
</head>
|
|
<body>
|
|
open your console
|
|
</body>
|
|
</html>
|