2

有没有办法让它在 ASP 页面中工作?它在 charset windows-1253 上运行良好,但现在我必须将我的网站转换为 UTF-8,我唯一的问题是加密和解密。我已经加密了会员注册密码,现在使用 UTF-8,解密后密码如下所示:2��8��6

请我需要一些帮助(对不起我的英语)。这是 RC4 代码:

Dim sbox(255)
   Dim rc4Key(255)

   Sub RC4Initialize(strPwd)

      dim tempSwap, a, b      

      intLength = len(strPwd)

      for a = 0 To 255

         rc4Key(a)  = asc(mid(strpwd, (a mod intLength)+1, 1))

         sbox(a) = a                       
      next

      b = 0

      for a = 0 To 255
         b = (b + sbox(a) + rc4Key(a)) Mod 256         
         tempSwap = sbox(a)
         sbox(a) = sbox(b)
         sbox(b) = tempSwap
      Next

   End Sub

   function EnDeCrypt(plaintxt, psw)      

      dim temp, a, i, j, k, cipherby, cipher      

      i = 0
      j = 0

      RC4Initialize psw

      for a = 1 To Len(plaintxt)
         i  = (i + 1) Mod 256
         j  = (j + sbox(i)) Mod 256
         temp   = sbox(i)
         sbox(i)= sbox(j)
         sbox(j)= temp

         k  = sbox((sbox(i) + sbox(j)) Mod 256)

         cipherby   = Asc(Mid(plaintxt, a, 1)) Xor k
         cipher     = cipher & Chr(cipherby)         
      next

      enDeCrypt = cipher            

   end function

   function RC4EnCryptASC(plaintxt, psw)      

      dim temp, a, i, j, k, cipherby, cipher      

      i = 0
      j = 0

      RC4Initialize psw

      for a = 1 To Len(plaintxt)
         i  = (i + 1) Mod 256
         j  = (j + sbox(i)) Mod 256
         temp   = sbox(i)
         sbox(i)= sbox(j)
         sbox(j)= temp

         k      = sbox((sbox(i) + sbox(j)) Mod 256)

         cipherby   = Asc(Mid(plaintxt, a, 1)) Xor k         
         cipher     = cipher & "|"& cipherby         
      next            

      RC4EnCryptASC = cipher            

   end function

   function RC4DeCryptASC(plaintxt, psw)      

      plaintxt = transformToCHR(plaintxt)

      dim temp, a, i, j, k, cipherby, cipher      

      i = 0
      j = 0      

      dim arrayEncrypted            

      RC4Initialize psw         

       for a = 1 To Len(plaintxt)
         i  = (i + 1) Mod 256
         j  = (j + sbox(i)) Mod 256
         temp   = sbox(i)
         sbox(i)= sbox(j)
         sbox(j)= temp

         k  = sbox((sbox(i) + sbox(j)) Mod 256)

         cipherby   = Asc(Mid(plaintxt, a, 1)) Xor k
         cipher     = cipher & Chr(cipherby)         
      next

      RC4DeCryptASC = cipher                       

   end function

function transformToCHR(plaintxt)


      dim returnText, arrayEncrypted
      arrayEncrypted = split(plaintxt, "|")            

      returnText=""            

      for a = 1 to ubound(arrayEncrypted)         
         returnText=returnText&CHR(arrayEncrypted(a))         
      next            

      transformToCHR = returnText
end function
4

2 回答 2

1

我认为您必须使用 AscW 函数和等效的其他函数来处理 Unicode 字符?

于 2014-01-21T14:22:04.447 回答
1

好吧,我终于成功了。我只是将每个 asc 替换为 ascW 并将每个 chr 替换为 chrW 并且效果很好。

于 2014-01-23T21:33:23.577 回答