Last active
August 29, 2015 14:00
-
-
Save sters/9fc3b557fee399428cf8 to your computer and use it in GitHub Desktop.
@yagihashooに脅されて作成した
This file contains hidden or 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
| var GomibacoEncode = (function() { | |
| var translateTable = "ごみばこ".split(""); | |
| return { | |
| Encode : function(str) { | |
| return str.split("").map(function(cur){ | |
| var enc = cur.charCodeAt(0).toString(translateTable.length); | |
| for(var i = enc.length; i < translateTable.length; i++) { | |
| enc = "0" + enc; | |
| } | |
| translateTable.forEach(function(translateWord, idx){ | |
| enc = enc.replace(new RegExp(idx, "g"), translateWord); | |
| }); | |
| return enc; | |
| }).join(""); | |
| }, | |
| Decode : function(str) { | |
| translateTable.forEach(function(translateWord, idx){ | |
| str = str.replace(new RegExp(translateWord, "g"), idx); | |
| }); | |
| return str.replace(/(\d{4})/g, "$1.").split(".").map(function(v){ | |
| return String.fromCharCode(parseInt(v, 4)); | |
| }).join(""); | |
| }, | |
| }; | |
| })(); | |
| var x = GomibacoEncode.Encode("HelloWorld"); | |
| document.writeln(x); | |
| var y = GomibacoEncode.Decode(x); | |
| document.writeln(y); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment