RC4


SUBMITTED BY: Guest

DATE: May 27, 2013, 12:28 p.m.

FORMAT: Text only

SIZE: 3.3 kB

HITS: 1606

  1. ;===============================================================================
  2. ;
  3. ; Function Name: _StringEncryptRC4
  4. ; Description:: Encrypts text using RC4 Encryption
  5. ; Parameter(s): $text, $encryptkey
  6. ; Requirement(s): AutoIt
  7. ; Return Value(s): Encrypted String
  8. ; Author(s): RazerM
  9. ;
  10. ;===============================================================================
  11. ;
  12. Func _StringEncryptRC4($text, $encryptkey)
  13. Local $sbox[256]
  14. Local $key[256]
  15. Local $temp
  16. Local $a
  17. Local $i
  18. Local $j
  19. Local $k
  20. Local $cipherby
  21. Local $cipher
  22. $i = 0
  23. $j = 0
  24. __RC4Initialize($encryptkey, $key, $sbox)
  25. For $a = 1 To StringLen($text)
  26. $i = Mod(($i + 1),256)
  27. $j = Mod(($j + $sbox[$i]),256)
  28. $temp = $sbox[$i]
  29. $sbox[$i] = $sbox[$j]
  30. $sbox[$j] = $temp
  31. $k = $sbox[Mod(($sbox[$i] + $sbox[$j]),256)]
  32. $cipherby = BitXOR(Asc(StringMid($text, $a, 1)),$k)
  33. $cipher = $cipher & Chr($cipherby)
  34. Next
  35. Return _StringToHexEx($cipher)
  36. EndFunc ;==>_StringEncryptRC4
  37. ;===============================================================================
  38. ;
  39. ; Function Name: _StringDecryptRC4
  40. ; Description:: Decrypts text using RC4 Encryption
  41. ; Parameter(s): $text, $encryptkey
  42. ; Requirement(s): AutoIt
  43. ; Return Value(s): Decrypted String
  44. ; Author(s): RazerM
  45. ; Note(s): RC4 uses the same algorithm to encrypt and decrypt
  46. ;
  47. ;===============================================================================
  48. ;
  49. Func _StringDecryptRC4($text, $encryptkey)
  50. Local $sbox[256]
  51. Local $key[256]
  52. Local $temp
  53. Local $a
  54. Local $i
  55. Local $j
  56. Local $k
  57. Local $cipherby
  58. Local $cipher
  59. $text = _HexToStringEx($text)
  60. $i = 0
  61. $j = 0
  62. __RC4Initialize($encryptkey, $key, $sbox)
  63. For $a = 1 To StringLen($text)
  64. $i = Mod(($i + 1),256)
  65. $j = Mod(($j + $sbox[$i]),256)
  66. $temp = $sbox[$i]
  67. $sbox[$i] = $sbox[$j]
  68. $sbox[$j] = $temp
  69. $k = $sbox[Mod(($sbox[$i] + $sbox[$j]),256)]
  70. $cipherby = BitXOR(Asc(StringMid($text, $a, 1)),$k)
  71. $cipher = $cipher & Chr($cipherby)
  72. Next
  73. Return $cipher
  74. EndFunc ;==>_StringDecryptRC4
  75. ; Helper function
  76. Func __RC4Initialize($strPwd, ByRef $key, ByRef $sbox)
  77. Dim $tempSwap
  78. Dim $a
  79. Dim $b
  80. $intLength = StringLen($strPwd)
  81. For $a = 0 To 255
  82. $key[$a] = Asc(StringMid($strPwd, (Mod($a,$intLength))+1, 1))
  83. $sbox[$a] = $a
  84. Next
  85. $b = 0
  86. For $a = 0 To 255
  87. $b = Mod($b + $sbox[$a] + $key[$a],256)
  88. $tempSwap = $sbox[$a]
  89. $sbox[$a] = $sbox[$b]
  90. $sbox[$b] = $tempSwap
  91. Next
  92. EndFunc ;==>__RC4Initialize
  93. Func _HexToStringEx($strHex)
  94. Return BinaryToString("0x" & $strHex)
  95. EndFunc ;==>_HexToStringEx
  96. Func _StringToHexEx($strChar)
  97. Return Hex(StringToBinary($strChar))
  98. EndFunc

comments powered by Disqus