Skip to content

Commit

Permalink
Add Quoted-Printable encoder/decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiasbynens committed May 4, 2014
1 parent 107c976 commit f93b9fe
Show file tree
Hide file tree
Showing 8 changed files with 375 additions and 30 deletions.
2 changes: 1 addition & 1 deletion bacon/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ <h2>Ciphertext: (<a href=#I%20shot%20the%20sheriff id=permalink>permalink</a>)</
<div><label><input name=alphabet type=radio checked> use the common 24-letter cipher alphabet <code>ABCDEFGHIKLMNOPQRSTUWXYZ</code></label></div>
<div><label><input name=alphabet type=radio> use the full alphabet of 26 letters <code>ABCDEFGHIJKLMNOPQRSTUVWXYZ</code></label></div>
<h2>About this tool</h2>
<p>This tool uses <a href=http://mths.be/bacon><i>bacon-cipher</i></a> to encode any string you enter in the ‘plaintext field, or to decode any Bacon-encoded ciphertext you enter in the other field.
<p>This tool uses <a href=http://mths.be/bacon><i>bacon-cipher</i></a> to encode any string you enter in the ‘plaintext field, or to decode any Bacon-encoded ciphertext you enter in the other field.
<p id=footer>Made by <a href=http://mathiasbynens.be/>@mathias</a><a href=https://github.com/mathiasbynens/mothereff.in/tree/master/bacon>fork this on GitHub!</a></p>
<script src=vendor/bacon.js></script>
<script src=eff.js></script>
58 changes: 29 additions & 29 deletions js-escapes/eff.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
(function(window, document, evil) {

var pre = document.getElementsByTagName('pre')[0],
code = document.getElementsByTagName('code')[0],
textarea = document.getElementsByTagName('textarea')[0],
inputs = document.getElementsByTagName('input'),
checkboxOnlyASCII = inputs[0],
checkboxES6 = inputs[1],
checkboxStringBody = inputs[2],
permalink = document.getElementById('permalink'),
// http://mathiasbynens.be/notes/localstorage-pattern
storage = (function() {
var uid = new Date,
storage,
result;
try {
(storage = window.localStorage).setItem(uid, uid);
result = storage.getItem(uid) == uid;
storage.removeItem(uid);
return result && storage;
} catch(e) {}
}()),
cache = {
'\n': '\\n',
'\"': '\\\"',
'\u2028': '\\u2028',
'\u2029': '\\u2029',
'\'': '\\\''
};
var pre = document.getElementsByTagName('pre')[0];
var code = document.getElementsByTagName('code')[0];
var textarea = document.getElementsByTagName('textarea')[0];
var inputs = document.getElementsByTagName('input');
var checkboxOnlyASCII = inputs[0];
var checkboxES6 = inputs[1];
var checkboxStringBody = inputs[2];
var permalink = document.getElementById('permalink');
// http://mathiasbynens.be/notes/localstorage-pattern
var storage = (function() {
var uid = new Date;
var storage;
var result;
try {
(storage = window.localStorage).setItem(uid, uid);
result = storage.getItem(uid) == uid;
storage.removeItem(uid);
return result && storage;
} catch(exception) {}
}());
var cache = {
'\n': '\\n',
'\"': '\\\"',
'\u2028': '\\u2028',
'\u2029': '\\u2029',
'\'': '\\\''
};

function encode(string) {
// URL-encode some more characters to avoid issues when using permalink URLs in Markdown
Expand Down Expand Up @@ -138,8 +138,8 @@
// Google Analytics
window._gaq = [['_setAccount', 'UA-6065217-60'], ['_trackPageview']];
(function(d, t) {
var g = d.createElement(t),
s = d.getElementsByTagName(t)[0];
var g = d.createElement(t);
var s = d.getElementsByTagName(t)[0];
g.src = '//www.google-analytics.com/ga.js';
s.parentNode.insertBefore(g, s);
}(document, 'script'));
5 changes: 5 additions & 0 deletions quoted-printable/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# [`Quoted-Printable` encoder/decoder](http://mothereff.in/quoted-printable)

This tool can be used to encode/decode any text using the `Quoted-Printable` content transfer encoding. It uses [_quoted-printable_](http://mths.be/quoted-printable) under the hood.

Made by [Mathias Bynens](http://mathiasbynens.be/).
87 changes: 87 additions & 0 deletions quoted-printable/eff.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
html, textarea {
font: .8em/1.6 sans-serif;
}

body {
max-width: 40em;
padding: 0 1em;
}

h1 {
text-align: center;
font-size: 1.3em;
margin: 0 0 .5em;
padding-top: 1em;
}

h2 {
font-size: 1em;
}

a {
color: #333;
text-decoration: none;
border-bottom: 1px solid #aaa;
padding: .1em .2em;
}

a:hover, a:focus {
color: #fff;
border-color: #036;
background: #36c;
}

textarea {
font-family: Monaco, Consolas, monospace;
}

#footer {
margin-top: 2em;
text-align: center;
}

textarea {
border: 3px double green;
background: #90ee90;
width: 100%;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
display: block;
margin: 1em 0 .5em;
padding: .7em;
resize: vertical;
min-height: 9.5em;
}

code {
font-family: Monaco, Consolas, monospace;
font-size: .9em;
white-space: pre;
white-space: pre-wrap;
word-wrap: break-word;
}

.invalid, :invalid {
border-color: red;
background: #ffb6c1;
}

@media (min-width: 42em) {

html {
font-size: 1.2em;
background: #c4c4c4;
height: 100%;
}

body {
margin: 0 auto;
padding: 0 2em;
min-height: 100%;
background: #fff;
border: solid #aaa;
border-width: 0 1px;
}

}
72 changes: 72 additions & 0 deletions quoted-printable/eff.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
(function(window, document) {

var textareas = document.getElementsByTagName('textarea');
var decoded = textareas[0];
var encoded = textareas[1];
var permalink = document.getElementById('permalink');
// http://mathiasbynens.be/notes/localstorage-pattern
var storage = (function() {
var uid = new Date;
var storage;
var result;
try {
(storage = window.localStorage).setItem(uid, uid);
result = storage.getItem(uid) == uid;
storage.removeItem(uid);
return result && storage;
} catch (exception) {}
}());

function encode(string) {
// URL-encode some more characters to avoid issues when using permalink URLs in Markdown
return encodeURIComponent(string).replace(/['()_*]/g, function(character) {
return '%' + character.charCodeAt().toString(16);
});
}

function update() {
var shouldDecode = this == encoded;
var value;
if (shouldDecode) {
value = quotedPrintable.decode(encoded.value);
decoded.value = value;
} else {
value = quotedPrintable.encode(decoded.value);
encoded.value = value;
}
value = decoded.value;
permalink.hash = encode(value);
storage && (storage.quotedPrintable = value);
};

// http://mathiasbynens.be/notes/oninput
decoded.onkeyup = encoded.onkeyup = update;
decoded.oninput = encoded.oninput = function() {
decoded.onkeyup = encoded.onkeyup = null;
update.call(this);
};

if (storage) {
storage.quotedPrintable && (decoded.value = storage.quotedPrintable);
update();
}

window.onhashchange = function() {
decoded.value = decodeURIComponent(location.hash.slice(1));
update();
};

if (location.hash) {
window.onhashchange();
}

}(this, document));

// Google Analytics
window._gaq = [['_setAccount', 'UA-6065217-60'], ['_trackPageview']];
(function(d, t) {
var g = d.createElement(t),
s = d.getElementsByTagName(t)[0];
g.src = '//www.google-analytics.com/ga.js';
s.parentNode.insertBefore(g, s);
}(document, 'script'));
19 changes: 19 additions & 0 deletions quoted-printable/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang=en>
<meta charset=utf-8>
<title>`Quoted-Printable` encoder/decoder</title>
<meta name=viewport content="width=device-width,initial-scale=1">
<link rel=stylesheet href=eff.css>
<meta name=description content="An online, on-the-fly `Quoted-Printable` encoder/decoder.">
<h1><code>Quoted-Printable</code> encoder/decoder</h1>
<noscript><strong>To use this tool, please <a href=http://enable-javascript.com/>enable JavaScript</a> and reload the page.</strong></noscript>
<h2>Decoded:</h2>
<textarea autofocus>If you believe that truth=beauty, then surely mathematics is the most beautiful branch of philosophy.</textarea>
<h2>Encoded: (<a href=#If%20you%20believe%20that%20truth%3Dbeauty%2C%20then%20surely%20mathematics%20is%20the%20most%20beautiful%20branch%20of%20philosophy. id=permalink>permalink</a>)</h2>
<textarea>If you believe that truth=3Dbeauty, then surely mathematics is the most bea=
utiful branch of philosophy.</textarea>
<h2>About this tool</h2>
<p>This tool uses <a href=http://mths.be/quoted-printable><i>quoted-printable</i></a> to do all the encoding/decoding.
<p id=footer>Made by <a href=http://mathiasbynens.be/>@mathias</a><a href=https://github.com/mathiasbynens/mothereff.in/tree/master/quoted-printable>fork this on GitHub!</a></p>
<script src=vendor/quoted-printable.js></script>
<script src=eff.js></script>
Loading

0 comments on commit f93b9fe

Please sign in to comment.