2012-04-13 58 views
0

我从http://personalsources.com/includes/functions.asp拉了ASP的代码和它的编码的所有密码,RC4,编码的功能是:如何创建解密功能对于这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 
你知道

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


例如,通过此功能的加密密码是这样的(和它从来没有像RC4密码!!!):

>r²çÅÅ 
+0

简短的回答:rtfm;) – 2012-04-13 08:56:47

+1

感谢特拉维斯,你怎么找到它? – user1259236 2012-04-13 08:59:21

回答

2

RC4是一个流密码,所以它使用异或来加密。运行RC4会产生一个随机查找的字节密钥流。

要加密你这样做:

明文XOR密钥流 - >密文

要解密你这样做:

密文异或的密钥流 - >明文

在这两种情况下,密钥流都是一样的,p使用相同的钥匙从RC4导出。

+0

谢谢,它的最佳答案 – user1259236 2012-04-13 11:06:34

0

Wikipedia,所有你需要做的解密RC4是使用相同的密钥再次运行相同的功能。

1

密码没有加密,所以你不能解密它。

数据已加密。要解密它,您需要密码,并使用加密文本和原始密码(用于加密的密码)运行相同的功能。