Skip to content

Instantly share code, notes, and snippets.

@dydx
Created January 6, 2015 03:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dydx/a9d8d4098b11a82e090b to your computer and use it in GitHub Desktop.
Save dydx/a9d8d4098b11a82e090b to your computer and use it in GitHub Desktop.
fuckin with some xor stuff in javascript
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