A Collection of Code Snippets in as Many Programming Languages as Possible
This project is maintained by TheRenegadeCoder
Welcome to the Rot13 in Javascript page! Here, you'll find the source code for this program as well as a description of how the program works.
const lower = "abcdefghijklmnopqrstuvwxyz";
const upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const rotateChar = (char) => {
if (lower.includes(char)) {
const newIdx = (lower.indexOf(char) + 13) % lower.length;
return lower[newIdx];
}
if (upper.includes(char)) {
const newIdx = (upper.indexOf(char) + 13) % upper.length;
return upper[newIdx];
}
return char;
}
const rotate13 = (string) => {
const stringArray = string.split("");
const rotatedBy13 = stringArray.map((char) => rotateChar(char));
return rotatedBy13.join("");
}
const exit = () => {
console.log('Usage: please provide a string to encrypt');
process.exit();
}
const main = (input) => {
try {
input.length > 0 ? console.log(rotate13(input)): exit();
} catch {
exit();
}
}
main(process.argv[2]);
Rot13 in Javascript was written by:
If you see anything you'd like to change or update, please consider contributing.
No 'How to Implement the Solution' section available. Please consider contributing.
No 'How to Run the Solution' section available. Please consider contributing.