/ Published in: JavaScript
URL: http://www.topcat.hypermart.net/rot13x-javascript.html
ROT13 is a self encrypting/decrypting cipher. While not terribly secure, its still a handy method for casually masking text. Here's my implementation of the ROT13 cipher in javascript extended to include digits. Feel free to use it in your own work, and contact us if you improve it. Wikipedia has more information about obfuscation.
Expand |
Embed | Plain Text
// rot13x.js - Topcat Software LLC. 2011 // rot13 cipher extended to include digits // http://www.topcat.hypermart.net/rot13x-javascript.html // // referencing the script in your HTML: // // <html> // <head> // <script type="text/javascript" src="rot13x.js"></script> // </head> // <body> // // <script>var foo = rot13x("321 some string..."); var bar = rot13x(foo)</script> // <p>encoded: <script>document.write(foo)</script> // <p>decoded: <script>document.write(bar)</script> // // </body> // </html> function rot13x(s) { var rxi = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" var rxo = "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm5678901234" var map = [] var buf = "" for (z = 0; z <= rxi.length; z++) {map[rxi.substr(z, 1)] = rxo.substr(z, 1)} for (z = 0; z <= s.length; z++) { var c = s.charAt(z) buf += (c in map) ? map[c] : c } return buf }
You need to login to post a comment.
