Skip to content

Instantly share code, notes, and snippets.

@westc
Last active August 29, 2015 14:02
Show Gist options
  • Save westc/7df66077dccecda1e897 to your computer and use it in GitHub Desktop.
Save westc/7df66077dccecda1e897 to your computer and use it in GitHub Desktop.
Message Scrambler - Proof that typoglycemia allows us to read scrambled messages.
function scramble(input) {
return input.replace(/\b(\w)(\w{2,})(\w)\b/g, function(all, a, b, c) {
return a
+ b.split('').sort(function(){return Math.random()-.5}).join('')
+ c;
});
}
input = prompt("Enter the message you want scrambled:");
console.log(scramble(input));
@westc
Copy link
Author

westc commented Jun 14, 2014

@tunnckoCore
Copy link

i think it should (it would be) better if it is .2 not .5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment