Private Function Decrypt(ByVal strSource As String, ByVal Key As Byte) As String
Dim I As Long
Dim j As Long
Dim temps As String
Dim S As String
Dim arr As Variant
I = Len(strSource)
If I Mod 2 = 1 Then
'待解密的字串不符合要求
Decrypt = ""
Exit Function
End If
Dim buff() As Byte
Dim k As Long
k = 0
For I = 1 To Len(strSource) Step 2
temps = Mid(strSource, I, 2)
j = Val("&H" & temps)
j = j Xor Key
ReDim Preserve buff(k)
buff(k) = j
k = k + 1
Next
Decrypt = StrConv(buff, vbUnicode)
End Function
Dim I As Long
Dim j As Long
Dim temps As String
Dim S As String
Dim arr As Variant
I = Len(strSource)
If I Mod 2 = 1 Then
'待解密的字串不符合要求
Decrypt = ""
Exit Function
End If
Dim buff() As Byte
Dim k As Long
k = 0
For I = 1 To Len(strSource) Step 2
temps = Mid(strSource, I, 2)
j = Val("&H" & temps)
j = j Xor Key
ReDim Preserve buff(k)
buff(k) = j
k = k + 1
Next
Decrypt = StrConv(buff, vbUnicode)
End Function
Mid->MidStr (use:StrUtils)
其它的没什么了吧?
function Decrypt(StrSource: string; Key: Byte): string;
var
i: Longint;
ws: widestring;
begin
i := length(StrSource);
if i mod 2 = 1 then
begin
showmessage('待解密的字串不符合要求');
Result := '';
exit;
end;
ws := StrSource;
for i := 1 to length(ws) do
ws[i] := widechar(Ord(ws[i]) xor Key);
Result := ws;
end;
If I Mod 2 = 1 Then
'待解密的字串不符合要求
function Decrypt(StrSource: string; Key: Byte): string;
var
i: Longint;
begin
i := length(StrSource);
if i mod 2 = 1 then
begin
showmessage('待解密的字串不符合要求');
Result := '';
exit;
end;
for i := 1 to length(StrSource) div 2 do
StrSource[2 * i - 1] := char(Ord(ws[2 * i - 1]) xor Key);
Result := StrSource;
end;
/////////////////////////////////
贴先别结,我再想想,改一改
var
i: Longint;
begin
i := length(StrSource);
if i mod 2 = 1 then
begin
showmessage('待解密的字串不符合要求');
Result := '';
exit;
end;
for i := 1 to length(StrSource) div 2 do
StrSource[2 * i] := char(Ord(ws[2 * i]) xor Key);//去掉“-1”
Result := StrSource;
end;
我先试试
function Decrypt(StrSource: string; Key: Byte): string;
var
i: Longint;
begin
i := length(StrSource);
if i mod 2 = 1 then
begin
showmessage('待解密的字串不符合要求');
Result := '';
exit;
end;
for i := 1 to length(StrSource) div 2 do
StrSource[2 * i] := char(Ord(StrSource[2 * i]) xor Key);
Result := StrSource;
end;
Private Function Encrypt(ByVal strSource As String, ByVal Key As Byte) As String
Dim I As Long
Dim j As Byte
Dim temps As String
Dim s As String
Dim arr() As Byte
arr = StrConv(strSource, vbFromUnicode)
For I = 0 To UBound(arr)
j = arr(I) Xor Key
temps = Right("00" & Hex(j), 2)
s = s + temps
Next
Encrypt = s
End Function
做什么用的?
我不这样认为,我猜这个函数的意思就是把一串二进制转换成字符显示出来,应该没别的还有就是:我还不知道VB里面的Byte和Delphi中的Byte是不是一样
Delphi中的:Byte 0..255 unsigned 8-bit
只有一个字节,而根据上面的代码
temps = Mid(strSource, I, 2)
j = Val("&H" & temps)
j = j Xor Key
它要和两个字节 XOR ,问题大概就在这里
///////////////////////////////////
最后的一贴中的函数可以实现:
Decrypt(Decrypt(trim(Edit1.Text),$DE),$DE) = Edit1.Text;
其中Edit1.Text满足“一窜 数字Or英文的 地址 (地址有中文字符)”
参数Key的值(例子中为$DE)也可以随便换
function Decrypt(StrSource: string; Key: Byte): string;
var
i: Longint;
s: string;
begin
i := length(StrSource);
if i mod 2 = 1 then
begin
showmessage('待解密的字串不符合要求');
Result := '';
exit;
end;
s := '';
for i := 1 to length(StrSource) div 2 do
begin
StrSource[2 * i] := char(Ord(StrSource[2 * i]) xor Key);
s := s + copy(StrSource, 2 * i, 1);
end;
Result := s;
end;
function Decrypt(StrSource: string; Key: Byte): string;
var
i: Longint;
s: string;
begin
i := length(StrSource);
if i mod 2 = 1 then
begin
showmessage('待解密的字串不符合要求');
Result := '';
exit;
end;
s := '';
for i := 1 to length(StrSource) div 2 do
begin
StrSource[2 * i] := char(Ord(StrSource[2 * i]) xor Key);
s := s + copy(StrSource, 2 * i, 1);
end;
Result := s;
end;function Encrypt(StrSource: String; Key: Byte): String;
var
s: string;
i: integer;
begin
s := '';
for i := 1 to Length(StrSource) do
begin
s := s + #00;
s := s + char(ord(StrSource[i]) xor Key);
end;
Result := s;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
if Decrypt(Encrypt(trim(Edit1.Text),$DE),$DE) = Edit1.Text then
showmessage('Right');
end;
UCS是双字节的 可以进行双字节的XOR