Last active
June 9, 2021 03:56
-
-
Save Efreak/0603eefa2cbbd42c4338552dcb3c0b97 to your computer and use it in GitHub Desktop.
copy of js url/base64 en/decoder by @stephenostermiller with some tweaks. To use, go to https://bots.efreakbnc.net/efreak/encode/ or rawgit: https://goo.gl/kakB1e
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Base64 and URL Encoding and Decoding</title> | |
<meta name="description" content="Encodes or decodes data in Base64 or URL encoding using client side JavaScript"> | |
<meta name="keywords" content="base64, base 64, urlencode, urldecode, hexencode, hex encode, hexdecode hex decode, javascript base64, javascript base 64, javascript urlencode, javascript urldecode, javascript hexencode, javascript hexdecode"> | |
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"> | |
<meta name=viewport content="width=device-width, initial-scale=1"> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/1.7.1/clipboard.js"></script> | |
<style> | |
input[type="button"],input[type="reset"]{ | |
text-align:center; | |
width: 100%; | |
height: 100%; | |
} | |
td { | |
width: 30%; | |
height: 3em; | |
} | |
table { | |
width:100%; | |
max-width: 500px; | |
} | |
</style> | |
<script> | |
// stolen from https://stackoverflow.com/a/21648161 - if you want to use this code, you get to deal with attribution and crap. I don't wanna. | |
// I probably should have kept @stephenostermiller's code, but I'm lazy. I mostly wanted to fix urlde/encode to fail on bad input. | |
String.prototype.hexEncode = function(){ | |
var hex, i; | |
var result = ""; | |
for (i=0; i<this.length; i++) { | |
hex = this.charCodeAt(i).toString(16); | |
result += ("000"+hex).slice(-4); | |
} | |
return result | |
} | |
String.prototype.hexDecode = function(){ | |
var j; | |
var hexes = this.match(/.{1,4}/g) || []; | |
var back = ""; | |
for(j = 0; j<hexes.length; j++) { | |
back += String.fromCharCode(parseInt(hexes[j], 16)); | |
} | |
return back; | |
} | |
document.addEventListener("DOMContentLoaded", function(event) { | |
new Clipboard('.btn'); | |
}); | |
</script> | |
</head> | |
<body> | |
<form name=code onsubmit="return false()"> | |
<textarea rows=25 name=text style='width:100%;height:75%;' placeholder='Enter text to encode or decode here.' id="box"></textarea> | |
<table> | |
<tr><td align=center> | |
<input value="Encode" type=button onclick="document.code.text.value=encodeURIComponent(btoa(document.code.text.value));"> | |
</td><td align=center> | |
Url(Base64) | |
</td><td align=center> | |
<input value="Decode" type=button onclick="document.code.text.value=atob(decodeURIComponent(document.code.text.value));"> | |
<tr><td align=center> | |
<input value="Encode" type=button onclick="document.code.text.value=encodeURIComponent(document.code.text.value);"> | |
</td><td align=center> | |
URL | |
</td><td align=center> | |
<input value="Decode" type=button onclick="document.code.text.value=decodeURIComponent(document.code.text.value);"> | |
</td></tr> | |
<tr><td align=center> | |
<input value="Encode" type=button onclick="document.code.text.value=btoa(document.code.text.value);"> | |
</td><td align=center> | |
Base 64 | |
</td><td align=center> | |
<input value="Decode" type=button onclick="document.code.text.value=atob(document.code.text.value);"> | |
</td></tr> | |
<tr><td align=center> | |
<input value="Encode" type=button onclick="document.code.text.value=document.code.text.value.hexEncode();"> | |
</td><td align=center> | |
Hex | |
</td><td align=center> | |
<input value="Decode" type=button onclick="document.code.text.value=document.code.text.value.hexDecode();"> | |
</td></tr> | |
<tr><td align=center> | |
<input type="reset" value="Clear"> | |
</td><td align=center> | |
<input type="button" value="Cut" class="btn" data-clipboard-target="#box" data-clipboard-action="cut"> | |
</td><td align=center> | |
<input type="button" value="Copy" class="btn" data-clipboard-target="#box" data-clipboard-action="copy"> | |
</td></tr> | |
</table> | |
</form> | |
<hr> | |
Base64 encode/decode was ported from a <a href="http://ostermiller.org/utils/Base64.html">Java Base64 encoder/decoder</a>.<br> | |
Base64 encode/decode was ported to <a href="http://ostermiller.org/base64_actionscript.html">Macromedia Actionscript</a>.<br> | |
<h3>License</h3> | |
<p>This program is free software; you can redistribute it and/or modify it | |
under the terms of the GNU General Public License as published by the Free | |
Software Foundation; either version 2 of the License, or (at your option) | |
any later version.</p> | |
<p>This program is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | |
or FITNESS FOR A PARTICULAR PURPOSE. See the | |
<a href="http://www.gnu.org/copyleft/gpl.html">GNU | |
General Public License</a> for more details.</p> | |
<p><a href="http://ostermiller.org/calc/">More converters, calculators, and other JavaScript goodies</a>. <a href="http://ostermiller.org/">ostermiller.org</a> (<a href="http://ostermiller.org/siteindex.html">site index</a>)</p> | |
<p>Copyright <a href="http://ostermiller.org/contact.pl?regarding=JavaScript+Encoding" class=mail>Stephen Ostermiller</a> 2003-2014</p> | |
<div><p>Modified by Efreak. All scripting replaced because ostermiller's base64 splits the output into multiple lines and doesn't fail on bad input, and the hex/url functions don't support unicode. Base64 and url are now js builtins and hex is from <a href="https://stackoverflow.com/a/21648161">SO</a>. Added Url-encoded Base64. Modified footer. Tweaked button styles for mobile use.</p></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment