加密解密函数如下:
function StrHexExchange(str:String):String;
var
i,l:integer;
k,t:byte;
begin
result:='';
l:=length(str);
for i:=1 to l do
begin
t:=ord(str[i]);
k:=(t shl 4) or (t shr 4); //每个字符的高低位进行交换,再交换一次还还原了! result:=result+chr(k);
end;
end;
但在加密解密测试中发现有部分中文字出现乱码,如'存款'、'取款'希望高手们赐教
function StrHexExchange(str:String):String;
var
i,l:integer;
k,t:byte;
begin
result:='';
l:=length(str);
for i:=1 to l do
begin
t:=ord(str[i]);
k:=(t shl 4) or (t shr 4); //每个字符的高低位进行交换,再交换一次还还原了! result:=result+chr(k);
end;
end;
但在加密解密测试中发现有部分中文字出现乱码,如'存款'、'取款'希望高手们赐教
解决方案 »
- 请问下,delphi中TWindowsMediaPlayer能不能修改Classid,换成低版本的mediaplayer
- ClientDataSet.Filter := 'F_ID like ' + QuotedStr('%玉%');为何不行
- 图标问题
- 请较文件的拖放的问题?还望大家指教!
- 从IP地址获得计算机名?
- 在QuickRep中, 如何让一个QRDBText自动换行阿?
- 给我一个关于多线程的解决方案吧!
- 为什么label组件在win7下会显示不出来呢
- 富翁又可以上了,感覺速度還不錯。 DELPHI 用戶有福了 wwww.delphibbs.com(內空)
- 上哪找TeeMach的TeeTree构件或RSD的DBTreeview构件,还有哪有ASPack减肥工具
- 如何安装DSPack控件?
- 关于日期字段显示问题??
能不用其它方式导入内存及写入磁盘????
//字符串加密函数
function Encrypt(const S: String; Key: Word): String;
var
I : Integer;
begin
Result := S;
for I := 1 to Length(S) do
begin
Result[I] := char(byte(S[I]) xor (Key shr 8));
Key := (byte(Result[I]) + Key) * C1 + C2;
if Result[I] = Chr(0) then
Result[I] := S[I];
end;
Result := StrToHex(Result);
end;//字符串解密函数
function Decrypt(const S: String; Key: Word): String;
var
I: Integer;
S1: string;
begin
S1 := HexToStr(S);
Result := S1;
for I := 1 to Length(S1) do
begin
if char(byte(S1[I]) xor (Key shr 8)) = Chr(0) then
begin
Result[I] := S1[I];
Key := (byte(Chr(0)) + Key) * C1 + C2; //保证Key的正确性
end
else
begin
Result[I] := char(byte(S1[I]) xor (Key shr 8));
Key := (byte(S1[I]) + Key) * C1 + C2;
end;
end;
end;