Skip to content

Instantly share code, notes, and snippets.

@jeksys
Last active August 29, 2015 14:15
Show Gist options
  • Save jeksys/b9b1ef7b21fd434eb322 to your computer and use it in GitHub Desktop.
Save jeksys/b9b1ef7b21fd434eb322 to your computer and use it in GitHub Desktop.
xorcrypto
let text = [UInt8]("hello!!!".utf8)
let cipher = [UInt8]("good".utf8)
var encrypted = [UInt8]()
// encrypt bytes
for t in enumerate(text) {
encrypted.append(t.element ^ cipher[t.index%cipher.count])
}
println(encrypted)
var decrypted = [UInt8]()
// decrypt bytes
for t in enumerate(encrypted) {
decrypted.append(t.element ^ cipher[t.index%cipher.count])
}
String(bytes: decrypted, encoding: NSUTF8StringEncoding)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment