
Смышленный
  
Профиль
Группа: Завсегдатай
Сообщений: 1915
Регистрация: 24.4.2006
Где: Планета Земля
Репутация: 7 Всего: 38
|
Вот исходный код в C++: Код | //============================================================================================================================ // inline int VersionCodeInt (){ return VersionId * 100 + VersionMajor; } inline int alpha2int ( chr c ){ if( c.digit) return c.code - 0x30; else if( c.alpha ) return c.code - 0x41 + 10; return -1; } inline chr int2alpha ( int n ){ if( n < 10 ) return chr ( char ( n + 0x30 ) ); else if( n < 36 ) return chr ( char ( n + 0x41 - 10 ) ); return ' '; } //============================================================================================================================ // inline chr table_decode ( chr c ){ const str mask = "IEPAJCGBMW4UKXS2T0YRDZ37VN98OH6Q1LF5"; int nn = mask.size; int a = VersionCodeInt () % nn; int n = alpha2int (c); if( n < 0 || 35 < n ) return c; return int2alpha ( ( alpha2int ( mask [ n % nn ] ) + nn - a ) % nn ); } //============================================================================================================================ const int exptable [NN][NN][2] = { 32768, 0, 32768, 0, 32768, 0, 32768, 0, 32768, 0, 32768, 0, 32768, 0, 32768, 0, 32768, 0, 23170, 23170, 0, 32768, -23170, 23170, -32768, 0, -23170, -23170, 0, -32768, 23170, -23170, 32768, 0, 0, 32768, -32768, 0, 0, -32768, 32768, 0, 0, 32768, -32768, 0, 0, -32768, 32768, 0, -23170, 23170, 0, -32768, 23170, 23170, -32768, 0, 23170, -23170, 0, 32768, -23170, -23170, 32768, 0, -32768, 0, 32768, 0, -32768, 0, 32768, 0, -32768, 0, 32768, 0, -32768, 0, 32768, 0, -23170, -23170, 0, 32768, 23170, -23170, -32768, 0, 23170, 23170, 0, -32768, -23170, 23170, 32768, 0, 0, -32768, -32768, 0, 0, 32768, 32768, 0, 0, -32768, -32768, 0, 0, 32768, 32768, 0, 23170, -23170, 0, -32768, -23170, -23170, -32768, 0, -23170, 23170, 0, 32768, 23170, 23170, }; const int srctable [36][2] = { -32768, 0, -32241, -5850, -30678, -11513, -28129, -16806, -24676, -21559, -20430, -25619, -15527, -28855, -10125, -31164, -4398, -32471, 1470, -32735, 7291, -31946, 12878, -30131, 18051, -27347, 22644, -23684, 26509, -19260, 29522, -14217, 31587, -8717, 32636, -2937, 32636, 2937, 31587, 8717, 29522, 14217, 26509, 19260, 22644, 23684, 18051, 27347, 12878, 30131, 7291, 31946, 1470, 32735, -4398, 32471, -10125, 31164, -15527, 28855, -20430, 25619, -24676, 21559, -28129, 16806, -30678, 11513, -32241, 5850, -32768, 0, }; //============================================================================================================================ // inline int check ( const str & key ) { typedef imp::complex<int> complex; const int nn = NN; const int mm = 36;
array<int> code; for( int n=0; n<key.size; n++ ){ int c = alpha2int ( table_decode ( key [n] ) ); if( c >= 0 && c <= 35 ) code += c; }; if( code.size != nn ) return -1; code [0] = alpha2int ( 'I' );
array<complex> dft; dft.size = nn; for( int n=0; n<nn; n++ ) dft [n] = complex ( srctable [ code [n] ][0], srctable [ code [n] ][1] );
array<complex> dst; dst.size = nn; for( int x=0; x<nn; x++ ){ complex c (0,0); for( int n=0; n<nn; n++ ) c += dft [n] * complex ( exptable [x][n][0], exptable [x][n][1] ).conjugate () / (256*256/2); dst [x] = c / (256*256/2); }
int nonzeroes = 0; for( int n=0; n<nn; n++ ) if( dst [n].im != 0 ) nonzeroes++; return nonzeroes; }
|
Это код проверки ключа программы на валидность. Переношу в Delphi, получаю следующее: Код | const srctable: array[0..35, 0..1] of Integer = ( (-32768, 0), (-32241, -5850), (-30678, -11513), (-28129, -16806), (-24676, -21559), (-20430, -25619), (-15527, -28855), (-10125, -31164), (-4398, -32471), (1470, -32735), (7291, -31946), (12878, -30131), (18051, -27347), (22644, -23684), (26509, -19260), (29522, -14217), (31587, -8717), (32636, -2937), (32636, 2937), (31587, 8717), (29522, 14217), (26509, 19260), (22644, 23684), (18051, 27347), (12878, 30131), (7291, 31946), (1470, 32735), (-4398, 32471), (-10125, 31164), (-15527, 28855), (-20430, 25619), (-24676, 21559), (-28129, 16806), (-30678, 11513), (-32241, 5850), (-32768, 0) );
exptable: array[0..7, 0..7, 0..1] of Integer = ( ((32768, 0), (32768, 0), (32768, 0), (32768, 0), (32768, 0), (32768, 0), (32768, 0), (32768, 0)), ((32768, 0), (23170, 23170), (0, 32768), (-23170, 23170), (-32768, 0), (-23170, -23170), (0, -32768), (23170, -23170)), ((32768, 0), (0, 32768), (-32768, 0), (0, -32768), (32768, 0), (0, 32768), (-32768, 0), (0, -32768)), ((32768, 0), (-23170, 23170), (0, -32768), (23170, 23170), (-32768, 0), (23170, -23170), (0, 32768), (-23170, -23170)), ((32768, 0), (-32768, 0), (32768, 0), (-32768, 0), (32768, 0), (-32768, 0), (32768, 0), (-32768, 0)), ((32768, 0), (-23170, -23170), (0, 32768), (23170, -23170), (-32768, 0), (23170, 23170), (0, -32768), (-23170, 23170)), ((32768, 0), (0, -32768), (-32768, 0), (0, 32768), (32768, 0), (0, -32768), (-32768, 0), (0, 32768)), ((32768, 0), (23170, -23170), (0, -32768), (-23170, -23170), (-32768, 0), (-23170, 23170), (0, 32768), (23170, 23170)) );
type TComplex = record a, b: Integer; end;
function alpha2int(ACh: Char): Integer; begin if (ACh >= '0') and (ACh <= '9') then Result := Ord(ACh) - 48 else Result := Ord(ACh) - 55; end;
function int2alpha(n: Integer): Char; begin Result := ' '; if n < 10 then Result := Chr(n + 48) else if n < 36 then Result := Chr(n + 55); end;
function table_decode(ACh: Char): Char; const mask = 'IEPAJCGBMW4UKXS2T0YRDZ37VN98OH6Q1LF5'; nn = Length(mask); var a, n: Integer; begin a := (VersionId * 100 + VersionMajor) mod nn; n := alpha2int(ACh); if (n < 0) or (n > 35) then Result := ACh else Result := int2alpha((alpha2int(mask[ n mod nn ]) + nn - a) mod nn); end;
function Complex(a, b: Integer): TComplex; begin Result.a := a; Result.b := b; end;
procedure C_Add(var a, b: TComplex); begin a.a := a.a + b.a; a.b := a.b + b.b; end;
function C_MulF(a, b: TComplex): TComplex; begin result.a := a.a * b.a - a.b * b.b; result.b := a.a * b.b + a.b * b.a; end;
procedure C_Div(var a: TComplex; b: Integer); begin a.a := a.a div b; a.b := a.b div b; end;
function C_Conj(a: TComplex): TComplex; begin Result := a; Result.b := -Result.b; end;
function CheckKey(AKey: string): Boolean; const mm = 36; var Idx, n: Integer; c: Integer; cc, d: TComplex; code: array of Integer; dft, dst: array of TComplex; nn: Integer; begin Result := True; nn := Length(AKey); SetLength(code, 0); SetLength(dft, nn); SetLength(dst, nn); try for Idx := 1 to nn do begin c := alpha2int(table_decode(AKey[Idx])); if (c >= 0) and (c <= 35) then begin SetLength(code, Length(code) + 1); code[Length(code) - 1] := c; end; end; if Length(code) <> nn then begin Result := False; Exit; end; code[0] := alpha2int('I'); for Idx := 0 to nn - 1 do dft[Idx] := Complex(srctable[code[Idx], 0], srctable[code[Idx], 1]); for Idx := 0 to nn - 1 do begin cc := Complex(0, 0); for n := 0 to nn - 1 do begin d := C_MulF(dft[n], C_Conj(Complex(exptable [Idx, n, 0], exptable [Idx, n, 1]))); C_Div(d, 32768); C_Add(cc, d); end; C_Div(cc, 32768); dst[Idx] := cc; end; for Idx := 0 to nn - 1 do if dst[Idx].b <> 0 then begin Result := False; Break; end; finally SetLength(code, 0); SetLength(dft, 0); SetLength(dst, 0); end; end;
|
Вроде и ошибок нет, а код все-равно работает иначе...
|