Skip to content

Instantly share code, notes, and snippets.

@vstarck
Created November 22, 2011 12:42
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 vstarck/1385585 to your computer and use it in GitHub Desktop.
Save vstarck/1385585 to your computer and use it in GitHub Desktop.
Caesar Cipher packed
// 149 chars :<
/*
function c(o) {
function t(o, s) {
return s.replace(/./g, function(c) {
return String.fromCharCode(c.charCodeAt(0) + o)
})
}
return {
e: t.bind(c, o),
d: t.bind(c, -o)
}
}
*/
function c(o){function t(o,s){return s.replace(/./g,function(c){return String.fromCharCode(c.charCodeAt(0)+o)})}return{e:t.bind(c,o),d:t.bind(c,-o)}}
var caesarCipher = c(3);
caesarCipher.e('Hello world'); // "Khoor#zruog"
caesarCipher.d('Khoor#zruog'); // "Hello world"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment