|
안녕하세요! 매직 입니다.
프로그램 배포 하기전에 시리얼 번호 만들어서 배포 하려고 합니다.
자료를 찾다보니 델파로 된 자료가 있는데요, 델파이를 잘 몰라서요!
빌더로 컨버팅 좀 부탁드립니다.
소스 내용을 올립니다.
델마당에 박후선님의 강좌에서 가지고 왔습니다.
//-------------------------------------------------------------------------
unit UEncrypt;
interface
function Encrypt(const S: String; Key: Word): String;
function Decrypt(const S: String; Key: Word): String;
implementation
uses SysUtils;
const
C1 = 74102;
C2 = 12337;
HexaChar : array [0..15] of Char =
( '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F' );
// Byte로 구성된 데이터를 Hexadecimal 문자열로 변환
function ValueToHex(const S : String): String;
var
I : Integer;
begin
SetLength(Result, Length(S)*2); // 문자열 크기를 설정
for I := 0 to Length(S)-1 do
begin
Result[(I*2)+1] := HexaChar[Integer(S[I+1]) shr 4];
Result[(I*2)+2] := HexaChar[Integer(S[I+1]) and $0f];
end;
end;
// Hexadecimal로 구성된 문자열을 Byte 데이터로 변환
function HexToValue(const S : String) : String;
var
I : Integer;
begin
SetLength(Result, Length(S) div 2);
for I := 0 to (Length(S) div 2) - 1 do
begin
Result[I+1] := Char(StrToInt('$'+Copy(S,(I*2)+1, 2)));
end;
end;
// 암호걸기
function Encrypt(const S: String; Key: Word): String;
var
I: byte;
FirstResult : String;
begin
SetLength(FirstResult, Length(S)); // 문자열의 크기를 설정
for I := 1 to Length(S) do begin
FirstResult[I] := char(byte(S[I]) xor (Key shr 8));
Key := (byte(FirstResult[I]) + Key) * C1 + C2;
end;
Result := ValueToHex(FirstResult);
end;
// 암호풀기
function Decrypt(const S: String; Key: Word): String;
var
I: byte;
FirstResult : String;
begin
FirstResult := HexToValue(S);
SetLength( Result, Length(FirstResult) );
for I := 1 to Length(FirstResult) do
begin
Result[I] := char(byte(FirstResult[I]) xor (Key shr 8));
Key := (byte(FirstResult[I]) + Key) * C1 + C2;
end;
end;
end.
//-------------------------------------------------------------------------------
unit UTest;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
ESource: TEdit;
BEncrypt: TButton;
Label1: TLabel;
Label2: TLabel;
EEncryptResult: TEdit;
EDecryptResult: TEdit;
Label3: TLabel;
BDecrypt: TButton;
procedure BEncryptClick(Sender: TObject);
procedure BDecryptClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses UEncrypt;
{$R *.DFM}
procedure TForm1.BEncryptClick(Sender: TObject);
begin
EEncryptResult.Text := Encrypt( ESource.Text, 13579 );
end;
procedure TForm1.BDecryptClick(Sender: TObject);
begin
EDecryptResult.Text := Decrypt( EEncryptResult.Text, 13579);
end;
end.
//-----------------------------------------------------------------------
감사합니다.
|