Skip to content

Instantly share code, notes, and snippets.

@imedadel
Created June 9, 2019 13:27
Show Gist options
  • Save imedadel/10f6ddbce474f6a8adae489e19ad2447 to your computer and use it in GitHub Desktop.
Save imedadel/10f6ddbce474f6a8adae489e19ad2447 to your computer and use it in GitHub Desktop.
const bigN = 13
const alphas = 26
const lowerCaseA = 'a'.charCodeAt(0)
const upperCaseA = 'A'.charCodeAt(0)
const rotate = str => str
.normalize('NFD')
.split('')
.map(chr => chr.charCodeAt(0))
.map(charCode =>
(lowerCaseA <= charCode && charCode < lowerCaseA + alphas) ? ((charCode - lowerCaseA + bigN) % alphas) + lowerCaseA :
(upperCaseA <= charCode && charCode < upperCaseA + alphas) ? ((charCode - upperCaseA + bigN) % alphas) + upperCaseA :
charCode
)
.map(charCode => String.fromCharCode(charCode))
.join('')
const onChange = () => {
const input = document.querySelector('.rot13__input')
const output = document.querySelector('.rot13__output')
output.value = rotate(input.value)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment