Skip to content

Instantly share code, notes, and snippets.

@jgravois
Created June 25, 2025 05:19
Show Gist options
  • Save jgravois/6e2196468a1c58b147b4bcc900ecf334 to your computer and use it in GitHub Desktop.
Save jgravois/6e2196468a1c58b147b4bcc900ecf334 to your computer and use it in GitHub Desktop.
i could have used this 30 years ago...
const alphabet = Array.from('abcdefghijklmnopqrstuvwxyz')
const codedMessage = Array.from(`
myxqbkdevkdsyxc!
sd gkc sxnoon usvbyi dro wyeco gry cdyvo dro pokcd. led ro rkn rovz:
yxo rexnbon kxn ovofox yp usvbyi'c pebbi bovkdsfoc rsn drowcovfoc sx
dro ryeco kxn kbyexn dro qkbnox kxn, kd ovofox wsxedoc dy ovofox droi
kvv cmkwzobon sxdy dro lkxaeod rkvv gsdr usvbyi kxn kdo ez kvv yp
rybkmo'c lokedspev pyyn.
kxn xyg, tecd dy cryg ryg mvofob iye kbo, mkx iye psxn yxo rexnbon
kxn ovofox wsmo rsnnox sx dro zsmdeboc?
rkzzi rexdsxq!
`)
const shiftAlphabet = (amount: number) =>
Array.from(alphabet.slice(amount).concat(alphabet.slice(0, amount)))
const decodeMessage = (suspect: string) => {
const firstInitial = suspect.charAt(0).toLowerCase()
const shift = alphabet.length - alphabet.indexOf(firstInitial)
const shiftedAlphabet = shiftAlphabet(shift)
return codedMessage
.map((char) => {
const pos = alphabet.indexOf(char)
if (pos > -1) return shiftedAlphabet[pos]
return char
})
.join('')
}
console.log(decodeMessage('Maxwell'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment