Skip to content

Instantly share code, notes, and snippets.

@charlietuna
Last active July 29, 2016 06:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charlietuna/a1d5ab16729ffd1157fdafde7e0fc09a to your computer and use it in GitHub Desktop.
Save charlietuna/a1d5ab16729ffd1157fdafde7e0fc09a to your computer and use it in GitHub Desktop.
RC4 in Swift
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