const XorKey:array[0..7] of Byte=($B2,$09,$AA,$55,$93,$6D,$84,$47); //字符串加密用function Enc(Str:String):String;//字符加密函數 這是用的一個異或加密
var
i,j:Integer;
begin
Result:='';
j:=0;
for i:=1 to Length(Str) do
begin
Result:=Result+IntToHex(Byte(Str[i]) xor XorKey[j],2);
j:=(j+1) mod 8;
end;
end;
function Dec(Str:String):String;//字符解密函數
var
i,j:Integer;
begin
Result:='';
j:=0;
for i:=1 to Length(Str) div 2 do
begin
Result:=Result+Char(StrToInt('$'+Copy(Str,i*2-1,2)) xor XorKey[j]);
j:=(j+1) mod 8;
end;
end;
var
i,j:Integer;
begin
Result:='';
j:=0;
for i:=1 to Length(Str) do
begin
Result:=Result+IntToHex(Byte(Str[i]) xor XorKey[j],2);
j:=(j+1) mod 8;
end;
end;
function Dec(Str:String):String;//字符解密函數
var
i,j:Integer;
begin
Result:='';
j:=0;
for i:=1 to Length(Str) div 2 do
begin
Result:=Result+Char(StrToInt('$'+Copy(Str,i*2-1,2)) xor XorKey[j]);
j:=(j+1) mod 8;
end;
end;
解决方案 »
- 请问StringGrid中如何限制只能输入大写字母
- form2.image1.Transparent:=true;的问题
- delphi中有类似这样param=(true)?=v1:v2语句的函数
- 同时播放mid和wav文件,只听得到mid文件怎么办???
- 不能把图片或其它二进制数据放入Sql Server的Image字段
- 如何设置TIdHTTP控件的超时
- 如何来用ADO来打开一个ACCESS数据库,并且把数据库中所有记录都读在DBGrid中?要完整的步骤!详细的!80分这么简单的问题!快来抢!择优录用!
- 在Delphi5中如何把text文本的数据导入其他的数据库表中(如dbase,access,fox)
- delphi xe7 webbrowser android下无法加载https地址
- 请教delphi+java开发
- 关闭窗体时怎么动态传值给调用窗体
- 编译通不过,大家看看
Private Sub Command1_Click()
Dim s As String
s = "hello"
s = Encode(s)
s = Decode(s)
Debug.Print s
End SubPrivate Sub Form_Load()
XorKey(0) = &HB2
XorKey(1) = &H9
XorKey(2) = &HAA
XorKey(3) = &H55
XorKey(4) = &H93
XorKey(5) = &H6D
XorKey(6) = &H84
XorKey(7) = &H47
End Sub
Function Encode(ByVal sStr As String) As String
Dim i As Long, j As Long
Dim s As String
For i = 1 To Len(sStr)
s = s & Hex(AscB(Mid(sStr, i, 1)) Xor XorKey(j))
j = (j + 1) Mod 8
Next i
Encode = s
End Function
Function Decode(ByVal sStr As String) As String
Dim i As Long, j As Long
Dim s As String, c As String
For i = 1 To Len(sStr) \ 2
c = Mid(sStr, i * 2 - 1, 2)
s = s & Chr(CByte("&H" & c) Xor XorKey(j))
j = (j + 1) Mod 8
Next i
Decode = s
End Function