Advertisement
DontPanic284

Untitled

Jul 31st, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.70 KB | None | 0 0
  1. func decode(input: String, key: String) -> String {
  2.         let inputBytes = input.utf8
  3.         let keyBytes = key.utf8
  4.         var keyIndex = 0
  5.        
  6.         var inputArray = [UInt8] (inputBytes)
  7.         var keyArray = [UInt8] (keyBytes)
  8.        
  9.         for i in 0..<inputArray.count {
  10.             print("input \(i) = \(inputArray[i])")
  11.             print("key \(i) = \(keyArray[keyIndex])")
  12.             inputArray[i] = inputArray[i] ^ keyArray[keyIndex]
  13.             keyIndex = keyIndex + 1
  14.            
  15.             if (keyIndex == keyArray.count) {
  16.                 keyIndex = 0
  17.             }
  18.         }
  19.        
  20.         return String(bytes: inputArray, encoding: String.Encoding.utf8)!
  21.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement