function encrypt_str(Src: string; Key: string; Encrypt: Boolean; m_brand: boolean = true): string;
var
idx: integer;
KeyLen: Integer;
KeyPos: Integer;
offset: Integer;
dest: string;
SrcPos: Integer;
SrcAsc: Integer;
TmpSrcAsc: Integer;
Range: Integer;
begin
try
KeyLen := Length(Key);
if KeyLen = 0 then key := 'wangy lsy dmp';
KeyPos := 0;
SrcPos := 0;
SrcAsc := 0;
Range := 256;
if Encrypt then
begin
Randomize;
offset := 18;
if m_brand then
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;
end
else
begin
offset := StrToInt('$' + copy(src, 1, 2));
SrcPos := 3;
repeat
SrcAsc := StrToInt('$' + copy(src, SrcPos, 2));
if KeyPos < KeyLen then KeyPos := KeyPos + 1 else KeyPos := 1;
TmpSrcAsc := SrcAsc xor Ord(Key[KeyPos]);
if TmpSrcAsc <= offset then
TmpSrcAsc := 255 + TmpSrcAsc - offset
else
TmpSrcAsc := TmpSrcAsc - offset;
dest := dest + chr(TmpSrcAsc);
offset := srcAsc;
SrcPos := SrcPos + 2;
until SrcPos >= Length(Src);
end;
Result := Dest;
except
showmessage(src);
end;
end;
var
idx: integer;
KeyLen: Integer;
KeyPos: Integer;
offset: Integer;
dest: string;
SrcPos: Integer;
SrcAsc: Integer;
TmpSrcAsc: Integer;
Range: Integer;
begin
try
KeyLen := Length(Key);
if KeyLen = 0 then key := 'wangy lsy dmp';
KeyPos := 0;
SrcPos := 0;
SrcAsc := 0;
Range := 256;
if Encrypt then
begin
Randomize;
offset := 18;
if m_brand then
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;
end
else
begin
offset := StrToInt('$' + copy(src, 1, 2));
SrcPos := 3;
repeat
SrcAsc := StrToInt('$' + copy(src, SrcPos, 2));
if KeyPos < KeyLen then KeyPos := KeyPos + 1 else KeyPos := 1;
TmpSrcAsc := SrcAsc xor Ord(Key[KeyPos]);
if TmpSrcAsc <= offset then
TmpSrcAsc := 255 + TmpSrcAsc - offset
else
TmpSrcAsc := TmpSrcAsc - offset;
dest := dest + chr(TmpSrcAsc);
offset := srcAsc;
SrcPos := SrcPos + 2;
until SrcPos >= Length(Src);
end;
Result := Dest;
except
showmessage(src);
end;
end;
解决方案 »
- Ttreeview动态生成树,与插入节点问题
- 一个富有挑战性的问题!高手们赶紧进来!如能解决高分相赠!
- 有工作的delphi程序员进来一下:???????在线等!!!!!!!!!
- 控件问题 ?
- 如何把Icon、Jpg、Bmp等资源文件里的东东放入DLL
- 请看备份数据库时出现的问题.怎么办?
- 各位达人好,小弟请教关于GPRS的数据库开发问题!
- Delphi编译问题
- 请问这是什么错误?invalid variant type conversion.
- Musicwind先生请看。别的朋友也请帮忙答复。谢谢
- 找高手会delphi的.帮我解决一下问题.重金酬谢
- ini文件怎样检测有没有section和section下的ident?
http://topic.csdn.net/u/20081218/05/beeff859-3d48-4b7a-876b-e789cd367f0a.html
http://topic.csdn.net/u/20081218/13/75e2bbac-992c-44fc-8914-597cb23e6a85.html