日期:2014-05-17  浏览次数:20459 次

求DELPHI 转VB
function TForm1.Encrypt(const S: String): String;
var
   I : Integer;
   Key: Word;
begin
      Result := S;
      Key:=3;
      for I := 1 to Length(S) do
      begin
         Result[I] := char(byte(S[I]) xor (Key shr 8));
         Key := (byte(Result[I]) + Key) * 21 + 31;
         if Result[I] = Chr(0) then
            Result[I] := S[I];
      end;
      Result := Result;

end;
------解决方案--------------------
急急急,在线等!部分已转换人,但有出现错误
Private Function Encrypt(ByVal sIn As String) As String
        Dim i As Integer
        Dim Key As Int64
        Dim s1 As String

        Dim Array_sIn As Char() = sIn.ToCharArray
        s1 = sIn
        Key = 3
        Dim Array_s1 As Char() = s1.ToCharArray
        For i = 1 To sIn.Length - 1
            Array_s1(i) = ChrW(CByte(AscW(Array_sIn(i))) Xor (Key >> 8))
            Key = (CByte(AscW(Array_s1(i))) + Key) * 21 + 31     '这段运行出错,数据溢出
            If Array_s1(i) = ChrW(0) Then
                Array_s1(i) = Array_sIn(i)
            End If
        Next i
        Return s1

    End Function