Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. public class Kata
  5. {
  6. public static string Rot13(string message)
  7. {
  8. return new string(message.Select(Replacer).ToArray());
  9. }
  10.  
  11. static char Replacer(char a)
  12. {
  13. var alphabet = new Alphabet();
  14.  
  15. if (char.IsLetter(a))
  16. {
  17. int index = alphabet.IndexOfAlphabet(a);
  18. var newChar = alphabet[index + 13];
  19. return char.IsUpper(a) ? char.ToUpper(newChar) : newChar;
  20. }
  21.  
  22. return a;
  23. }
  24. }
  25.  
  26. public class Alphabet
  27. {
  28. private static string _alphabet = "abcdefghijklmnopqrstuvwxyz";
  29.  
  30. public char this[int i] => i >= _alphabet.Length ? _alphabet[i - _alphabet.Length] : _alphabet[i];
  31.  
  32. public int IndexOfAlphabet(char a) => _alphabet.IndexOf(char.ToLower(a));
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement