Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- public class Kata
- {
- public static string Rot13(string message)
- {
- return new string(message.Select(Replacer).ToArray());
- }
- static char Replacer(char a)
- {
- var alphabet = new Alphabet();
- if (char.IsLetter(a))
- {
- int index = alphabet.IndexOfAlphabet(a);
- var newChar = alphabet[index + 13];
- return char.IsUpper(a) ? char.ToUpper(newChar) : newChar;
- }
- return a;
- }
- }
- public class Alphabet
- {
- private static string _alphabet = "abcdefghijklmnopqrstuvwxyz";
- public char this[int i] => i >= _alphabet.Length ? _alphabet[i - _alphabet.Length] : _alphabet[i];
- public int IndexOfAlphabet(char a) => _alphabet.IndexOf(char.ToLower(a));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement