/ Published in: JavaScript
URL: http://www.topcat.hypermart.net/index.html
Here's an implementation of the classic xor cipher written javascript. The script encodes/decodes plain-text using a password you supply. Feel free to use it in your own work, and contact us if you improve it. Something to remember, the longer the password string, the better...
Expand |
Embed | Plain Text
// xorEncode.js - Topcat Software LLC. 2011 // bitwise XOR cipher for javascript // http://www.topcat.hypermart.net/index.html // // referencing the script in your HTML: // // <html> // <head> // <script type="text/javascript" src="xorEncode.js"></script> // </head> // <body> // // <script> // var foo = xorEncode("we can be heros...", "mypassword") // var bar = xorEncode(foo, "mypassword") // </script> // // <p>encoded: <script>document.write(foo)</script> // <p>decoded: <script>document.write(bar)</script> // // </body> // </html> function xorEncode(txt, pass) { var ord = [] var buf = "" for (z = 1; z <= 255; z++) {ord[String.fromCharCode(z)] = z} for (j = z = 0; z < txt.length; z++) { buf += String.fromCharCode(ord[txt.substr(z, 1)] ^ ord[pass.substr(j, 1)]) j = (j < pass.length) ? j + 1 : 0 } return buf }
You need to login to post a comment.
