Rot13 in Typescript

Published on 09 October 2024 (Updated: 09 October 2024)

Welcome to the Rot13 in Typescript page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

function rot13(input: string): string {
  if (!input) {
      return "Usage: please provide a string to encrypt";
  }

  return input.split('').map(char => {
      const code = char.charCodeAt(0);
      // Check if the character is an uppercase letter
      if (code >= 65 && code <= 90) {
          return String.fromCharCode((code - 65 + 13) % 26 + 65);
      }
      // Check if the character is a lowercase letter
      else if (code >= 97 && code <= 122) {
          return String.fromCharCode((code - 97 + 13) % 26 + 97);
      }
      // If it's not a letter, return the character unchanged
      return char;
  }).join('');
}

const args = process.argv.slice(2);

if (args.length !== 1) {
  console.log("Usage: please provide a string to encrypt");
  process.exit(1);
} else {
  const input = args[0];
  const result = rot13(input);
  console.log(result);
}

Rot13 in Typescript was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.