我们有2个字段,包含消息和密钥。将它们转换为字节并对消息和密钥的每个字节使用^
(它可以小于实际消息长度,这就是我们在那里使用%的原因)
@IBOutlet weak var messageToEncrypt: UITextField!
@IBOutlet weak var encryptionKey: UITextField!
@IBOutlet weak var cryptResult: UITextField!
@IBOutlet weak var decryptResult: UITextField!
@IBAction func encryptFunc(sender: AnyObject) {
let mte = messageToEncrypt.text;
let kte = encryptionKey.text;
var mte_byteArray = [UInt8]();
var kte_byteArray = [UInt8]();
for char in mte!.utf8{
mte_byteArray += [char]
}
for char1 in kte!.utf8{
kte_byteArray += [char1]
}
var counT: Int = mte_byteArray.count;
var cryptedSum = [UInt8](count: counT, repeatedValue: 0);
for i in 0...mte_byteArray.count{
cryptedSum[i] = mte_byteArray[i] ^ kte_byteArray[i%kte_byteArray.count];
}
print(cryptedSum);
}
这里我有这个问题
for i in 0...mte_byteArray.count{
cryptedSum[i] = mte_byteArray[i] ^ kte_byteArray[i%kte_byteArray.count];
}
致命错误:索引超出范围