关于一个简单的Delphi加密算法的问题

来源:百度知道 编辑:UC知道 时间:2024/05/15 09:39:51
procedure TForm1.BitBtn1Click(Sender: TObject);
var
s: string;
j: integer;
begin
Edit2.Clear;
s := Edit1.Text;
for j := 1 to length(s) do
s[j] := chr(ord(s[j]) xor 255);
Edit2.Text := s;
application.MessageBox( '加密成功! ', '明日科技 ');
end;

procedure TForm1.BitBtn2Click(Sender: TObject);
var
s: string;
j: integer;
begin
Edit3.Clear;
s := Edit2.Text;
for j := 1 to length(s) do
s[j] := chr(ord(s[j]) xor 255);
Edit3.Text := s;
application.MessageBox( '解密成功! ', '明日科技 ');
end;

为什么我这样写加密100解密却成了10.请教各位大虾

你的算法没有KEY,当字符数为奇数时就会出错。
给一个简单的加密算法。
program Project1;

{$APPTYPE CONSOLE}

uses
SysUtils;

const
Key='TESTNET';
Cryptograph='100';

//不能为0.5,相加为1
Percent1=0.21;
Percent2=0.79;

var
s1:string;
function GetKey(aKey:string;aPercent:Double):string;
var
i:integer;
begin
SetLength(Result,Length(aKey));
for i:=1 to Length(aKey) do
begin
Result[i]:=Chr(Round(Ord(aKey[i])*aPercent));
end;
end;

function EnCode(aCryptograph,aKey:string):string;
var
i,keylen,codelen:integer;
begin
keylen:=Length(akey);
codelen:=Length(aCryptograph);
SetLength(Result, Length(aCryptograph));
for i:=1 to codelen do
begin
Result[i]:=Chr(Ord(aCryptograph[i])+Ord(aKey[(i mod KeyLen)+1]));
end;
end;

function DeCode(aCryptograph,aKey:string):strin