RC4 Encryption modified

Author Message
angryrabbit

  • Total Posts : 36
  • Scores: 2
  • Reward points : 0
  • Joined: 11/23/2010
  • Status: offline
RC4 Encryption modified Thursday, December 02, 2010 7:33 AM (permalink)
0
 This is an implementation of the original RC4 algorithm with two improvements.
1) It drops the first 3072 bytes of the original keystream to reduce the non-randomness of the stream.
2) It solves the combinatorial problem discovered by Mantin and Shamir by implementing an extra sbox and key into the output as suggested by Paul and Praneel.
 Option Explicit Dim s(256), s2(256), strKey, strMessage, x, y, y2, a, strOutput, boolMode, mLen strKey = InputBox("Password:", "Enter Password") 
Randomize 
strMessage = InputBox("Message:", "Enter Message") 
If MsgBox("Yes to Encrypt, No to Decrypt" & vbCrLf & "Output is in Hex for Encryption" & vbCrLf & "Input must be in Hex for Decryption", vbYesNo, "Select Mode") = vbYes Then 
 boolMode = True 
 mLen = Len(strMessage) 
Else 
 boolMode = False 
 mLen = Len(strMessage) \ 2 
End If x = 0 
y = 0 
y2 = 0 
rc4a_init For a = 1 To mLen 
 If boolMode Then 
  strOutput = strOutput & Right("0" & Hex(rc4a_output1 Xor Asc(Mid(strMessage, a, 1))), 2) 
 Else 
  strOutput = strOutput & Chr(rc4a_output1 Xor CLng("&H" & Mid(strMessage, a*2 - 1, 2))) 
 End If 
  
 a = a + 1 
 If a > mLen Then 
  Exit For 
 Else 
  If boolMode Then 
   strOutput = strOutput & Right("0" & Hex(rc4a_output2 Xor Asc(Mid(strMessage, a, 1))), 2) 
  Else 
   strOutput = strOutput & Chr(rc4a_output2 Xor CLng("&H" & Mid(strMessage, a*2 - 1, 2))) 
  End If 
 End If 
Next MsgBox strOutput, 0, "" Sub Swap(ByRef sbox, ByVal i, ByVal j) 
 Dim temp 
 temp = sbox(i) 
 sbox(i) = sbox(j) 
 sbox(j) = temp 
End Sub Sub rc4a_init 
 Dim i, j, klen, k(256), k2(256) 
 klen = Len(strKey) 
  
 For i = 0 To 255 
  s(i) = i 
  s2(i) = i 
  k(i) = Asc(Mid(strKey, (i Mod klen) + 1, 1)) 
 Next 
  
 j = 0 
 For i = 0 To 255 
  j = (j + k(i) + s(i)) And 255 
  swap s, i, j 
 Next 
  
 rc4_drop 
 For i = 0 To 255 
  k2(i) = rc4_output 
 Next 
  
 j = 0 
 For i = 0 To 255 
  j = (j + k2(i) + s2(i)) And 255 
  swap s2, i, j 
 Next 
End Sub   Sub rc4_drop 
 Dim i 
  
 For i = 1 To 3072 
  x = (x + 1) And 255 
  y = (y + s(x)) And 255 
  Swap s, x, y 
 Next 
End Sub   Function rc4_output 
 x = (x + 1) And 255 
 y = (y + s(x)) And 255 
 Swap s, x, y 
  
 rc4_output = s((s(x) + s(y)) And 255) 
End Function   Function rc4a_output1 
 x = (x + 1) And 255 
 y = (y + s(x)) And 255 
 Swap s, x, y 
 rc4a_output1 = s2((s(x) + s(y)) And 255) 
End Function   Function rc4a_output2 
 y2 = (y2 + s2(x)) And 255 
 Swap s2, x, y2 
 rc4a_output2 = s((s2(x) + s2(y2)) And 255) 
End Function 

<message edited by angryrabbit on Thursday, December 02, 2010 7:38 AM>
 
#1
    gohwh1

    • Total Posts : 3
    • Scores: 0
    • Reward points : 0
    • Joined: 3/23/2011
    • Status: offline
    Re:RC4 Encryption modified Wednesday, March 23, 2011 6:05 PM (permalink)
    0
    I edit the strMessage to hardcore-dded into the script, encrypt work but when decrypt it give an error Type mismatch:'CLng'
     
    #2
      angryrabbit

      • Total Posts : 36
      • Scores: 2
      • Reward points : 0
      • Joined: 11/23/2010
      • Status: offline
      Re:RC4 Encryption modified Thursday, March 24, 2011 6:03 AM (permalink)
      0
      It's likely that the cipher text you inputted was exactly what was outputted. It has to be a valid hexadecimal string with no other characters. There's no checking in there to make sure it's valid.
       
      #3

        Online Bookmarks Sharing: Share/Bookmark

        Jump to:

        Current active users

        There are 0 members and 1 guests.

        Icon Legend and Permission

        • New Messages
        • No New Messages
        • Hot Topic w/ New Messages
        • Hot Topic w/o New Messages
        • Locked w/ New Messages
        • Locked w/o New Messages
        • Read Message
        • Post New Thread
        • Reply to message
        • Post New Poll
        • Submit Vote
        • Post reward post
        • Delete my own posts
        • Delete my own threads
        • Rate post

        2000-2012 ASPPlayground.NET Forum Version 3.9