Guest User

Untitled

a guest
May 20th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. Imports System.Text
  2. Module RC4Mod
  3. Public Function rc4(ByVal message As String, ByVal password As String) As String
  4. Dim i As Integer = 0
  5. Dim j As Integer = 0
  6. Dim cipher As New StringBuilder
  7. Dim returnCipher As String = String.Empty
  8. Dim sbox As Integer() = New Integer(256) {}
  9. Dim key As Integer() = New Integer(256) {}
  10. Dim intLength As Integer = password.Length
  11. Dim a As Integer = 0
  12. While a <= 255
  13. Dim ctmp As Char = (password.Substring((a Mod intLength), 1).ToCharArray()(0))
  14. key(a) = Microsoft.VisualBasic.Strings.Asc(ctmp)
  15. sbox(a) = a
  16. System.Math.Max(System.Threading.Interlocked.Increment(a), a - 1)
  17. End While
  18. Dim x As Integer = 0
  19. Dim b As Integer = 0
  20. While b <= 255
  21. x = (x + sbox(b) + key(b)) Mod 256
  22. Dim tempSwap As Integer = sbox(b)
  23. sbox(b) = sbox(x)
  24. sbox(x) = tempSwap
  25. System.Math.Max(System.Threading.Interlocked.Increment(b), b - 1)
  26. End While
  27. a = 1
  28. While a <= message.Length
  29. Dim itmp As Integer = 0
  30. i = (i + 1) Mod 256
  31. j = (j + sbox(i)) Mod 256
  32. itmp = sbox(i)
  33. sbox(i) = sbox(j)
  34. sbox(j) = itmp
  35. Dim k As Integer = sbox((sbox(i) + sbox(j)) Mod 256)
  36. Dim ctmp As Char = message.Substring(a - 1, 1).ToCharArray()(0)
  37. itmp = Asc(ctmp)
  38. Dim cipherby As Integer = itmp Xor k
  39. cipher.Append(Chr(cipherby))
  40. System.Math.Max(System.Threading.Interlocked.Increment(a), a - 1)
  41. End While
  42. returnCipher = cipher.ToString
  43. cipher.Length = 0
  44. Return returnCipher
  45. End Function
  46. End Module
Add Comment
Please, Sign In to add comment