Created
March 14, 2017 05:21
-
-
Save bussiere/da9106b887ff29e09577deea1426c13e to your computer and use it in GitHub Desktop.
xor encrypt javascript
This file contains 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
// 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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment