Last active
July 29, 2016 06:43
-
-
Save charlietuna/a1d5ab16729ffd1157fdafde7e0fc09a to your computer and use it in GitHub Desktop.
RC4 in Swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func RC4(๐:[UInt8], ๐:[Int]) -> [UInt8] | |
{ | |
var i = 0, j = 0, S = Array(0...255) | |
for i in 0...255 { | |
j = (j + S[i] + ๐[i % ๐.count]) % 256 | |
(S[j], S[i]) = (S[i], S[j]) | |
} | |
i = 0; j = 0 | |
return ๐.map { | |
i = (i + 1) % 256; j = (j + S[i]) % 256 | |
(S[j], S[i]) = (S[i], S[j]) | |
return $0 ^ UInt8(S[(S[i] + S[j]) % 256]) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment