Skip to content

Instantly share code, notes, and snippets.

@Efreak Efreak/index.html
Last active Aug 17, 2017

What would you like to do?
copy of js url/base64 en/decoder by @stephenostermiller with some tweaks. To use, go to or rawgit:
<!DOCTYPE html>
<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=""></script>
width: 100%;
height: 100%;
td {
width: 30%;
height: 3em;
table {
max-width: 500px;
// stolen from - 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');
<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>
<tr><td align=center>
<input value="Encode" type=button onclick="document.code.text.value=encodeURIComponent(btoa(document.code.text.value));">
</td><td align=center>
</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>
</td><td align=center>
<input value="Decode" type=button onclick="document.code.text.value=decodeURIComponent(document.code.text.value);">
<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);">
<tr><td align=center>
<input value="Encode" type=button onclick="document.code.text.value=document.code.text.value.hexEncode();">
</td><td align=center>
</td><td align=center>
<input value="Decode" type=button onclick="document.code.text.value=document.code.text.value.hexDecode();">
<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">
Base64 encode/decode was ported from a <a href="">Java Base64 encoder/decoder</a>.<br>
Base64 encode/decode was ported to <a href="">Macromedia Actionscript</a>.<br>
<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
<a href="">GNU
General Public License</a> for more details.</p>
<p><a href="">More converters, calculators, and other JavaScript goodies</a>. <a href=""></a> (<a href="">site index</a>)</p>
<p>Copyright <a href="" 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="">SO</a>. Added Url-encoded Base64. Modified footer. Tweaked button styles for mobile use.</p></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.