Created
January 6, 2015 03:35
-
-
Save dydx/a9d8d4098b11a82e090b to your computer and use it in GitHub Desktop.
fuckin with some xor stuff in 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
function cipher(message, key) { | |
return message.split('') | |
.map(function(element) { | |
return (element.charCodeAt(0) ^ key); | |
}) | |
.map(function(element) { | |
return String.fromCharCode(element) | |
}) | |
.join(''); | |
} | |
function calculateKey(key) { | |
return key.split('') | |
.map(function(element) { | |
return element.charCodeAt(0) | |
}) | |
.join(''); | |
} | |
var message = process.argv[2]; | |
var key = calculateKey(process.argv[3]); | |
var encrypted = cipher(message, key); | |
var decrypted = cipher(encrypted, key); | |
console.log('plaintext: ' + message); | |
console.log('encrypted: ' + encrypted); | |
console.log('Key: ' + key); | |
console.log('decrypted: ' + decrypted); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment