Advertisement
mastersan12

Activation Keys

Apr 13th, 2019
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.32 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4. using System.Text;
  5. using System.Linq;
  6.  
  7. namespace Activation_Keys
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<string> input = Console.ReadLine().Split("&").ToList();
  14.             string keyPattern16 = @"^[A-Za-z0-9]{16}$";
  15.             string keyPattern25 = @"[A-Za-z0-9]{25}";
  16.             List<string> results = new List<string>();
  17.             for (int i = 0; i < input.Count; i++)
  18.             {
  19.                 bool IsMatch1 = Regex.IsMatch(input[i], keyPattern16);
  20.                 bool IsMatch2 = Regex.IsMatch(input[i], keyPattern25);
  21.  
  22.                 if (IsMatch1 || IsMatch2)
  23.                 {
  24.                     StringBuilder current = new StringBuilder();
  25.                     string currentKey = input[i].ToUpper();
  26.  
  27.                     for (int j = 0; j < currentKey.Length; j++)
  28.                     {
  29.                         char currentChar = currentKey[j];
  30.                         if (char.IsDigit(currentChar))
  31.                         {
  32.                             string charString = currentChar.ToString();
  33.                             int number = int.Parse(charString);
  34.                             number = 9 - number;
  35.                             char newChar = char.Parse(number.ToString());
  36.                             current.Append(newChar);
  37.                         }
  38.  
  39.                         else
  40.                         {
  41.                             current.Append(currentChar);
  42.                         }
  43.                     }
  44.                     if (current.Length == 16)
  45.                     {
  46.                         current.Insert(4, '-');
  47.                         current.Insert(9, '-');
  48.                         current.Insert(14, '-');                      
  49.                     }
  50.  
  51.                     else if (current.Length == 25)
  52.                     {
  53.                         current.Insert(5, '-');
  54.                         current.Insert(11, '-');
  55.                         current.Insert(17, '-');
  56.                         current.Insert(23, '-');
  57.                     }
  58.                     results.Add(current.ToString());
  59.                 }
  60.             }
  61.  
  62.  
  63.             Console.WriteLine(String.Join($", ", results));
  64.  
  65.  
  66.  
  67.  
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement