Advertisement
Guest User

Untitled

a guest
Oct 7th, 2011
462
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.38 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. using System.Windows.Forms;
  6.  
  7. namespace CodeLock
  8. {
  9.     public class Key
  10.     {
  11.         public string GenerateSerial()
  12.         {
  13.             string serial = "";
  14.  
  15.             Random ran = new Random();
  16.             long key = ran.Next(0, 60466175);
  17.  
  18.             List<List<string>> lst = new List<List<string>>();
  19.  
  20.             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" };
  21.             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" };
  22.             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" };
  23.             string[] arr4 = { "0", "2", "4", "6", "8", "A", "C", "E", "G", "I", "K", "M", "O", "Q", "S", "U", "W", "Y" };
  24.             string[] arr5 = { "0", "1", "2", "6", "7", "8", "A", "B", "C", "G", "H", "I", "M", "N", "O", "S", "T", "U", "Y", "Z" };
  25.             string[] arr6 = { "L", "X", "M", "N", "T", "O", "P", "U", "V", "Q", "W", "A", "K", "0", "2", "4", "5", "6", "8", "9" };
  26.             string[] arr7 = { "N", "T", "O", "S", "P", "R", "I", "E", "L", "X", "Q", "Z", "C", "B", "H", "8", "7", "2", "1", "6", "0", "3" };
  27.             string[] arr8 = { "L", "S", "D", "M", "N", "O", "Q", "R", "S", "N", "V", "Q", "Y", "Q", "K", "X", "C", "A", "4", "5", "9", "2" };
  28.             string[] arr9 = { "9", "7", "6", "4", "3", "1", "Q", "E", "T", "U", "O", "A", "S", "F", "H", "K", "Z", "C", "B", "M" };
  29.             string[] arr10 = { "9", "8", "7", "3", "2", "1", "5", "5", "5", "W", "R", "Y", "I", "P", "S", "F", "H", "K", "Z", "C", "B", "M" };
  30.             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" };
  31.             string[] arr12 = { "Q", "A", "Z", "E", "D", "C", "T", "G", "B", "U", "J", "M", "O", "L", "7", "4", "5", "6", "3", "2" };
  32.             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" };
  33.             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" };
  34.             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" };
  35.             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" };
  36.             string[] arr17 = { "O", "I", "U", "T", "G", "B", "C", "X", "Z", "Q", "W", "E", "R", "F", "V", "B", "N", "M" };
  37.             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" };
  38.             string[] arr19 = { "L", "I", "A", "M", "I", "S", "C", "O", "O", "L", "I", "S", "N", "T", "H", "E", "3", "3", "3" };
  39.             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" };
  40.  
  41.             lst.Add(new List<string>(arr1));
  42.             lst.Add(new List<string>(arr2));
  43.             lst.Add(new List<string>(arr3));
  44.             lst.Add(new List<string>(arr4));
  45.             lst.Add(new List<string>(arr5));
  46.             lst.Add(new List<string>(arr6));
  47.             lst.Add(new List<string>(arr7));
  48.             lst.Add(new List<string>(arr8));
  49.             lst.Add(new List<string>(arr9));
  50.             lst.Add(new List<string>(arr10));
  51.             lst.Add(new List<string>(arr11));
  52.             lst.Add(new List<string>(arr12));
  53.             lst.Add(new List<string>(arr13));
  54.             lst.Add(new List<string>(arr14));
  55.             lst.Add(new List<string>(arr15));
  56.             lst.Add(new List<string>(arr16));
  57.             lst.Add(new List<string>(arr17));
  58.             lst.Add(new List<string>(arr18));
  59.             lst.Add(new List<string>(arr19));
  60.             lst.Add(new List<string>(arr20));
  61.  
  62.             serial = CConvert.ToBase36((int)key, 36);
  63.  
  64.             while (!(serial.Length >= 5))
  65.             {
  66.                 serial = "0" + serial;
  67.             }
  68.  
  69.             Random r1 = new Random((int)key);
  70.  
  71.             int x = 0;
  72.             while (!(serial.Length == 29))
  73.             {
  74.                 x = serial.Length;
  75.  
  76.                 if (x % 6 == 5)
  77.                 {
  78.                     serial += "-";
  79.                 }
  80.                 else
  81.                 {
  82.                     serial += lst[x - (5 + (x + 1) / 6)][r1.Next(0, lst[x - (5 + (x + 1) / 6)].Count - 1)];
  83.                 }
  84.             }
  85.             return serial;
  86.         }
  87.  
  88.         public bool ValidateCode(string Serial)
  89.         {
  90.             Random ran = new Random();
  91.  
  92.             char[] charsToTrim = { '!', '"', '£', '$', '%', '^', '&', '*', '(', ')', '_', '+', '=', '[', ']', '{', '}',
  93.                                    ';', ':', '\'', '@', '#', '~', '<', '>', ',', '.', '?', '/', '\\', '|', '`', '¬' };
  94.  
  95.             Serial = Serial.Trim();
  96.             Serial = Serial.Trim(charsToTrim);
  97.  
  98.             if (!(Serial.Length == 29))
  99.                 return false;
  100.  
  101.             List<List<string>> lst = new List<List<string>>();
  102.  
  103.             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" };
  104.             string[] arr5 = { "0", "1", "2", "6", "7", "8", "A", "B", "C", "G", "H", "I", "M", "N", "O", "S", "T", "U", "Y", "Z" };
  105.             string[] arr9 = { "9", "7", "6", "4", "3", "1", "Q", "E", "T", "U", "O", "A", "S", "F", "H", "K", "Z", "C", "B", "M" };
  106.             string[] arr10 = { "9", "8", "7", "3", "2", "1", "5", "5", "5", "W", "R", "Y", "I", "P", "S", "F", "H", "K", "Z", "C", "B", "M" };
  107.             string[] arr19 = { "L", "I", "A", "M", "I", "S", "C", "O", "O", "L", "I", "S", "N", "T", "H", "E", "3", "3", "3" };
  108.  
  109.             lst.Add(new List<string>(arr1));
  110.             lst.Add(new List<string>());
  111.             lst.Add(new List<string>());
  112.             lst.Add(new List<string>());
  113.             lst.Add(new List<string>(arr5));
  114.             lst.Add(new List<string>());
  115.             lst.Add(new List<string>());
  116.             lst.Add(new List<string>());
  117.             lst.Add(new List<string>(arr9));
  118.             lst.Add(new List<string>(arr10));
  119.             lst.Add(new List<string>());
  120.             lst.Add(new List<string>());
  121.             lst.Add(new List<string>());
  122.             lst.Add(new List<string>());
  123.             lst.Add(new List<string>());
  124.             lst.Add(new List<string>());
  125.             lst.Add(new List<string>());
  126.             lst.Add(new List<string>());
  127.             lst.Add(new List<string>(arr19));
  128.             lst.Add(new List<string>());
  129.  
  130.             Random r1 = null;
  131.  
  132.             try
  133.             {
  134.                 r1 = new Random((int)CConvert.FromBase36(Serial.Substring(0, 5)));
  135.             }
  136.             catch
  137.             {
  138.                 return false;
  139.             }
  140.  
  141.             int x = 0;
  142.             string chk = Serial.Substring(0, 5);
  143.  
  144.             while (!(chk.Length == 29))
  145.             {
  146.                 x = chk.Length;
  147.  
  148.                 if (x % 6 == 5)
  149.                 {
  150.                     chk += "-";
  151.                 }
  152.                 else
  153.                 {
  154.                     if (lst[x - (5 + (x + 1) / 6)].Count == 0)
  155.                     {
  156.                         chk += ".";
  157.                         r1.Next(0, 1);
  158.                     }
  159.                     else
  160.                     {
  161.                         chk += lst[x - (5 + (x + 1) / 6)][r1.Next(0, lst[x - (5 + (x + 1) / 6)].Count - 1)];
  162.                     }
  163.                 }
  164.             }
  165.             return System.Text.RegularExpressions.Regex.IsMatch(Serial, chk);
  166.         }
  167.     }
  168. }
  169.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement