自己找了几个算法,发现对英文、数字字符加密解密没有问题,但是对于中文字符就不一致了,请给出对于中文字符的加密和解密算法,VB代码实现,请给出代码,一定给分!
多谢!

解决方案 »

  1.   

    同样等待!!!
    学习ing
      

  2.   

    呵呵,基于字节好像不行,我试验过好几个网上下载的算法,英文,数字没有问题,中文就会出问题,尤其是中英文混编的,例如“中文123abc中文”在很多算法中加密,然后解密就得不到正确的原文字
      

  3.   

    hehe,不知楼主对加密的要求高不高?如果要求不高,可试试BASE64编码或UU编码^_^都是很常用的。
      

  4.   

    //都是基于字节的加密
    同意给你写了个最简单的:Option Explicit
    '加密
    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
    '解密
    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 FunctionPrivate Sub Command1_Click()
        Dim s As String
        s = "abc中国123456"
        s = Encrypt(s, 253)
        Debug.Print s
        s = decrypt(s, 253)
        Debug.Print s
    End Sub
      

  5.   

    给我发一个,通过就给分,呵呵
    [email protected]
      

  6.   

    rainstormmaster(rainstormmaster) 的代码好像可以,多谢!
    3661512(菜鸟一只) 的代码还没有收到,收到后就给大家加分了
    liyan010(我是大坏蛋) ,呵呵,校友好啊,你的邮件要给出来,代码才好发给你