Guest User

Untitled

a guest
Dec 26th, 2016
492
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 4.65 KB | None | 0 0
  1. unit Main;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs, StdCtrls,StrUtils;
  8.  
  9. type
  10.   TMainForm = class(TForm)
  11.     Generate: TButton;
  12.     Key1: TEdit;
  13.     Key2: TEdit;
  14.     Key3: TEdit;
  15.     Key4: TEdit;
  16.     procedure GenerateClick(Sender: TObject);
  17.   private
  18.     { Private declarations }
  19.   public
  20.     { Public declarations }
  21.   end;
  22.  
  23. var
  24.   MainForm: TMainForm;
  25.  
  26. implementation
  27.  
  28. {$R *.dfm}
  29.  
  30. function ShiftLeft(Value: LongWord): LongWord; register; overload;
  31. asm
  32.   shl eax,5
  33. end;
  34.  
  35. procedure TMainForm.GenerateClick(Sender: TObject);
  36. const
  37.   SpecString='QETYFIWCOPASBNGHJZURKDLXVM1234567890';
  38. var
  39.   Crc:integer;
  40.   i,current:integer;
  41.   DepOnSym:integer;
  42.   SymPos:integer;
  43.   FirstPart,Step5,SecondPart,FullKey:string;
  44.   Step1,Step2,Step3,Step35,Step4:integer;
  45. begin
  46.   SecondPart:='';
  47.   current:=0;
  48.   DepOnSym:=0;
  49.   crc:=$001773D8;
  50.   SymPos:=Random(36); //с помощью функции рэндом мы сгенерируем позицию для символа
  51.   FirstPart:=Copy(SpecString,SymPos,1)+Copy(SpecString,SymPos,1)+Copy(SpecString,SymPos,1)+Copy(SpecString,SymPos,1);
  52. //Здесь мы определяем по набору символов то, какое число нужно отнимать в шаге 35
  53.   if (Pos('M',FirstPart) <> 0) or (Pos('0',FirstPart) <> 0)
  54.   or (Pos('5',FirstPart) <> 0) or (Pos('Q',FirstPart) <> 0)
  55.   or (Pos('A',FirstPart) <> 0) or (Pos('I',FirstPart) <> 0)
  56.   or (Pos('H',FirstPart) <> 0) or (Pos('K',FirstPart) <> 0) then
  57.   begin
  58.     DepOnSym:=0;
  59.   end
  60.   else
  61.   if (Pos('1',FirstPart) <> 0) or (Pos('6',FirstPart) <> 0)
  62.   or (Pos('E',FirstPart) <> 0) or (Pos('W',FirstPart) <> 0)
  63.   or (Pos('S',FirstPart) <> 0) or (Pos('J',FirstPart) <> 0)
  64.   or (Pos('D',FirstPart) <> 0) then
  65.   begin
  66.     DepOnSym:=1;
  67.   end
  68.   else
  69.   if (Pos('2',FirstPart) <> 0) or (Pos('7',FirstPart) <> 0)
  70.   or (Pos('T',FirstPart) <> 0) or (Pos('C',FirstPart) <> 0)
  71.   or (Pos('Z',FirstPart) <> 0) or (Pos('B',FirstPart) <> 0)
  72.   or (Pos('L',FirstPart) <> 0) then
  73.   begin
  74.     DepOnSym:=2;
  75.   end
  76.   else
  77.   if (Pos('3',FirstPart) <> 0) or (Pos('8',FirstPart) <> 0)
  78.   or (Pos('Y',FirstPart) <> 0) or (Pos('O',FirstPart) <> 0)
  79.   or (Pos('N',FirstPart) <> 0) or (Pos('U',FirstPart) <> 0)
  80.   or (Pos('X',FirstPart) <> 0) then
  81.   begin
  82.     DepOnSym:=3;
  83.   end
  84.   else
  85.   if (Pos('4',FirstPart) <> 0) or (Pos('9',FirstPart) <> 0)
  86.   or (Pos('F',FirstPart) <> 0) or (Pos('P',FirstPart) <> 0)
  87.   or (Pos('G',FirstPart) <> 0) or (Pos('R',FirstPart) <> 0)
  88.   or (Pos('V',FirstPart) <> 0) then
  89.   begin
  90.     DepOnSym:=4;
  91.   end;
  92.  /////////////////////////////////////////////////////////////////////////////
  93.   inc(crc,Sympos);
  94.   for i := 0 to 11 do
  95.   begin
  96.     inc(current); //начинаем с первого (точнее пятого) символа
  97.     Step1:=current+crc; //прибавляем к нему crc от первых 4ех
  98.     Step2:=ShiftLeft(Step1); //сдвигаем
  99.     Step3:=Step1+Step2; //суммируем предыдущие результаты
  100.     Step35:=Step3-DepOnSym;
  101.     Step4:=Step35 mod 36; //делим на кол-во символов в SpecString и получаем остаток
  102.     Step5:=Copy(SpecString,Step4+1,1); //извлекаем нужный символ
  103.     SecondPart:=SecondPart+Step5; //собираем вторую часть
  104.   end;
  105.   //А здесь то, каким образом формировать конечный ключ
  106.   if (Pos('1',FirstPart) <> 0) or (Pos('6',FirstPart) <> 0)
  107.   or (Pos('E',FirstPart) <> 0) or (Pos('W',FirstPart) <> 0)
  108.   or (Pos('S',FirstPart) <> 0) or (Pos('J',FirstPart) <> 0)
  109.   or (Pos('D',FirstPart) <> 0) then
  110.   begin
  111.     FullKey:= FirstPart+Copy(SecondPart,12,1)+Copy(SecondPart,10,1)
  112.     +Copy(SecondPart,8,1)+Copy(SecondPart,6,1)+Copy(SecondPart,4,1)
  113.     +ReverseString(Copy(SecondPart,1,2))+Copy(SecondPart,3,1)
  114.     +Copy(SecondPart,5,1)+Copy(SecondPart,7,1)+Copy(SecondPart,9,1)
  115.     +Copy(SecondPart,11,1)
  116.   end
  117.   else
  118.   if (Pos('3',FirstPart) <> 0) or (Pos('8',FirstPart) <> 0)
  119.   or (Pos('Y',FirstPart) <> 0) or (Pos('O',FirstPart) <> 0)
  120.   or (Pos('N',FirstPart) <> 0) or (Pos('U',FirstPart) <> 0)
  121.   or (Pos('X',FirstPart) <> 0) then
  122.   begin
  123.     FullKey:=FirstPart+ReverseString(Copy(SecondPart,10,3))+ReverseString(Copy(SecondPart,6,3))
  124.     +ReverseString(Copy(SecondPart,3,2))+ReverseString(Copy(SecondPart,1,2))
  125.     +Copy(SecondPart,5,1)+Copy(SecondPart,9,1)
  126.   end
  127.   else
  128.   begin
  129.     FullKey:=FirstPart+ReverseString(SecondPart);
  130.   end;
  131.   Key1.text:=Copy(FullKey,1,4);
  132.   Key2.text:=Copy(FullKey,5,4);
  133.   Key3.text:=Copy(FullKey,9,4);
  134.   Key4.text:=Copy(FullKey,13,4);
  135. end;
  136.  
  137. end.
Advertisement
Add Comment
Please, Sign In to add comment