Advertisement
GabrielDas

Untitled

Apr 12th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.02 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace ActivationKeysExam
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. string[] keys = Console.ReadLine().Split('&');
  12. bool isValid = true;
  13. List<string> validKeys = new List<string>();
  14.  
  15.  
  16. for (int i = 0; i < keys.Length; i++)
  17. {
  18. for (int j = 0; j < keys[i].Length; j++)
  19. {
  20. if (!char.IsDigit(keys[i][j]) && !char.IsLetter(keys[i][j]) ||
  21. (keys[i].Length != 16 && keys[i].Length !=25)
  22. )
  23. {
  24. isValid = false;
  25. break;
  26.  
  27. }
  28.  
  29. }
  30.  
  31. if (isValid == true)
  32. {
  33. validKeys.Add(keys[i]);
  34. }
  35.  
  36. isValid = true;
  37.  
  38. }
  39.  
  40. foreach (var key in validKeys)
  41. {
  42. if (key.Length == 16)
  43. {
  44. ModifyKeyWith16(key);
  45. foreach (var item in ModifyKeyWith16(key))
  46. {
  47. if(item == ModifyKeyWith16(key)[3])
  48. {
  49. if (key == validKeys[validKeys.Count - 1])
  50. {
  51. Console.WriteLine($"{item}");
  52. break;
  53. }
  54. else
  55. {
  56. Console.Write($"{item}, ");
  57. break;
  58. }
  59. }
  60. Console.Write($"{item}-");
  61. }
  62. }
  63. else if (key.Length == 25)
  64. {
  65. ModifyKeyWith25(key);
  66. foreach (var item in ModifyKeyWith25(key))
  67. {
  68. if(item == ModifyKeyWith25(key)[4])
  69. {
  70. if (key == validKeys[validKeys.Count - 1])
  71. {
  72. Console.WriteLine($"{item}");
  73. break;
  74. }
  75. else
  76. {
  77. Console.Write($"{item}, ");
  78. break;
  79. }
  80. }
  81. Console.Write($"{item}-");
  82. }
  83.  
  84. }
  85.  
  86. }
  87.  
  88. }
  89.  
  90. private static List<string> ModifyKeyWith25(string key)
  91. {
  92. List<string> modifiedKeys = new List<string>();
  93. StringBuilder output = new StringBuilder();
  94. int count = 0;
  95.  
  96. for (int i = 0; i < key.Length; i++)
  97. {
  98. char newChar = ' ';
  99. if (char.IsLetter(key[i]))
  100. {
  101. newChar = char.ToUpper(key[i]);
  102. }
  103. else if (char.IsDigit(key[i]))
  104. {
  105. char digit = key[i];
  106. string newDigit = (9 - int.Parse(digit.ToString())).ToString();
  107. newChar = char.Parse(newDigit);
  108.  
  109. }
  110.  
  111. output.Append(newChar);
  112. count++;
  113.  
  114. if (count == 5)
  115. {
  116. count = 0;
  117. //output.Append('-');
  118. var newOutput = output.ToString();
  119. modifiedKeys.Add(newOutput);
  120. output = new StringBuilder();
  121.  
  122. }
  123. }
  124.  
  125.  
  126. return modifiedKeys;
  127. }
  128.  
  129.  
  130. private static List<string> ModifyKeyWith16(string key)
  131. {
  132. List<string> modifiedKeys = new List<string>();
  133. StringBuilder output = new StringBuilder();
  134. int count = 0;
  135.  
  136. for (int i = 0; i < key.Length; i++)
  137. {
  138. char newChar = ' ';
  139. if (char.IsLetter(key[i]))
  140. {
  141. newChar = char.ToUpper(key[i]);
  142. }
  143. else if (char.IsDigit(key[i]))
  144. {
  145. char digit = key[i];
  146. string newDigit = (9 - int.Parse(digit.ToString())).ToString();
  147. newChar = char.Parse(newDigit);
  148.  
  149. }
  150.  
  151. output.Append(newChar);
  152. count++;
  153.  
  154. if (count == 4)
  155. {
  156. count = 0;
  157. // output.Append('-');
  158. var newOutput = output.ToString();
  159. modifiedKeys.Add(newOutput);
  160. output = new StringBuilder();
  161.  
  162. }
  163. }
  164.  
  165.  
  166. return modifiedKeys;
  167. }
  168.  
  169. }
  170. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement