I have developed a simple iOS application that performs encryption and decryption to a randomly generated message. When deploying the application on an iPhone 8, the runtime sometimes varies. In most cases it is consistent. I am trying to understand why could the runtime sometimes vary. I make sure to have no other applications open at the time of running to ensure that no other apps are utilizing the iPhone's processors.
These are my action buttons that call the encrypt and decrypt functions, and this is how I measure the elapsed time:
@IBAction func enc(_ sender: Any) {
let info = ProcessInfo.processInfo
let begin = info.systemUptime
enc0.text = "Enc-c0: \(e0)"
enc1.text = "Enc-c1: \(e1)"
let time = (info.systemUptime - begin)
time1.text = "Enc Time: \(time)"
}
@IBAction func dec(_ sender: Any) {
let info = ProcessInfo.processInfo
let begin = info.systemUptime
let decryption = dDec(encryption0:e0,encryption1:e1)
dec.text = "Dec: \(decryption)"
let time = (info.systemUptime - begin)
time2.text = "Dec Time: \(time)"
}
These are the two functions being called:
func dEnc() -> (BigUInt,BigUInt){
let r:BigUInt = BigUInt.randomInteger(lessThan: (p-2))
let c0:BigUInt = x.power(_:r,modulus:p)
let a:BigUInt = m.power(_:1, modulus: p)
let b:BigUInt = (pub_m.multiplied(by: pub_r)).power(_:r, modulus: p)
let c1:BigUInt = a.multiplied(by: b).power(1, modulus: p)
return (c0, c1)
}
func dDec(encryption0:BigUInt, encryption1:BigUInt) -> BigUInt{
let a = encryption1
var b = encryption0.power(priv_m, modulus: p)
var c = encryption0.power(priv_r, modulus: p)
b = b.inverse(p)!
c = c.inverse(p)!
let d = ((a.multiplied(by: b)).multiplied(by: c)).power(1, modulus: p)
return (d)
}
The applications works fine, but the runtime sometimes varies. Is there something I need to handle to make sure that the runtime is consistent?