Guest User

RC4 Encryption Source

a guest
Apr 7th, 2011
2,978
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.75 KB | None | 0 0
  1. Private Shared Function Proper_RC4(ByVal Input As Byte(), ByVal Key As Byte()) As Byte()
  2.   'Leave a thanks at least..
  3.   'by d3c0mpil3r from HF
  4.   Dim i, j, swap As UInteger
  5.   Dim s As UInteger() = New UInteger(255) {}
  6.   Dim Output As Byte() = New Byte(Input.Length - 1) {}
  7.  
  8.   For i = 0 To 255
  9.     s(i) = i
  10.   Next
  11.  
  12.   For i = 0 To 255
  13.     j = (j + Key(i Mod Key.Length) + s(i)) And 255
  14.     swap = s(i) 'Swapping of s(i) and s(j)
  15.     s(i) = s(j)
  16.     s(j) = swap
  17.   Next
  18.  
  19.   i = 0 : j = 0
  20.   For c = 0 To Output.Length - 1
  21.     i = (i + 1) And 255
  22.     j = (j + s(i)) And 255
  23.     swap = s(i) 'Swapping of s(i) and s(j)
  24.     s(i) = s(j)
  25.     s(j) = swap
  26.     Output(c) = Input(c) Xor s((s(i) + s(j)) And 255)
  27.   Next
  28.  
  29.   Return Output
  30.     End Function
Advertisement
Add Comment
Please, Sign In to add comment