2012-04-13 37 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

密碼沒有加密,所以你不能解密它。

數據已加密。要解密它,您需要密碼,並使用加密文本和原始密碼(用於加密的密碼)運行相同的功能。