Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit b85032db8e3bcbd5ef4d6a64ea610ac5650b50c1 0 parents
@alcuadrado authored
18 LICENSE
@@ -0,0 +1,18 @@
+Copyright (c) <2012> <Patricio Palladino>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 bin/hieroglyphy
@@ -0,0 +1,17 @@
+#!/usr/bin/env node
+
+var hieroglyphy = require("../hieroglyphy.js"),
+ fs = require("fs");
+
+if ((process.argv.length !== 3) || (process.argv[2] == "--help") ||
+ (process.argv[2] == "-h")) {
+
+ console.log("Run it with the file to convert as first argument.");
+ console.log("It prints the output to stdout.");
+ process.exit(1);
+}
+
+fs.readFile(process.argv[2], function (err, data) {
+ if (err) throw err;
+ console.log(hieroglyphy(data.toString()));
+});
177 hieroglyphy.js
@@ -0,0 +1,177 @@
+;(function (global, undefined) {
+/*jshint sub:true, evil:true */
+ "use strict";
+
+ var numbers,
+ characters,
+ functionConstructor,
+ escape,
+ unescape;
+
+ numbers = [
+ "+[]",
+ "+!![]",
+ "!+[]+!![]",
+ "!+[]+!![]+!![]",
+ "!+[]+!![]+!![]+!![]",
+ "!+[]+!![]+!![]+!![]+!![]",
+ "!+[]+!![]+!![]+!![]+!![]+!![]",
+ "!+[]+!![]+!![]+!![]+!![]+!![]+!![]",
+ "!+[]+!![]+!![]+!![]+!![]+!![]+!![]+!![]",
+ "!+[]+!![]+!![]+!![]+!![]+!![]+!![]+!![]+!![]"
+ ];
+
+ characters = {
+ "0" : "(" + numbers[0] + ")",
+ "1" : "(" + numbers[1] + ")",
+ "2" : "(" + numbers[2] + ")",
+ "3" : "(" + numbers[3] + ")",
+ "4" : "(" + numbers[4] + ")",
+ "5" : "(" + numbers[5] + ")",
+ "6" : "(" + numbers[6] + ")",
+ "7" : "(" + numbers[7] + ")",
+ "8" : "(" + numbers[8] + ")",
+ "9" : "(" + numbers[9] + ")",
+ " " : "({}+[])[!+[]+!![]+!![]+!![]+!![]+!![]+!![]]",
+ "[" : "({}+[])[+[]]",
+ "]" : "({}+[])[[]+ +!![]+(!+[]+!![]+!![]+!![])]",
+ "+" : "(+(+!![] + (!![]+[])[!+[]+!+[]+!+[]] + +!![] + +[] + +[])+[])[" +
+ "+[]+!![]+!![]]",
+ "a" : "(+{}+[])[+!![]]",
+ "b" : "({}+[])[!+[]+!![]]",
+ "c" : "({}+[])[!+[]+!+[]+!+[]+!+[]+!+[]]",
+ "d" : "([][+[]]+[])[!+[]+!![]]",
+ "e" : "(!![]+[])[!+[]+!![]+!![]]",
+ "f" : "([][+[]]+[])[!+[]+!![]+!![]+!![]]",
+ "i" : "([][+[]]+[])[!+[]+!![]+!![]+!![]+!![]]",
+ "j" : "({}+[])[!+[]+!![]+!![]]",
+ "l" : "(![]+[])[+[]+!![]+!![]]",
+ "n" : "([][+[]]+[])[+!![]]",
+ "o" : "({}+[])[+!![]]",
+ "r" : "(!![]+[])[+!![]]",
+ "s" : "(![]+[])[+[]+!![]+!![]+!![]]",
+ "t" : "(!![]+[])[+[]]",
+ "u" : "([][+[]]+[])[+[]]",
+ "y" : "(+(+!![] + (!![]+[])[!+[]+!+[]+!+[]] + +!![] + +[] + +[] + +[]" +
+ ")+[])[!+[]+!![]+!![]+!![]+!![]+!![]+!![]]",
+ "I" : "(+(+!![] + (!![]+[])[!+[]+!+[]+!+[]] + +!![] + +[] + +[] + +[]" +
+ ")+[])[+[]]",
+ "N" : "(+{}+[])[+[]]",
+ "O" : "({}+[])[!+[]+!![]+!![]+!![]+!![]+!![]+!![]+!![]]"
+ };
+
+ functionConstructor = "[][" + hieroglyphyString("sort") + "][" +
+ hieroglyphyString("constructor") + "]";
+
+ //Below characters need target http(s) pages
+ characters["h"] = "([]+" + hieroglyphy("return location") + ")[" +
+ numbers[0] + "]";
+ characters["p"] = "([]+" + hieroglyphy("return location") + ")[" +
+ numbers[3] + "]";
+ characters["/"] = "([]+" + hieroglyphy("return location") + ")[" +
+ numbers[6] + "]";
+
+ unescape = hieroglyphy("return unescape");
+ escape = hieroglyphy("return escape");
+
+ characters["%"] = escape + "(" + hieroglyphyString("[") + ")[" +
+ numbers[0] + "]";
+
+ function getHexaString (number, digits) {
+ var string = number.toString(16);
+
+ while (string.length < digits) {
+ string = "0" + string;
+ }
+
+ return string;
+ }
+
+ function getUnescapeSequence (charCode) {
+ return unescape + "(" +
+ hieroglyphyString("%" + getHexaString(charCode, 2)) + ")";
+ }
+
+ function getHexaSequence (charCode) {
+ return hieroglyphyString("\\x" + getHexaString(charCode, 2));
+ }
+
+ function getUnicodeSequence (charCode) {
+ return hieroglyphyString("\\u" + getHexaString(charCode, 4));
+ }
+
+ function hieroglyphyCharacter (char) {
+ var charCode = char.charCodeAt(0),
+ unescapeSequence,
+ hexaSequence,
+ unicodeSequence,
+ shortestSequence;
+
+ if (characters[char] !== undefined) {
+ return characters[char];
+ }
+
+ if (char === "\\") {
+ //This char must be handled appart becuase the others need them
+ characters[char] = getUnescapeSequence(charCode);
+ return characters[char];
+ }
+
+ if (charCode < 128) {
+ //ASCII characters can be obtained with hexa and unscape sequences
+ unescapeSequence = getUnescapeSequence(charCode);
+
+ if (char !== "x") {
+ //Hexa sequences need the x.
+ hexaSequence = getHexaSequence(charCode);
+ }
+ }
+
+ shortestSequence = getUnicodeSequence(charCode);
+
+ if (hexaSequence !== undefined) {
+ if (unescapeSequence.length < hexaSequence.length) {
+ if (shortestSequence.length > unescapeSequence.length) {
+ shortestSequence = unescapeSequence;
+ }
+ } else {
+ if (shortestSequence.length > hexaSequence.length) {
+ shortestSequence = hexaSequence;
+ }
+ }
+ } else if (unescapeSequence !== undefined) {
+ if (shortestSequence.length > unescapeSequence.length) {
+ shortestSequence = unescapeSequence;
+ }
+ }
+
+ characters[char] = shortestSequence;
+ return shortestSequence;
+ }
+
+ function hieroglyphyString (str) {
+ var i,
+ hieroglyphiedStr = "";
+
+ for (i = 0; i < str.length; i += 1) {
+
+ hieroglyphiedStr += (i > 0) ? "+" : "";
+ hieroglyphiedStr += hieroglyphyCharacter(str[i]);
+ }
+
+ return hieroglyphiedStr;
+ }
+
+ function hieroglyphy (src) {
+ return functionConstructor + "(" + hieroglyphyString(src) + ")()";
+ }
+
+ if (global.define && global.define.amd) {
+ global.define([], hieroglyphy);
+ } else if (typeof exports !== "undefined") {
+ module.exports = hieroglyphy;
+ } else {
+ global.hieroglyphy = hieroglyphy;
+ }
+
+})(this);
16 package.json
@@ -0,0 +1,16 @@
+{
+ "name": "hieroglyphy",
+ "description": "Convert any javascript to a sequence of ()[]+! characters",
+ "author": "Patricio Palladino <email@patriciopalladino.com>",
+ "version": "0.1.0",
+ "dependencies": {},
+ "bin": {
+ "hieroglyphy": "./bin/hieroglyphy"
+ },
+ "main": "./hieroglyphy.js",
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/alcuadrado/hieroglyphy"
+ },
+ "license": "MIT"
+}
52 test.html
@@ -0,0 +1,52 @@
+<!doctype html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>test - MUST run in http or https</title>
+ </head>
+ <body>
+ <script src="hieroglyphy.js"></script>
+ <script>
+ var i,
+ c,
+ encoded,
+ evaled,
+ script;
+
+ for (i = 0; i < 127; i += 1) {
+
+ if ((i == 10) || (i == 13) || (i == 34) || (i == 92)) {
+ continue; //We can't test these chars like this
+ }
+
+ c = String.fromCharCode(i);
+ encoded = hieroglyphy("return \"" + c + "\";");
+ evaled = eval(encoded);
+
+ if (c !== evaled) {
+ console.error("Error at char %s", c);
+ }
+ }
+
+ c = "\\";
+
+ encoded = hieroglyphy("return \"\\\\\";");
+ evaled = eval(encoded);
+
+ if (c !== evaled) {
+ console.error("Error at char %s", c);
+ }
+
+ //a script doing something and testing 10, 13, 34 and some unicode
+ script = "document.body.innerHTML =\r\n" +
+ "\"<h1>It Works ☺!</h1>\"";
+
+ eval(hieroglyphy(script));
+
+ if (document.body.innerHTML !== "<h1>It Works ☺!</h1>") {
+ console.error("Error with the script");
+ }
+
+ </script>
+ </body>
+</html>

0 comments on commit b85032d

Please sign in to comment.
Something went wrong with that request. Please try again.