1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| function TForm1.DecodeMSKey(const HexSrc: array of byte): string;
const
StartOffset: integer = $34; // Offset 34 = Array[52]
EndOffset: integer = $34 + 15; // Offset 34 + 15(Bytes) = Array[64]
Digits: array[0..23] of char =
('B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'M', 'P', 'Q', 'R', 'T',
'V', 'W', 'X', 'Y', '2', '3', '4', '6', '7', '8', '9');
DecodedLen: integer = 29; // Length of Decoded Product Key
EncodedLen: integer = 15;
// Length of Encoded Product Key in Bytes (An total of 30 in chars)
var
HexDigitalPID: array of cardinal;
Des: array[0..30] of char; // Length of Decoded Product Key + 1
I: integer;
N: integer;
HN: cardinal;
Value: cardinal;
begin
Result := '';
SetLength(HexDigitalPID, DecodedLen);
for I := StartOffset to EndOffset do
HexDigitalPID[I - StartOffSet] := HexSrc[I];
// SetLength(Des, DecodedLen + 1);
for I := DecodedLen - 1 downto 0 do
if (((I + 1) mod 6) = 0) then
Des[I] := '-'
else
begin
HN := 0;
for N := EncodedLen - 1 downto 0 do
begin
Value := (HN shl 8) or HexDigitalPID[N];
HexDigitalPID[N] := Value div 24;
HN := Value mod 24;
end;
Des[I] := Digits[HN];
end;
Des[DecodedLen] := Chr(0);
// For I := 0 To Length(Des) Do
// begin
// Result := Result + Des[I];
// end;
Result := StrPas(Des);
end; |
Partager