字符串加解密源程序(200分)

C

chooy

Unregistered / Unconfirmed
GUEST, unregistred user!
给出一段字符串加密程序,谁能第一个写出解密程序,测试OK加200分!
---------------------------------------------------
function change(Ustring:string):string;
var
s1,s2:String;
i,j,k:integer;
begin
s1:=trim(Ustring);
k:=round(length(s1)/2+0.0001);
s2:=s1;
j:=1;
for i:=1 to k do
begin
if chr(ord(s1) xor 9) IN ['0'..'9','a'..'z','A'..'Z',':'] then
s2[j]:=chr(ord(s1) xor 9)
else
s2[j]:=s1;
inc(j);
if j<=length(s1) then
begin
if chr(ord(s1[i+k]) xor 9) IN ['0'..'9','a'..'z','A'..'Z',':'] then
s2[j]:=chr(ord(s1[i+k]) xor 9)
else
s2[j]:=s1[i+k];
inc(j);
end;
end;
result:=s2;
end;
 
function change1(Ustring:string):string;
var
s1,s2:String;
i,j,k:integer;
begin
s1:=trim(Ustring);
s2:=s1;
i := 1;
j := 1;
while i <= Length(s1) do
begin
s2[j] := chr(ord(s1) xor 9);
if not (s2[j] in ['0'..'9','a'..'z','A'..'Z',':']) then s2[j] := chr(ord(s2[j]) xor 9);
inc(i, 2);
inc(j);
end;

i := 2;
while i <= Length(s1) do
begin
s2[j] := chr(ord(s1) xor 9);
if not (s2[j] in ['0'..'9','a'..'z','A'..'Z',':']) then s2[j] := chr(ord(s2[j]) xor 9);

inc(i, 2);
inc(j);
end;


result:=s2;
end;
 
function changeStr(s,sKey:string):string;
var
i,m,n:integer;
begin
Result:=s;
m:=length(sKey);
if m=0 then exit;
n:=1;
for i:=1 to length(s) do
begin
Result:=char(Ord(Result) xor ord(sKey[n]));
inc(n);
if n>m then n:=1;
end;
end;


procedure TForm1.Button2Click(Sender: TObject);
var
s:string;
begin
s:=ChangeStr('12Abcdefg345678','abc');
showmessage(s);
s:=ChangeStr(s,'abc');
showmessage(s);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
s:string;
begin
s:=ChangeStr('12Ab中文汉字defg345678','12A3b4c');
showmessage(s);
s:=ChangeStr(s,'12A3b4c');
showmessage(s);
end;
 
看看这个例子
加密/解密一个字符串

{ Begin code }
program Crypt;
uses WinCRT;
const
C1 = 52845;
C2 = 22719;
function Encrypt(const S: String; Key: Word): String;
var
I: byte;
begin
Result[0] := S[0];
for I := 1 to Length(S) do begin
Result := char(byte(S) xor (Key shr 8));
Key := (byte(Result) + Key) * C1 + C2;
end;
end;

function Decrypt(const S: String; Key: Word): String;
var
I: byte;
begin
Result[0] := S[0];
for I := 1 to Length(S) do begin
Result := char(byte(S) xor (Key shr 8));
Key := (byte(S) + Key) * C1 + C2;
end;
end;

var
S: string;
begin
Write('>');
ReadLn(S);
S := Encrypt(S,12345);
WriteLn(S);
S := Decrypt(S,12345);
WriteLn(S);
end.
 
tseug的回答完全符合该函数加解密要求,测试通过!另两位的回答也非常精彩!谢谢!
 
顶部