Battery vs Security Explorer
Try Change Encryption Algorithm, then press Calculate battery life.
Observe After Calculate battery life, compare Modeled battery life, Capacity Lost to Encryption, and Overhead.
Explain Explain why Calculate battery life changes modeled battery life with encryption overhead.
Calculate battery life
Reset
Technical boundaries. Battery-life penalties are illustrative scenario assumptions, not cipher properties. Measure the actual device and implementation; security suitability requires a separate assessment.
Explore the real-world impact of encryption choices on battery life for IoT devices.
colors = ({
navy : "#2C3E50" ,
teal : "#16A085" ,
orange : "#E67E22" ,
blue : "#3498DB" ,
gray : "#7F8C8D" ,
purple : "#9B59B6" ,
red : "#E74C3C"
})
viewof batteryCapacity = Inputs. range ([100 , 500 ], {
value : 180 ,
step : 10 ,
label : "Battery Capacity (mAh)" ,
width : 350
})
viewof targetDays = Inputs. range ([1 , 30 ], {
value : 7 ,
step : 1 ,
label : "Target Battery Life (days)" ,
width : 350
})
viewof encryptionChoice = Inputs. radio (
["None" , "ChaCha20-Poly1305" , "AES-128-GCM" , "AES-256-GCM" ],
{
value : "ChaCha20-Poly1305" ,
label : "Encryption Algorithm"
}
)
// Illustrative scenario assumptions: percentage battery-life penalty relative to no encryption;
// measure the actual device and implementation rather than treating these as cipher properties.
encryptionOverhead = ({
"None" : 0 ,
"ChaCha20-Poly1305" : 7.5 ,
"AES-128-GCM" : 12 ,
"AES-256-GCM" : 15
})
// Calculate effective capacity
baseConsumption = batteryCapacity / targetDays
overhead = encryptionOverhead[encryptionChoice] / 100
effectiveCapacity = batteryCapacity * (1 - overhead)
actualDays = effectiveCapacity / baseConsumption
batteryReduction = batteryCapacity - effectiveCapacity
// Results display
html `<div style="margin: 20px 0; padding: 20px; background: ${ colors. navy } ; color: white; border-radius: 8px;">
<h3 style="margin-top: 0; color: ${ colors. teal } ;">Results for ${ encryptionChoice} </h3>
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(145px, 1fr)); gap: 16px; margin-top: 15px;">
<div>
<div style="font-size: 24px; font-weight: bold; color: ${ colors. orange } ;"> ${ actualDays. toFixed (2 )} days</div>
<div style="font-size: 14px; opacity: 0.9;">Modeled battery life</div>
</div>
<div>
<div style="font-size: 14px; font-weight: bold; color: ${ colors. teal } ;">Assess the complete authenticated-encryption implementation</div>
<div style="font-size: 14px; opacity: 0.9;">Security suitability</div>
</div>
<div>
<div style="font-size: 20px; font-weight: bold; color: ${ colors. red } ;"> ${ batteryReduction. toFixed (1 )} mAh</div>
<div style="font-size: 14px; opacity: 0.9;">Capacity Lost to Encryption</div>
</div>
<div>
<div style="font-size: 20px; font-weight: bold; color: ${ colors. purple } ;"> ${ encryptionOverhead[encryptionChoice]} %</div>
<div style="font-size: 14px; opacity: 0.9;">Overhead</div>
</div>
</div>
</div>`
allOptions = Object . keys (encryptionOverhead). map (enc => ({
algorithm : enc,
batteryDays : (batteryCapacity * (1 - encryptionOverhead[enc]/ 100 ) / baseConsumption). toFixed (2 ),
overhead : encryptionOverhead[enc]
}))
maxBatteryDays = Math . max (... allOptions. map (d => parseFloat (d. batteryDays )))
html `<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(185px, 1fr)); gap: 12px; margin: 18px 0;">
${ allOptions. map (d => {
const selected = d. algorithm === encryptionChoice;
const batteryWidth = Math . max (4 , parseFloat (d. batteryDays ) / maxBatteryDays * 100 ). toFixed (0 );
return `
<div style="background: ${ selected ? '#fff7ed' : '#ffffff' } ; border: 2px solid ${ selected ? colors. orange : '#d9e5ea' } ; border-radius: 12px; padding: 12px; box-shadow: 0 8px 20px rgba(15,23,42,0.06);">
<div style="display: flex; justify-content: space-between; gap: 8px; align-items: baseline; margin-bottom: 8px;">
<strong style="color: ${ colors. navy } ;"> ${ d. algorithm } </strong>
<span style="font-size: 0.78rem; color: ${ selected ? colors. orange : colors. gray } ; font-weight: 700;"> ${ selected ? 'SELECTED' : ` ${ d. overhead } % overhead` } </span>
</div>
<div style="font-size: 0.88rem; color: ${ colors. navy } ; margin-bottom: 5px;">Modeled battery life: <strong> ${ d. batteryDays } days</strong></div>
<div style="height: 10px; border-radius: 999px; background: #e8eef3; overflow: hidden; margin-bottom: 10px;">
<div style="height: 100%; width: ${ batteryWidth} %; background: ${ colors. teal } ;"></div>
</div>
</div>
` ;
}). join ('' )}
</div>`
md `**Key Insight**: Under these assumed loads, moving from AES-256-GCM to ChaCha20-Poly1305 halves encryption energy overhead; security suitability requires a separate assessment. Battery figures are modeled from the stated assumptions. Your current choice (** ${ encryptionChoice} **) gives ** ${ actualDays. toFixed (1 )} days** of modeled battery life.`
Back to the chapter