asp.net - 如何为此 RC4 算法创建解密函数

标签 asp.net algorithm function encryption vbscript

我从 http://personalsources.com/includes/functions.asp 中提取了这段 ASP 代码并将所有密码编码成RC4,编码的功能是:

function rc4(byref thestr, byref thekey)
  dim asciiarray(255)
  dim keyarray(255)
  if isnull(thestr) then exit function
  if len(thekey)=0 then exit function
  if len(thestr)=0 then thestr=" "
  if len(thestr)=0 then exit function
  zxlen=len(thekey)
  for ipos=0 To 255
    keyarray(ipos)=asc(mid(thekey, ((ipos) Mod (zxlen)) + 1, 1))
  next
  for ipos=0 To 255
    asciiarray(ipos)=ipos
  next
  vpos=0
  for ipos=0 To 255
    vpos=(vpos + asciiarray(ipos) + keyarray(ipos)) Mod 256
    tempa= asciiarray(ipos)
    asciiarray(ipos)=asciiarray(vpos)
    asciiarray(vpos)=tempa
  next
  ipos=0
  vpos=0
  for rcx=1 To len(thestr)
    ipos=(ipos + 1) Mod 256 
    vpos=(vpos + asciiarray(ipos)) Mod 256
    tempb=(asciiarray(ipos) + asciiarray(vpos)) Mod 256
    tempa=asciiarray(ipos)
    asciiarray(ipos)=asciiarray(vpos)
    asciiarray(vpos)=tempa
    tempc=asciiarray(tempb)
    rc4=rc4 & chr(asc(mid(thestr, rcx, 1)) xor tempc)
  next
end function

你知道如果我们有加密 key (RC4)所以我们可以很容易地解密密码,但我不知道这个函数是如何加密密码的?这个函数的确切算法是什么?是否可以编写一个函数来解密此 RC4 密码?


例如这个函数的加密密码是这样的(而且它从来不像 RC4 密码!!!):

>r²çÅÅ

最佳答案

RC4 是一个流密码,所以它使用 XOR 来加密。运行 RC4 会生成一个看起来随机的字节 key 流。

加密你做的:

plaintext XOR keystream -> cyphertext

解密你做的:

cyphertext XOR keystream -> plaintext

在这两种情况下, key 流是相同的,使用相同的 key 从 RC4 生成。

关于asp.net - 如何为此 RC4 算法创建解密函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10137875/

相关文章:

c# - 检测在 C# 中运行的平台代码?

c# - 获取 IIS 设置

algorithm - 如何使用皮萨诺周期求出斐波那契数列之和的最后一位数字?

jquery 传递给 animate()

asp.net - 防止回发时关闭 ModalPopup

asp.net - 如何使用 MSTEST 对 ASP.NET CORE Controller 进行单元测试并添加 Fakes

算法:找到包含整个域的最少集合数

algorithm - 使用 A* 算法解决滑动拼图和 N Queens?

C++ 函数调用后无关指针发生变化

c - 包装来自静态库错误的函数调用