字符串加密函数为什么在Delphi2009中不能正常使用?

来源:百度知道 编辑:UC知道 时间:2024/06/08 04:14:43
我有个简单的字符串加密函数,在Delphi7中能正常使用,但在Delphi2009中无法正常使用,经加密解密后的文字跟原来的不一样。不知道该怎么做,请帮忙!代码如下:

//加密解密函数
function DenCrypt(Str:string;Key:string):string;
var
X,Y : Integer;
A : Byte;
begin
if Key= '' then
Key := 'd1duOsy3n6qrPr2eF9u';
Y:= 1;
for X :=1 to length(Str) do begin
A :=(ord(Str[X]) and $0f) xor (ord(Key[Y]) and $0f);
Str[X] := char((ord(Str[X]) and $f0)+A);
inc(Y);
if Y > length(Key) then
Y := 1;
end;
Result:=Str;
end;

//调用
procedure TMainForm.JIAMIClick(Sender: TObject);
var
a:string;
begin
a:=inputbox('请输入密码!','密码:','');
memo1.text:=DenCrypt(memo1.Text,a); //a 表示key (密码)
end;

delphi2009增加了UnicodeString类型,默认的string也就是UnicodeString,所以在字符串处理方面和delphi7有所区别,具体请参考http://www.delphifans.com/infoview/Article_4649.html

不一样的版本