Rot13 in C#

Published on 30 December 2018 (Updated: 30 December 2018)

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

Current Solution

using System;
using System.Collections.Generic;
using System.Linq;

namespace SamplePrograms
    public class Rot13
        static List<char> Lowers = "abcdefghijklmnopqrstuvwxyz".ToCharArray().ToList();
        static List<char> Uppers = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray().ToList();

        public static string Encrypt(string str) =>
            string.Join("", str.ToCharArray().Select(c => Encrypt(c)));

        public static Char Encrypt(char c)
            List<char> ltrs;
            if (char.IsUpper(c))
                ltrs = Uppers;
            else if (char.IsLower(c))
                ltrs = Lowers;
                return c;

            var newIndex = (ltrs.IndexOf(c) + 13) % 26;
            return ltrs[newIndex];


        public static void ExitWithError()
            Console.WriteLine("Usage: please provide a string to encrypt");

        public static void Main(string[] args)
                var str = args[0];
                if (String.IsNullOrEmpty(str))
                var result = Encrypt(str);

Rot13 in C# was written by:

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

Note: The solution shown above is the current solution in the Sample Programs repository as of Apr 06 2019 00:37:26. The solution was first committed on Dec 30 2018 02:35:38. As a result, documentation below may be outdated.

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.