●请问下DELPHI下的可逆乱码加密解密 ●(100分)

C

cn0754

Unregistered / Unconfirmed
GUEST, unregistred user!
我参考了网上的一个简单的例子
function TForm1.EnDeCode(const Value : String) : String;//加密
var
CharIndex : Integer;

ReturnValue : String;

begin

ReturnValue := '';

for CharIndex := 1 to Length(Value) do

begin

ReturnValue := ReturnValue + chr(NOT(ord(Value[CharIndex])));

end;

Result := ReturnValue;

end;

function TForm1.DisDeCode(const Value : String) : String;//解密
var
CharIndex : Integer;

ReturnValue : String;

begin

ReturnValue := '';

for CharIndex := 1 to Length(Value) do

begin

ReturnValue := ReturnValue + chr(NOT(ord(Value[CharIndex])));

end;

Result := ReturnValue;

end;

加密后可以是乱码的.但是有个问题就是例如你字符
"我"加密后是 "1-"
但是如果多个
"我我我我"加密后还是"1-1-1-1-"
这样就很容易被猜出了.
我想请教各位如何当
多次重复字符的话
加密后的效果不会重复类似"1-1-1-1-"
的情况.谢谢.也就是按位的不同加密后是不同的
需要的是一种能加密到乱码的字符.
 
// 将你的发的代码略为改变一下就行了。
function TForm1.EnDeCode(const Value : String) : String;//加密
var
CharIndex : Integer;
ReturnValue : String;
begin
ReturnValue := '';
for CharIndex := 1 to Length(Value) do
begin
ReturnValue := ReturnValue + chr(NOT(ord(Value[CharIndex]) xor CharIndex));
end;
Result := ReturnValue;
end;
function TForm1.DisDeCode(const Value : String) : String;//解密
var
CharIndex : Integer;
ReturnValue : String;
begin
ReturnValue := '';
for CharIndex := 1 to Length(Value) do
begin

ReturnValue := ReturnValue + chr(NOT(ord(Value[CharIndex]) xor CharIndex));
end;

Result := ReturnValue;
end;
 
感谢.呵呵,不知道大家还有更好的类似这样的加密代码吗?
加密后乱码的.
 
呵呵,加密算法是要自己想的才能起到加密效果,如果自己不会,还是建议你去网上找那些成熟的加密算法加密强度会更高,如RSA、DES等等,如果对加密强度不高的话,用上面的代码已经可以应付了。
 

Similar threads

S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
933
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
958
SUNSTONE的Delphi笔记
S
顶部