Advertisement
Guest User

Untitled

a guest
May 20th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _123
  8. {
  9. class Program
  10. {
  11. static int[] keys = null;
  12. static string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  13.  
  14. static void Main(string[] args)
  15. {
  16. EnterKey();
  17.  
  18. string str = null;
  19. str = Console.ReadLine();
  20. string[] words = str.Split(' ');
  21.  
  22. StringBuilder result = new StringBuilder();
  23. foreach (string s in words)
  24. result.Append(MyShifr(new StringBuilder(s)).Append(" "));
  25.  
  26. Console.WriteLine(result);
  27. Console.Read();
  28. }
  29.  
  30. static StringBuilder MyShifr(StringBuilder s)
  31. {
  32. StringBuilder sb = new StringBuilder();
  33. for (int i = 0; i < s.Length; i++)
  34. {
  35. sb.Append(alphabet[(alphabet.IndexOf(s[i]) + keys[i % keys.Length]) % alphabet.Length]);
  36. }
  37. return sb;
  38. }
  39.  
  40. static void EnterKey()
  41. {
  42. string str = null;
  43. str = Console.ReadLine();
  44. try
  45. {
  46. string[] strkey = str.Split(' ');
  47. keys = new int[strkey.Length];
  48. for (int i = 0; i < strkey.Length; i++)
  49. {
  50. keys[i] = Convert.ToInt32(strkey[i]) % 10;
  51. }
  52. }
  53. catch (Exception e)
  54. {
  55. Console.Write(e.Message);
  56. }
  57. }
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement