fork(2) download
  1. using System;
  2.  
  3. public class Test
  4. {
  5.  
  6. public static void Main()
  7. {
  8. Test cipher = new Test();
  9. string input = "Hello World";
  10. Console.WriteLine(input);
  11. string enc = cipher.Encrypt(input, 5);
  12. Console.WriteLine(enc);
  13. string dec = cipher.Decrypt(enc, 5);
  14. Console.WriteLine(dec);
  15.  
  16. }
  17.  
  18. public string removeSpaces(string plainIn)
  19. {
  20. return plainIn.Replace(" ", string.Empty);
  21. }
  22.  
  23. public string reverse(string plainIn)
  24. {
  25. char[] charArray = plainIn.ToCharArray();
  26. Array.Reverse(charArray);
  27. return new string(charArray);
  28. }
  29.  
  30. public string toUCase(string strIn)
  31. {
  32. return strIn.ToUpper();
  33. }
  34.  
  35. private const int LETTERA = (int)'A';
  36. private const int LETTERS = (int)'Z' - LETTERA + 1;
  37.  
  38. public string shift(string plainIn, int shift)
  39. {// 65=a 90=z in ASCII
  40. string readOut=string.Empty;
  41. char[] charArray;
  42.  
  43. charArray = plainIn.ToCharArray();
  44. for (int i = 0; i < charArray.Length; i++)
  45. {
  46. //Console.WriteLine("Char {0} is {1} and maps to {2} and shifts to {3}",
  47. // i, charArray[i], (int)charArray[i] - LETTERA,
  48. // (((int)charArray[i] - LETTERA + shift) % LETTERS)
  49. //);
  50. //char c = (char)(LETTERA + (((int)charArray[i] + shift - LETTERA + LETTERS)
  51. // % LETTERS));
  52. //Console.WriteLine("Char {0}", c);
  53. readOut += (char)(LETTERA + (((int)charArray[i] + shift - LETTERA + LETTERS) % LETTERS));
  54. //int Num = Convert.ToInt32(charArray[i]) + shift;
  55. //readOut += Convert.ToChar(Num > 90 ? Num -= 26 : (Num < 65 ? Num += 26: Num));
  56. }
  57. return readOut;
  58. }
  59.  
  60. //this method will take all of these methods and put them together to encrypt
  61. public string Encrypt(string ReadIn, int Shift)
  62. {
  63. ReadIn = removeSpaces(ReadIn);
  64. ReadIn = reverse(ReadIn);
  65. ReadIn = toUCase(ReadIn);
  66. ReadIn = shift(ReadIn, Shift);
  67. return ReadIn;
  68. }
  69.  
  70. public string Decrypt(string ReadIn, int amountShift)
  71. {
  72. ReadIn = reverse(ReadIn);// undo the reverse by running the method again
  73. ReadIn = shift(ReadIn, -amountShift);
  74.  
  75. return ReadIn;
  76. }
  77. }
Success #stdin #stdout 0.03s 33912KB
stdin
Standard input is empty
stdout
Hello World
IQWTBTQQJM
HELLOWORLD