Delphi代码
加密部分
function Encode(source : string):string;
var
Source_Len,Len : integer;
Count,c : integer;
a1,a2 : byte;
ind : dword;
Encode_Str : string;
begin
Result := ‘‘;
Encode_Str := ‘‘;
Len := 0;
a1 := 0;
a2 := 0;
c := 0;
ind := 0;
Count := 0;
Source_Len := Length(source);
while Count < Source_Len do
begin
if Len >= $2710 then
break;
ind := ord(source[Count+1]);
ind := ind shr (c+2);
a1 := ind or a2;
a1 := a1 and $3f;
ind := ord(source[Count+1]);
ind := ind shl (8-(c+2));
ind := ind shr 2;
a2 := ind and $3f;
inc(c,2);
if c >= 6 then
begin
if Len >= $270f then
begin
Encode_Str := Encode_Str + chr(a1 + $3c);
inc(Len);
end
else
begin
Encode_Str := Encode_Str + chr(a1 + $3c);
Encode_Str := Encode_Str + chr(a2 + $3c);
Inc(Len,2);
end;
c := 0;
a2 := 0;
end
else
begin
Encode_Str := Encode_Str + chr(a1 + $3c);
Inc(Len);
end;
inc(Count);
end;
if c > 0 then
begin
Encode_Str := Encode_Str + chr(a2 + $3c);
Inc(Len);
end;
SetLength(Encode_Str,Len);
Result := Encode_Str;
end; 解密部分
function Decode(source : string):string;
var
Source_Len,Len : integer;
Count,c1,c2 : integer;
code : array[0..7] of byte;
a1,a2 : byte;
ind : dword;
Decode_Str : string;
label L1,L2;
begin
Result := ‘‘;
Decode_Str := ‘‘;
code[2] := $fc;
code[4] := $f0;
code[6] := $c0;
Len := 0;
a1 := 0;
a2 := 0;
c1 := 2;
c2 := 0;
ind := 0;
Count := 0;
Source_Len := Length(source);
while (Count < Source_Len) do
begin
if(ord(Source[Count+1]) - $3c) < 0 then
begin
Decode_Str := Decode_Str + Source[Count+1];
inc(Len);
inc(Count);
a1 := 0;
a2 := 0;
c1 := 2;
c2 := 0;
ind := 0;
Continue;
//break;
end;
a1 := ord(Source[Count+1]) - $3c;
if Len >= Source_Len then
begin
break;
end;
if (c2 + 6) < 8 then
begin
goto L2;
end;
ind := a1 and $3f;
ind := ind shr (6-c1);
Decode_Str := Decode_Str + chr(ind or a2);
Inc(Len);
c2 := 0;
if c1 >= 6 then
begin
c1 := 2;
goto L1;
end;
inc(c1,2);
L2 :a2 := a1 shl c1;
a2 := a2 and code[c1];
c2 := c2 + (8 - c1);
L1 :inc(count);
end;
SetLength(Decode_Str,Len);
Result := Decode_Str;
end;
我想把他用VB代码写出来!!有会DELPHI和VB的朋友帮忙转一下!!
加密部分
function Encode(source : string):string;
var
Source_Len,Len : integer;
Count,c : integer;
a1,a2 : byte;
ind : dword;
Encode_Str : string;
begin
Result := ‘‘;
Encode_Str := ‘‘;
Len := 0;
a1 := 0;
a2 := 0;
c := 0;
ind := 0;
Count := 0;
Source_Len := Length(source);
while Count < Source_Len do
begin
if Len >= $2710 then
break;
ind := ord(source[Count+1]);
ind := ind shr (c+2);
a1 := ind or a2;
a1 := a1 and $3f;
ind := ord(source[Count+1]);
ind := ind shl (8-(c+2));
ind := ind shr 2;
a2 := ind and $3f;
inc(c,2);
if c >= 6 then
begin
if Len >= $270f then
begin
Encode_Str := Encode_Str + chr(a1 + $3c);
inc(Len);
end
else
begin
Encode_Str := Encode_Str + chr(a1 + $3c);
Encode_Str := Encode_Str + chr(a2 + $3c);
Inc(Len,2);
end;
c := 0;
a2 := 0;
end
else
begin
Encode_Str := Encode_Str + chr(a1 + $3c);
Inc(Len);
end;
inc(Count);
end;
if c > 0 then
begin
Encode_Str := Encode_Str + chr(a2 + $3c);
Inc(Len);
end;
SetLength(Encode_Str,Len);
Result := Encode_Str;
end; 解密部分
function Decode(source : string):string;
var
Source_Len,Len : integer;
Count,c1,c2 : integer;
code : array[0..7] of byte;
a1,a2 : byte;
ind : dword;
Decode_Str : string;
label L1,L2;
begin
Result := ‘‘;
Decode_Str := ‘‘;
code[2] := $fc;
code[4] := $f0;
code[6] := $c0;
Len := 0;
a1 := 0;
a2 := 0;
c1 := 2;
c2 := 0;
ind := 0;
Count := 0;
Source_Len := Length(source);
while (Count < Source_Len) do
begin
if(ord(Source[Count+1]) - $3c) < 0 then
begin
Decode_Str := Decode_Str + Source[Count+1];
inc(Len);
inc(Count);
a1 := 0;
a2 := 0;
c1 := 2;
c2 := 0;
ind := 0;
Continue;
//break;
end;
a1 := ord(Source[Count+1]) - $3c;
if Len >= Source_Len then
begin
break;
end;
if (c2 + 6) < 8 then
begin
goto L2;
end;
ind := a1 and $3f;
ind := ind shr (6-c1);
Decode_Str := Decode_Str + chr(ind or a2);
Inc(Len);
c2 := 0;
if c1 >= 6 then
begin
c1 := 2;
goto L1;
end;
inc(c1,2);
L2 :a2 := a1 shl c1;
a2 := a2 and code[c1];
c2 := c2 + (8 - c1);
L1 :inc(count);
end;
SetLength(Decode_Str,Len);
Result := Decode_Str;
end;
我想把他用VB代码写出来!!有会DELPHI和VB的朋友帮忙转一下!!
Public CF As Boolean '进位标志
Function Encode(source As String) As String
Dim Source_Len, Len_VB As Integer
Dim Count, c As Integer
Dim a1, a2 As Byte
Dim ind As Byte
Dim Encode_Str As String
Result = ""
Encode_Str = ""
Len_VB = 0
a1 = 0
a2 = 0
c = 0
ind = 0
Count = 0
Source_Len = Len(source)Do While Count < Source_Len
Len_VB = Source_Len
If Len_VB >= 9999 Then
Exit Do
End If
ind = Asc(Mid(source, Count + 1, 1))
ind = SHR(ind, c + 2)
a1 = ind Or a2
a1 = a1 And 63
ind = Asc(Mid(source, Count + 1, 1))
ind = SHL(ind, 8 - (c + 2))
ind = SHR(ind, 2)
a2 = ind And 63
c = c + 2
If c >= 6 Then
If Len_VB >= 9999 Then
Encode_Str = Encode_Str + Chr(a1 + 60)
Len_VB = Len_VB + 1
Else
Encode_Str = Encode_Str + Chr(a1 + 60)
Encode_Str = Encode_Str + Chr(a2 + 60)
Len_VB = Len_VB + 2
End If
c = 0
a2 = 0
Else
Encode_Str = Encode_Str + Chr(a1 + 60)
Len_VB = Len_VB + 1
End If
Count = Count + 1
Loop
If c > 0 Then
Encode_Str = Encode_Str + Chr(a2 + 60)
Len_VB = Len_VB + 1
End If
Encode = Encode_Str
End Function'1.逻辑左移Public Function SHL(OPR As Byte, n As Integer) As Byte
Dim BD As Byte
Dim I As Integer
BD = OPR
For I = 1 To n - 1
BD = (BD And &H7F) * 2 '将D7位屏蔽左移,防止字节溢出
Next I
CF = BD And &H80 '判断D7位是否进位
SHL = (BD And &H7F) * 2
End Function
'2.逻辑右移Public Function SHR(OPR As Byte, n As Integer) As Byte
Dim BD As Byte
Dim I As Integer
BD = OPR
For I = 1 To n - 1
BD = BD \ 2 '右移
Next I
CF = BD And 1 '判断D0位是否进位
SHR = BD \ 2
End Function