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

解决方案 »

  1.   

    Len()->Length
    Mid->MidStr (use:StrUtils)
    其它的没什么了吧?
      

  2.   

    晕死StrConv(buff, vbUnicode) 呢?
      

  3.   

    好像就是这个功能,楼主试试下面的代码:
    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;
      

  4.   

    那你的这句话什么意思,难道数字Or英文字符串必须是复数字节的?
    If I Mod 2 = 1 Then
                '待解密的字串不符合要求
      

  5.   

    QQ有,不过很少上,要找就到这里来发短消息。再试试看
    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;
    /////////////////////////////////
    贴先别结,我再想想,改一改
      

  6.   

    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(ws[2 * i]) xor Key);//去掉“-1”
      Result := StrSource;
    end;
      

  7.   

    好的  我想关键 应该是 StrConv(buff, vbUnicode)
    我先试试
      

  8.   

    现在可以了,已经试过了
    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;
      

  9.   

    这个是 这个次  应该好改了吧?'加密
    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
      

  10.   

    Decrypt = StrConv(buff, vbUnicode)呢?
    做什么用的?
      

  11.   

    StrConv(buff, vbUnicode)
    我不这样认为,我猜这个函数的意思就是把一串二进制转换成字符显示出来,应该没别的还有就是:我还不知道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)也可以随便换
      

  12.   

    根据加密函数修改如下,试试:
    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;
      

  13.   

    不行   再问问  任何写个ActiveXDll  让Asp调用  上面的  本来是  Vb 写的  现在没办法  只要用 Delphi写  可以写个列子给我吗?   如果全部问题  解决  这100 分外  再给  500
      

  14.   

    8F898E8DC7D2D2CFCCC5D3CBCED3CFCDCDD3CCC5CAD22D1046262D3DD23E3D3D0B48394D533A14D2CA293FCA35283A1AD3908DCE我不记得  全部地址了  解密  以后  前7个字符  应该是 http://但是   你写的  还是乱码
      

  15.   

    错误了  应该  是 rtsp://
      

  16.   

    终于知道你的加密的方式了,现在可以了,全部改好了,已经试过了,
    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;
      

  17.   

    Edit2.Text:=Decrypt('8F898E8DC7D2D2CFCCC5D3CBCED3CFCDCDD3CCC5CAD22D1046262D3DD23E3D3D0B48394D533A14D2CA293FCA35283A1AD3908DCE',253);rtsp://....................好象是  10进制还是16进制
      

  18.   

    用UCS应该可以解决
    UCS是双字节的  可以进行双字节的XOR