Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace ActivationKeysExam
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] keys = Console.ReadLine().Split('&');
- bool isValid = true;
- List<string> validKeys = new List<string>();
- for (int i = 0; i < keys.Length; i++)
- {
- for (int j = 0; j < keys[i].Length; j++)
- {
- if (!char.IsDigit(keys[i][j]) && !char.IsLetter(keys[i][j]) ||
- (keys[i].Length != 16 && keys[i].Length !=25)
- )
- {
- isValid = false;
- break;
- }
- }
- if (isValid == true)
- {
- validKeys.Add(keys[i]);
- }
- isValid = true;
- }
- foreach (var key in validKeys)
- {
- if (key.Length == 16)
- {
- ModifyKeyWith16(key);
- foreach (var item in ModifyKeyWith16(key))
- {
- if(item == ModifyKeyWith16(key)[3])
- {
- if (key == validKeys[validKeys.Count - 1])
- {
- Console.WriteLine($"{item}");
- break;
- }
- else
- {
- Console.Write($"{item}, ");
- break;
- }
- }
- Console.Write($"{item}-");
- }
- }
- else if (key.Length == 25)
- {
- ModifyKeyWith25(key);
- foreach (var item in ModifyKeyWith25(key))
- {
- if(item == ModifyKeyWith25(key)[4])
- {
- if (key == validKeys[validKeys.Count - 1])
- {
- Console.WriteLine($"{item}");
- break;
- }
- else
- {
- Console.Write($"{item}, ");
- break;
- }
- }
- Console.Write($"{item}-");
- }
- }
- }
- }
- private static List<string> ModifyKeyWith25(string key)
- {
- List<string> modifiedKeys = new List<string>();
- StringBuilder output = new StringBuilder();
- int count = 0;
- for (int i = 0; i < key.Length; i++)
- {
- char newChar = ' ';
- if (char.IsLetter(key[i]))
- {
- newChar = char.ToUpper(key[i]);
- }
- else if (char.IsDigit(key[i]))
- {
- char digit = key[i];
- string newDigit = (9 - int.Parse(digit.ToString())).ToString();
- newChar = char.Parse(newDigit);
- }
- output.Append(newChar);
- count++;
- if (count == 5)
- {
- count = 0;
- //output.Append('-');
- var newOutput = output.ToString();
- modifiedKeys.Add(newOutput);
- output = new StringBuilder();
- }
- }
- return modifiedKeys;
- }
- private static List<string> ModifyKeyWith16(string key)
- {
- List<string> modifiedKeys = new List<string>();
- StringBuilder output = new StringBuilder();
- int count = 0;
- for (int i = 0; i < key.Length; i++)
- {
- char newChar = ' ';
- if (char.IsLetter(key[i]))
- {
- newChar = char.ToUpper(key[i]);
- }
- else if (char.IsDigit(key[i]))
- {
- char digit = key[i];
- string newDigit = (9 - int.Parse(digit.ToString())).ToString();
- newChar = char.Parse(newDigit);
- }
- output.Append(newChar);
- count++;
- if (count == 4)
- {
- count = 0;
- // output.Append('-');
- var newOutput = output.ToString();
- modifiedKeys.Add(newOutput);
- output = new StringBuilder();
- }
- }
- return modifiedKeys;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement