引用上面这些单元后,加数函数,就变随机数了..这是怎么回事???(20分)

  • 主题发起人 主题发起人 jgame
  • 开始时间 开始时间
J

jgame

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, DB, ADODB, fcdbtreeview, dxtree, dxdbtree,
ImgList, Mask, DBCtrls, Menus, strutils;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation



{$R *.dfm}

function Encrypt(Src: String
Key: string):String;
var
KeyLen :Integer;
KeyPos :Integer;
offset :Integer;
dest :string;
SrcPos :Integer;
SrcAsc :Integer;
Range :Integer;
begin
KeyLen:=Length(Key);
if KeyLen = 0 then
key:='Think Space';
KeyPos:=0;
Range:=256;
Randomize;
offset:=Random(Range);
dest:=format('%1.2x',[offset]);
for SrcPos := 1 to Length(Src) do
begin
SrcAsc:=(Ord(Src[SrcPos]) + offset) MOD 255;
if KeyPos < KeyLen then
KeyPos:= KeyPos + 1 else KeyPos:=1;
SrcAsc:= SrcAsc xor Ord(Key[KeyPos]);
dest:=dest + format('%1.2x',[SrcAsc]);
offset:=SrcAsc;
end;
Result:=Dest;
end;
//////////////////////////////////////

procedure TForm1.Button1Click(Sender: TObject);
var s:string;
begin
s:='111111';
showmessage(Encrypt(s,'12635'));
end;

end.


{
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, DB, ADODB, fcdbtreeview, dxtree, dxdbtree,
ImgList, Mask, DBCtrls, Menus, strutils;
引用上面这些单元后,
加数函数,
Encrypt(s,'12635');
就变随机数了..

点一下变一个.
这是怎么回事???

请高手指教一下.
}
 
Randomize;
offset:=Random(Range);
这里本身就用随机数做计算的啊?
 
贴错了,已改正;
各位再看看.

function Encrypt(Src: String
Key: string):String;
var
KeyLen :Integer;
KeyPos :Integer;
offset :Integer;
dest :string;
SrcPos :Integer;
SrcAsc :Integer;
Range :Integer;
begin
KeyLen:=Length(Key);
if KeyLen = 0 then
key:='Think Space';
KeyPos:=0;
Range:=256;
Randomize;
offset:=Random(Range);
dest:=format('%1.2x',[offset]);
for SrcPos := 1 to Length(Src) do
begin
SrcAsc:=(Ord(Src[SrcPos]) + offset) MOD 255;
if KeyPos < KeyLen then
KeyPos:= KeyPos + 1 else KeyPos:=1;
SrcAsc:= SrcAsc xor Ord(Key[KeyPos]);
dest:=dest + format('%1.2x',[SrcAsc]);
offset:=SrcAsc;
end;
Result:=Dest;
end;
 
原来就是动态啊..结贴了.
 
接受答案了.
 
后退
顶部