Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- public class Kata
- {
- public static string Rot13(string message)
- {
- string alphabetString = "abcdefghijklmnopqrstuvwxyz";
- string alphabetStrCaps = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- char [] alphabetChar = alphabetString.ToCharArray();
- char [] alphabetCharCaps = alphabetStrCaps.ToCharArray();
- char [] msgCharArray = message.ToCharArray();
- string result = string.Empty;
- int letterIndex = 0;
- int rot13Index = 0;
- //Console.Write(message);
- for(int x = 0;x < msgCharArray.Length;x++)
- {
- if(Char.IsLetter(msgCharArray[x]))
- {
- for(int y = 0;y < alphabetChar.Length;y++)
- {
- if(alphabetChar[y] == msgCharArray[x])
- {
- letterIndex = y;
- break;
- }
- }
- if(letterIndex + 13 < 26)
- {
- rot13Index = (letterIndex + 13) ;
- if(Char.IsUpper(msgCharArray[x]))
- {
- msgCharArray[x] = alphabetCharCaps[rot13Index];
- Console.Write( " " + rot13Index.ToString() + " ");
- }
- else
- {
- msgCharArray[x] = alphabetChar[rot13Index];
- Console.Write( " " + rot13Index.ToString() + " ");
- }
- }
- else if(letterIndex + 13 == 26)
- {
- rot13Index = 26 - 1;
- if(Char.IsUpper(msgCharArray[x]))
- {
- msgCharArray[x] = alphabetCharCaps[rot13Index];
- Console.Write( " " + rot13Index.ToString() + " ");
- }
- else
- {
- msgCharArray[x] = alphabetChar[rot13Index];
- Console.Write( " " + rot13Index.ToString() + " ");
- }
- }
- else if(letterIndex + 13 > 26)
- {
- rot13Index = ((letterIndex + 13) % alphabetChar.Length);
- if(Char.IsUpper(msgCharArray[x]))
- {
- msgCharArray[x] = alphabetCharCaps[rot13Index];
- Console.Write( " " + rot13Index.ToString() + " ");
- }
- else
- {
- msgCharArray[x] = alphabetChar[rot13Index];
- Console.Write( " " + rot13Index.ToString() + " ");
- }
- }
- }
- }
- result = new string(msgCharArray);
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement