Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Windows.Forms;
- namespace CodeLock
- {
- public class Key
- {
- public string GenerateSerial()
- {
- string serial = "";
- Random ran = new Random();
- long key = ran.Next(0, 60466175);
- List<List<string>> lst = new List<List<string>>();
- string[] arr1 = { "A", "A", "B", "C", "C", "D", "E", "E", "F", "G", "G", "H", "I", "I", "J", "K", "K", "L", "M", "M", "N", "O", "O", "P", "Q", "Q", "R", "S", "S", "T", "U", "U", "V", "W", "W", "X", "Y", "Y", "Z", "0", "0", "1", "2", "2", "3", "4", "4", "5", "6", "6", "7", "8", "8", "9" };
- string[] arr2 = { "B", "C", "D", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "V", "W", "X", "Y", "Z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
- string[] arr3 = { "A", "E", "I", "O", "U", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
- string[] arr4 = { "0", "2", "4", "6", "8", "A", "C", "E", "G", "I", "K", "M", "O", "Q", "S", "U", "W", "Y" };
- string[] arr5 = { "0", "1", "2", "6", "7", "8", "A", "B", "C", "G", "H", "I", "M", "N", "O", "S", "T", "U", "Y", "Z" };
- string[] arr6 = { "L", "X", "M", "N", "T", "O", "P", "U", "V", "Q", "W", "A", "K", "0", "2", "4", "5", "6", "8", "9" };
- string[] arr7 = { "N", "T", "O", "S", "P", "R", "I", "E", "L", "X", "Q", "Z", "C", "B", "H", "8", "7", "2", "1", "6", "0", "3" };
- string[] arr8 = { "L", "S", "D", "M", "N", "O", "Q", "R", "S", "N", "V", "Q", "Y", "Q", "K", "X", "C", "A", "4", "5", "9", "2" };
- string[] arr9 = { "9", "7", "6", "4", "3", "1", "Q", "E", "T", "U", "O", "A", "S", "F", "H", "K", "Z", "C", "B", "M" };
- string[] arr10 = { "9", "8", "7", "3", "2", "1", "5", "5", "5", "W", "R", "Y", "I", "P", "S", "F", "H", "K", "Z", "C", "B", "M" };
- string[] arr11 = { "Q", "R", "I", "A", "F", "J", "Z", "V", "M", "E", "U", "P", "D", "H", "L", "C", "N", "0", "2", "3", "5", "7", "8" };
- string[] arr12 = { "Q", "A", "Z", "E", "D", "C", "T", "G", "B", "U", "J", "M", "O", "L", "7", "4", "5", "6", "3", "2" };
- string[] arr13 = { "Q", "A", "S", "E", "R", "F", "G", "H", "Y", "U", "J", "K", "I", "O", "L", "Z", "X", "S", "D", "F", "V", "B", "G", "H", "J", "M", "K", "9", "5", "1", "7", "5", "3" };
- string[] arr14 = { "Q", "W", "E", "T", "Y", "U", "O", "P", "A", "D", "F", "G", "J", "K", "L", "X", "C", "V", "N", "M", "1", "4", "6", "9" };
- string[] arr15 = { "Q", "A", "Z", "X", "C", "D", "E", "R", "T", "G", "B", "N", "M", "J", "U", "I", "O", "L", "1", "5", "4", "8", "6", "2", "3" };
- string[] arr16 = { "W", "E", "D", "C", "V", "B", "G", "T", "Y", "U", "J", "M", "K", "L", "O", "H", "F", "S", "1", "5", "4", "2", "3" };
- string[] arr17 = { "O", "I", "U", "T", "G", "B", "C", "X", "Z", "Q", "W", "E", "R", "F", "V", "B", "N", "M" };
- string[] arr18 = { "Q", "A", "Z", "X", "S", "D", "C", "V", "F", "R", "T", "G", "B", "N", "H", "J", "M", "K", "I", "O", "L", "P", "1", "3", "2", "5", "6", "7", "9" };
- string[] arr19 = { "L", "I", "A", "M", "I", "S", "C", "O", "O", "L", "I", "S", "N", "T", "H", "E", "3", "3", "3" };
- string[] arr20 = { "L", "S", "D", "I", "S", "C", "O", "O", "L", "S", "O", "I", "S", "C", "O", "C", "A", "I", "N", "E", "A", "N", "D", "P", "O", "T", "A", "N", "D", "M", "E", "T", "H" };
- lst.Add(new List<string>(arr1));
- lst.Add(new List<string>(arr2));
- lst.Add(new List<string>(arr3));
- lst.Add(new List<string>(arr4));
- lst.Add(new List<string>(arr5));
- lst.Add(new List<string>(arr6));
- lst.Add(new List<string>(arr7));
- lst.Add(new List<string>(arr8));
- lst.Add(new List<string>(arr9));
- lst.Add(new List<string>(arr10));
- lst.Add(new List<string>(arr11));
- lst.Add(new List<string>(arr12));
- lst.Add(new List<string>(arr13));
- lst.Add(new List<string>(arr14));
- lst.Add(new List<string>(arr15));
- lst.Add(new List<string>(arr16));
- lst.Add(new List<string>(arr17));
- lst.Add(new List<string>(arr18));
- lst.Add(new List<string>(arr19));
- lst.Add(new List<string>(arr20));
- serial = CConvert.ToBase36((int)key, 36);
- while (!(serial.Length >= 5))
- {
- serial = "0" + serial;
- }
- Random r1 = new Random((int)key);
- int x = 0;
- while (!(serial.Length == 29))
- {
- x = serial.Length;
- if (x % 6 == 5)
- {
- serial += "-";
- }
- else
- {
- serial += lst[x - (5 + (x + 1) / 6)][r1.Next(0, lst[x - (5 + (x + 1) / 6)].Count - 1)];
- }
- }
- return serial;
- }
- public bool ValidateCode(string Serial)
- {
- Random ran = new Random();
- char[] charsToTrim = { '!', '"', '£', '$', '%', '^', '&', '*', '(', ')', '_', '+', '=', '[', ']', '{', '}',
- ';', ':', '\'', '@', '#', '~', '<', '>', ',', '.', '?', '/', '\\', '|', '`', '¬' };
- Serial = Serial.Trim();
- Serial = Serial.Trim(charsToTrim);
- if (!(Serial.Length == 29))
- return false;
- List<List<string>> lst = new List<List<string>>();
- string[] arr1 = { "A", "A", "B", "C", "C", "D", "E", "E", "F", "G", "G", "H", "I", "I", "J", "K", "K", "L", "M", "M", "N", "O", "O", "P", "Q", "Q", "R", "S", "S", "T", "U", "U", "V", "W", "W", "X", "Y", "Y", "Z", "0", "0", "1", "2", "2", "3", "4", "4", "5", "6", "6", "7", "8", "8", "9" };
- string[] arr5 = { "0", "1", "2", "6", "7", "8", "A", "B", "C", "G", "H", "I", "M", "N", "O", "S", "T", "U", "Y", "Z" };
- string[] arr9 = { "9", "7", "6", "4", "3", "1", "Q", "E", "T", "U", "O", "A", "S", "F", "H", "K", "Z", "C", "B", "M" };
- string[] arr10 = { "9", "8", "7", "3", "2", "1", "5", "5", "5", "W", "R", "Y", "I", "P", "S", "F", "H", "K", "Z", "C", "B", "M" };
- string[] arr19 = { "L", "I", "A", "M", "I", "S", "C", "O", "O", "L", "I", "S", "N", "T", "H", "E", "3", "3", "3" };
- lst.Add(new List<string>(arr1));
- lst.Add(new List<string>());
- lst.Add(new List<string>());
- lst.Add(new List<string>());
- lst.Add(new List<string>(arr5));
- lst.Add(new List<string>());
- lst.Add(new List<string>());
- lst.Add(new List<string>());
- lst.Add(new List<string>(arr9));
- lst.Add(new List<string>(arr10));
- lst.Add(new List<string>());
- lst.Add(new List<string>());
- lst.Add(new List<string>());
- lst.Add(new List<string>());
- lst.Add(new List<string>());
- lst.Add(new List<string>());
- lst.Add(new List<string>());
- lst.Add(new List<string>());
- lst.Add(new List<string>(arr19));
- lst.Add(new List<string>());
- Random r1 = null;
- try
- {
- r1 = new Random((int)CConvert.FromBase36(Serial.Substring(0, 5)));
- }
- catch
- {
- return false;
- }
- int x = 0;
- string chk = Serial.Substring(0, 5);
- while (!(chk.Length == 29))
- {
- x = chk.Length;
- if (x % 6 == 5)
- {
- chk += "-";
- }
- else
- {
- if (lst[x - (5 + (x + 1) / 6)].Count == 0)
- {
- chk += ".";
- r1.Next(0, 1);
- }
- else
- {
- chk += lst[x - (5 + (x + 1) / 6)][r1.Next(0, lst[x - (5 + (x + 1) / 6)].Count - 1)];
- }
- }
- }
- return System.Text.RegularExpressions.Regex.IsMatch(Serial, chk);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement