一个只有17K的Delphi字符串加密程序源码

2008-04-09 04:20:56来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

program Window;

{
This is an example of making an application
without using the Forms unit. Forms.pas is the
Delphi unit that makes your programs so damn
huge! Forms.pas has all the code for translating
the forms you create with Delphi w/components
into windows. If you ask me, anything that adds
200k(@%#$!) to your app has got to be some damn
inefficient code.

GoRDy <gfody@jps.net>
www.jps.net/gfody
}


uses Windows, Messages;

{$R *.RES}

var
wClass: TWndClass; // class struct for main window
hFont, // handle of font
hInst, // handle of program (hinstance)
Handle, // handle of main window
hEncrypt, // handle of encrypt button
hDecrypt, // handle of decrypt button
hEdit, // handle of main edit
hLabel, // handle of password label
hPW: HWND; // handle of password edit
Msg: TMSG; // message struct
dEncrypt,
dDecrypt: Pointer; // default button procedures

(*------------------------------------------------*)

// This lines everything up
procedure Resize;
var
RCT:TRect;
begin
GetWindowRect(Handle,RCT);
MoveWindow(hPW,230,5,RCT.Right-RCT.Left-245,24,True);
MoveWindow(hEdit,5,34,RCT.Right-RCT.Left-20,RCT.Bottom-RCT.Top-66,True);
end;

(*------------------------------------------------*)

// This is to cleanup and stop the program
procedure ShutDown;
begin
DeleteObject(hFont);
UnRegisterClass(''''Sample Class'''',hInst);
ExitProcess(hInst); //end program
end;

(*------------------------------------------------*)

// Decrypts the text in hEdit with the text in hPW
procedure Decrypt;
var
x,i, // count variables
sText,sPW: Integer; // size of Text, PW
Text,PW: PChar; // buffer for Text, PW
begin
sText:=GetWindowTextLength(hEdit) 1;
sPW:=GetWindowTextLength(hPW) 1;
GetMem(Text,sText);
GetMem(PW,sPW);
GetWindowText(hEdit,Text,sText);
GetWindowText(hPW,PW,sPW);
x:=0; // initialize count
for i:=0 to sText-2 do
begin
Text[i]:=Chr(Ord(Text[i])-Ord(PW[x]));
Inc(x);
if x=(sPW-1)then x:=0;
end;
SetWindowText(hEdit,Text);
FreeMem(Text);
FreeMem(PW);
end;

(*------------------------------------------------*)

// Encrypts the text in hEdit with the text in hPW
procedure Encrypt;
var
x,i, // count variables
sText,sPW: Integer; // size of Text, PW
Text,PW: PChar; // buffer for Text, PW
begin
sText:=GetWindowTextLength(hEdit) 1;
sPW:=GetWindowTextLength(hPW) 1;
GetMem(Text,sText);
GetMem(PW,sPW);
GetWindowText(hEdit,Text,sText);
GetWindowText(hPW,PW,sPW);
x:=0; // initialize count
for i:=0 to sText-2 do
begin
Text[i]:=Chr(Ord(Text[i]) Ord(PW[x]));
Inc(x);
if x=(sPW-1)then x:=0;
end;
SetWindowText(hEdit,Text);
FreeMem(Text);
FreeMem(PW);
end;

(*------------------------------------------------*)

// This function processes every message sent to the Encrypt Button
function EncryptProc(hWnd,Msg,wParam,lParam:Longint):Longint; stdcall;
var
i: Integer;
begin
// Always pass the message to the Default procedure
Result:=CallWindowProc(dEncrypt,hWnd,Msg,wParam,lParam);

case Msg of
// If the user presses TAB we''''re gunna switch the
// focus over to the Decrypt button.
WM_KEYDOWN: if wParam=9 then SetFocus(hDecrypt);
end;

end;

(*------------------------------------------------*)

// This function processes every message sent to the Decrypt Button
function DecryptProc(hWnd,Msg,wParam,lParam:Longint):Longint; stdcall;
begin
// Always pass the message to the Default procedure
Result:=CallWindowProc(dEncrypt,hWnd,Msg,wParam,lParam);

case Msg of
// if the user presses TAB we''''re gunna switch
// the focus back to the Encrypt button.
WM_KEYDOWN: if wParam=9 then SetFocus(hEncrypt);
end;

end;

(*------------------------------------------------*)

// This function processes every message sent to our Main window
function WindowProc(hWnd,Msg,wParam,lParam:Longint):Longint; stdcall;
begin
// Always pass the message to the Default procedure
Result:=DefWindowProc(hWnd,Msg,wParam,lParam);

case Msg of
WM_SIZE: Resize;
// When buttons are clicked the message is passed to
// the parent window, so we handle it here.
WM_COMMAND: if lParam=hEncrypt then Encrypt
else if lParam=hDecrypt then Decrypt;
WM_DESTROY: ShutDown;
end;

end;

(*------------------------------------------------*)

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:Create为什么可以为虚函数?

下一篇:TWebBrowser的常见属性和方法