unit FunctionPas;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;
const
  LockKey: Word = 13;
  BegKey: Integer = 53523;
  EndKey: Integer = 32768;

type
  TCPUID = array[1..4] of Longint;
  TVendor = array[0..11] of char;

function TransChar(AChar: char): Integer;
function StrToHex(AStr: string): string;
function HexToStr(AStr: string): string;

function EncrypKey(const S: string): string;
function UncrypKey(const S: string): string;

implementation

function EncrypKey(const S: string): string;
var
  i: Integer;
  Key: Word;
begin
  Result := S;
  Key := LockKey;
  for i := 1 to Length(S) do
  begin
    Result[i] := char(Byte(S[i]) xor (Key shr 8));
    Key := (Byte(Result[i]) + Key) * BegKey + EndKey;
    if Result[i] = Chr(0) then
      Result[i] := S[i];
  end;
  Result := StrToHex(Result);
end;

function UncrypKey(const S: string): string;
var
  i: Integer;
  Key: Word;
  S1: string;
begin
  Key := LockKey;
  S1 := HexToStr(S);
  Result := S1;
  for i := 1 to Length(S1) do
  begin
    if char(Byte(S1[i]) xor (Key shr 8)) = Chr(0) then
    begin
      Result[i] := S1[i];
      Key := (Byte(Chr(0)) + Key) * BegKey + EndKey;
    end
    else begin
      Result[i] := char(Byte(S1[i]) xor (Key shr 8));
      Key := (Byte(S1[i]) + Key) * BegKey + EndKey;
    end;
  end;
end;
function TransChar(AChar: char): Integer;
begin
  if AChar in ['0'..'9'] then
    Result := Ord(AChar) - Ord('0')
  else
    Result := 10 + Ord(AChar) - Ord('A');
end;

function StrToHex(AStr: string): string;
var
  i: Integer;
begin
  Result := '';

  for i := 1 to Length(AStr) do
    Result := Result + IntToHex(Byte(AStr[i]), 2);
end;

function HexToStr(AStr: string): string;
var
  i: Integer;
  CharValue: Word;
begin
  Result := '';
  for i := 1 to Trunc(Length(AStr) / 2) do
  begin
    Result := Result + ' ';
    CharValue := TransChar(AStr[2 * i - 1]) * 16 + TransChar(AStr[2 * i]);
    Result[i] := char(CharValue);
  end;
end;

end.