Skip to content

Instantly share code, notes, and snippets.

@foxt
Created November 5, 2023 00:48
Show Gist options
  • Save foxt/0cda1472dbd2e6e29908ceafc0087ef5 to your computer and use it in GitHub Desktop.
Save foxt/0cda1472dbd2e6e29908ceafc0087ef5 to your computer and use it in GitHub Desktop.
JS XOR finder
// XORs hexadecimal format with all values 0-255, sorted by the amount of printable characters.
var data = `3d 01 0c 49 18 1c 00 0a 02 49 0b 1b 06 1e 07 49 0f 06 11 49 03 1c 04 19 1a 49 06 1f 0c 1b 49 1d 01 0c 49 05 08 13 10 49 0d 06 0e 47`.split(" ").map((a) => parseInt(a,16))
const xor = (x) => data.map(a => a ^ x).map(a => String.fromCharCode(a)).join("")
const printable = (s) => [...s].filter((a) => ( a.charCodeAt(0) >= 33 && a.charCodeAt(0) <= 126)).join("")
Array(256).fill(1).map((a,i) => i + ": "+ printable(xor(i))).sort((a,b) => b.length - a.length).join("\n")
//
// [...]
// 38: '*o>:&,$o-=8!o)7o%:\"?<o9*=o;'*o#.56o+(a
// 105: Thequickbrownfoxjumpsoverthelazydog.
// 54: 7:.*6<4=-0(190'5*2/,0):-+7:3>%&;08q
// [...]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment