import Foundation classRC4 { var state = [UInt8](repeating: 0, count: 256) init(key: [UInt8]) { var j:Int=0 for i in0..<256 { state[i] =UInt8(i) } for i in0..<256 { j = (j +Int(state[i]) +Int(key[i % key.count])) %256 state.swapAt(i, j) } } funcencrypt(data: inout [UInt8]){ var x: Int=0 var y: Int=0 for i in0..<data.count { x = (x +1) %256 y = (y +Int(state[x])) %256 let temp = state[x] state[x]=state[y] state[y]=temp let t = state[(Int(state[x]) +Int(state[y])) %256] data[i] = data[i] ^ t } } } let key: [UInt8] =Array("qwq".utf8) let rc4=RC4(key: key) var text: [UInt8] =Array("straw".utf8) rc4.encrypt(data: &text) for i in0..<text.count{ var texthex=String(format: "0x%02x", text[i]) print("\(texthex)") }