These are the notes for Cybersecurity Fundamentals (defensive), episode 2. Last time we learned assets, threats, vulnerabilities and risk. Today's question sounds simple: what does "secure" actually mean? It means several different promises, and we invent each one by breaking a small Python program and fixing it: confidentiality (a notice board leaks phone numbers), integrity (a payment changes from 500 to 5000), authenticity (the attacker re-makes the fingerprint, so we add a secret key: HMAC), non-repudiation (why a shared key can't prove who sent it), availability (one bad request crashes the service), AAA (authentication, authorization, accounting) and accountability, the Parkerian hexad (possession, utility), privacy vs security, and the trade-offs between C, I and A. Every word is explained the first time it appears, and the Glossary at the end defines them all again with an example. Every code sample runs as-is; outputs are real (Python 3).
The problems you'll solve
| Problem | What it teaches |
|---|---|
| Phone numbers on a notice board | Confidentiality, data masking, access control |
| 500 becomes 5000 on the way | Integrity, hashes as fingerprints |
| The attacker re-makes the fingerprint | Authenticity, HMAC (a keyed hash), constant-time comparison |
| "I never sent that" | Non-repudiation, why it needs digital signatures |
| One bad request kills the service | Availability, error handling |
| Who did what? | AAA: authentication, authorization, accounting; accountability |
| Three isn't enough | Parkerian hexad: possession or control, utility; privacy vs security |
| You can't max out all three | Trade-offs between confidentiality, integrity and availability |
Problem 1: confidentiality
Results day. The class teacher prints the marks list from the school computer and pins it on the notice board, but the printout also has every student's phone number. A week later, strangers call: "You won a prize!" Information reached people who were never meant to see it.
Demo 1: print everything (the leak)
# the class notice board, printed from a list
students = [
{"name": "Asha", "phone": "9876543210", "marks": 91},
{"name": "Ravi", "phone": "9123456780", "marks": 78},
]
for s in students:
print(s)
Output:
{'name': 'Asha', 'phone': '9876543210', 'marks': 91}
{'name': 'Ravi', 'phone': '9123456780', 'marks': 78}
The code works perfectly. It just shows too much.
Demo 1b: print only what's needed, mask the rest
Masking means hiding part of a value so it's still recognisable but not usable, like a bank showing only the last four digits of your card.
# print only what the notice board needs
students = [
{"name": "Asha", "phone": "9876543210", "marks": 91},
{"name": "Ravi", "phone": "9123456780", "marks": 78},
]
def mask(phone):
return "******" + phone[-4:] # keep the last 4
for s in students:
print(s["name"], s["marks"], "phone", mask(s["phone"]))
Output:
Asha 91 phone ******3210
Ravi 78 phone ******6780
Confidentiality means only the right people can see the information. It breaks through leaks, snooping, a lost phone, or an email sent to the wrong person. It's protected by access control (deciding who may see what), by masking, and by encryption (scrambling data so only someone with the key can read it; episode 10).
The US standard FIPS 199 (Federal Information Processing Standard 199), quoting US law (44 U.S.C. § 3542), defines confidentiality as "preserving authorized restrictions on information access and disclosure, including means for protecting personal privacy and proprietary information".
Problem 2: integrity and authenticity
Asha sends her bank a note: "pay Ravi 500". Nothing secret about it. On the way, someone adds a zero: "pay Ravi 5000". The bank pays 5000, because it can't tell anything changed. Confidentiality didn't help: the attacker didn't read anything secret, they changed something.
A box of sweets explains the fix:
| A box of sweets | In security | Meaning |
|---|---|---|
| A tamper-proof seal | Hash | A short fingerprint calculated from data; change one letter and the fingerprint changes completely |
| The shop's own wax stamp | HMAC (hash-based message authentication code) | A fingerprint made with a secret key, so only key holders can make a valid one |
Demo 2: a hash catches the change
Python's hashlib module computes hashes. SHA-256 is a standard hash function (Secure Hash Algorithm, 256-bit output; episode 13 covers hashes fully). We keep the first 16 hex characters so it fits on screen; real systems keep all 64.
import hashlib
def fingerprint(text):
return hashlib.sha256(text.encode()).hexdigest()[:16]
sent = "pay Ravi 500"
tag = fingerprint(sent) # travels with the message
received = "pay Ravi 5000" # changed on the way
print("tag sent: ", tag)
print("tag of received:", fingerprint(received))
print("match?", fingerprint(received) == tag)
Output:
tag sent: 3589a8aed317f89a
tag of received: 6962eefe36ddae55
match? False
Caught. Keeping data correct and unchanged, and noticing when it isn't, is integrity.
Demo 2b: the attacker re-makes the hash
import hashlib
def fingerprint(text):
return hashlib.sha256(text.encode()).hexdigest()[:16]
# the attacker changes the message AND re-makes the tag
received = "pay Ravi 5000"
tag = fingerprint(received) # anyone can do this
print("match?", fingerprint(received) == tag)
print("bank pays:", received)
Output:
match? True
bank pays: pay Ravi 5000
Why it failed: a plain hash has no secret. Anyone can compute SHA-256. A plain hash catches accidents (a corrupted download, a bad disk), not attackers who can re-make it.
Demo 2c: a secret key (HMAC)
import hmac, hashlib
KEY = b"asha-and-bank-only" # a secret the two share
def tag(text, key):
mac = hmac.new(key, text.encode(), hashlib.sha256)
return mac.hexdigest()[:16]
real = "pay Ravi 500"
real_tag = tag(real, KEY)
fake = "pay Ravi 5000"
fake_tag = tag(fake, b"attacker-guess") # no real key
ok_real = hmac.compare_digest(tag(real, KEY), real_tag)
ok_fake = hmac.compare_digest(tag(fake, KEY), fake_tag)
print("real message: ", ok_real)
print("attacker's message:", ok_fake)
Output:
real message: True
attacker's message: False
Without the key, the attacker can't make a valid tag. Now the bank knows the note is unchanged and that it came from someone holding the key: Asha. Proving where something really came from is authenticity.
hmac.compare_digest compares two values in constant time: it takes the same time whether the first or the last character differs, so an attacker timing the check learns nothing. Plain == can stop at the first difference. (Episode 27 covers these "timing side channels".)
This is a toy. Real keys are long random values from a secure random generator (
secrets.token_bytes(32)), never a readable phrase in code.
Non-repudiation
Suppose Asha later says: "I never sent that, the bank made it up." With HMAC, Asha and the bank hold the same key, so either could have made the tag. A judge can't tell who did. Non-repudiation is the promise that a sender can't deny sending something (to repudiate is to deny). It needs a proof only the sender can make: a digital signature, where only the sender holds the private signing key (episode 16).
| Integrity | Authenticity | Non-repudiation | |
|---|---|---|---|
| Plain hash (SHA-256) | Accidents only | No | No |
| HMAC (shared key) | Yes | Yes, to the key holders | No: both sides hold the key |
| Digital signature (private key) | Yes | Yes | Yes |
FIPS 199 defines integrity as "guarding against improper information modification or destruction", which "includes ensuring information nonrepudiation and authenticity".
Problem 3: availability
An ATM holds your money perfectly safely: nobody stole it, nobody changed your balance. But at 11 pm it says "temporarily out of service". Safe, correct, and useless. Being able to use something when you need it is availability. FIPS 199: "ensuring timely and reliable access to and use of information".
Demo 3: one bad request crashes everyone
A service is a program that answers requests from many users. Requests here are text like "90,80,70".
# a tiny "average marks" service, many users, one loop
def average(marks_text):
marks = [int(m) for m in marks_text.split(",")]
return sum(marks) / len(marks)
requests = ["90,80,70", "abc", "60,70"]
for r in requests:
print(r, "->", average(r))
Output:
90,80,70 -> 80.0
Traceback (most recent call last):
File "main.py", line 9, in <module>
print(r, "->", average(r))
~~~~~~~^^^
File "main.py", line 3, in average
marks = [int(m) for m in marks_text.split(",")]
~~~^^^
ValueError: invalid literal for int() with base 10: 'abc'
The third user, who sent good data, got nothing. If someone sends junk on purpose, again and again, nobody can use the service: the idea behind a denial-of-service (DoS) attack (episode 23).
Demo 3b: reject the bad request, keep serving
try runs code; if it raises the named error, except handles it instead of crashing.
def average(marks_text):
marks = [int(m) for m in marks_text.split(",")]
return sum(marks) / len(marks)
requests = ["90,80,70", "abc", "60,70"]
for r in requests:
try:
print(r, "->", average(r))
except ValueError as e: # one bad request
print(r, "-> rejected:", e) # ...not a dead service
Output:
90,80,70 -> 80.0
abc -> rejected: invalid literal for int() with base 10: 'abc'
60,70 -> 65.0
Availability breaks through crashes, floods of fake traffic, power cuts, hardware failure and ransomware (malicious software that locks your files and demands payment). It's protected by careful error handling, backups, spare servers (redundancy) and capacity planning.
The CIA triad
| Letter | Promise | Question it answers | Broken by |
|---|---|---|---|
| Confidentiality | Only the right people see it | Who can see it? | Leaks, snooping, a lost laptop |
| Integrity | It's correct and unchanged | Is it unchanged? | Tampering, corruption, bugs |
| Availability | It works when needed | Can I use it? | Crashes, DoS, ransomware, outages |
A triad is a group of three. "CIA" has nothing to do with the spy agency.
Problem 4: who did what? (AAA)
At a hotel: you show your ID at the desk, your key opens only room 204, and the bill lists every minibar snack with the time.
| Hotel | In security | Question |
|---|---|---|
| Show your ID at the desk | Authentication: proving who you are (password, OTP, fingerprint) | Who are you? |
| Your key opens room 204 only | Authorization: deciding what you're allowed to do | What may you do? |
| The bill lists every snack, with the time | Accounting: recording what each person did | What did you do? |
Together: AAA, "triple A".
Demo 4: all three A's in one function
PASSWORDS = {"asha": "chai@123", "ravi": "cricket7"} # toy
ROLE = {"asha": "teacher", "ravi": "student"}
log = []
def change_marks(user, password, marks):
if PASSWORDS.get(user) != password: # 1. authentication
log.append(f"{user}: wrong password")
return "who are you?"
if ROLE[user] != "teacher": # 2. authorization
log.append(f"{user}: tried to change marks")
return "not allowed"
log.append(f"{user}: set marks to {marks}") # 3. accounting
return "done"
print(change_marks("ravi", "guess", 100))
print(change_marks("ravi", "cricket7", 100))
print(change_marks("asha", "chai@123", 85))
for line in log: print("log:", line)
Output:
who are you?
not allowed
done
log: ravi: wrong password
log: ravi: tried to change marks
log: asha: set marks to 85
Toy only: real systems never store passwords as plain text. Episode 14 shows how to store them (salted, slow hashes like Argon2id).
Ravi with his real password is authenticated (we know he's Ravi) but not authorized (students can't change marks). Because every action is tied to one identified person in the log, we can hold that person responsible: accountability. Accounting is the record; accountability is what the record makes possible.
Problem 5: three isn't enough (the Parkerian hexad)
Two puzzles CIA can't describe:
- A thief steals a sealed envelope with your debit card and PIN. Nobody has read the PIN yet, so confidentiality isn't broken. But you've clearly lost something: possession.
- You encrypt a file and lose the key. It's still secret, unchanged and on your disk, so C, I and A look fine. But you can't use it: utility is lost.
In 1998, security researcher Donn B. Parker proposed six elements in his book Fighting Computer Crime: A New Framework for Protecting Information. They're called the Parkerian hexad (a hexad is a group of six):
| Element | Meaning | Example of a loss |
|---|---|---|
| Confidentiality | Only the right people see it | Phone numbers on a notice board |
| Possession or control | You still hold and control it | The stolen sealed envelope |
| Integrity | Correct and unchanged | 500 → 5000 |
| Authenticity | Really from its claimed source | A fake "bank" SMS |
| Availability | Usable when needed | The ATM out of service |
| Utility | Useful in practice | Encrypted data whose key is lost |
Privacy vs security
| Privacy | Security |
|---|---|
| A person's rights over their personal data | The protection that keeps promises about data |
| What may be collected? Who may it be shared with? How long is it kept? Can you see or delete it? | Locks, passwords, encryption, access control, backups, logs |
An app can be very secure and still bad for privacy, if it carefully guards data it should never have collected. The best protection for the phone numbers on the notice board was not printing them at all. Collecting only what you need is called data minimisation.
Problem 6: trade-offs between C, I and A
Gold in a bank locker is very safe but reachable only in bank hours (more C, less A). Gold in a cupboard at home is reachable in a second but less safe (more A, less C). Families decide per item: wedding jewellery in the locker, daily earrings at home. Security decides per asset, using risk (episode 1).
| Turning this up... | ...can turn this down |
|---|---|
| More encryption and checks (C, I) | Speed; and a lost key kills availability |
| More copies and backups (A) | More places to leak from (C), more copies to keep correct (I) |
| An OTP on every click | Usability: annoyed people find shortcuts |
A hospital's patient records need far more protection than the canteen's lunch menu.
Common mistakes (and what they print)
| Mistake | Real output | Why | Fix |
|---|---|---|---|
print(student) (whole record) |
{'name': 'Asha', 'phone': '9876543210', 'marks': 91} |
Shows more than the reader needs (C) | Print only needed fields; mask the rest |
Plain hashlib.sha256(...) to stop tampering |
match? True (attacker re-made it) |
A plain hash has no secret | Use a key: hmac.new(key, msg, hashlib.sha256) |
Comparing tags with == |
Works, but can leak timing | == may stop at the first difference |
hmac.compare_digest(a, b) |
average("abc") with no error handling |
ValueError: invalid literal for int() with base 10: 'abc' |
One bad request stops everyone (A) | try / except: reject it, keep serving |
| "The user logged in, so allow it" | A student changes his own marks | Authentication is not authorization | Check the role too, and log every attempt |
| "We use HMAC, so they can't deny it" | Either side could have made the tag | A shared key gives no non-repudiation | Digital signatures (episode 16) |
Mini project: a tamper-evident marks file
Store each student's marks with an HMAC tag. When the file is loaded, verify every row and report any row that was changed.
import hmac, hashlib
KEY = b"school-secret-key" # toy; real keys come from secrets.token_bytes(32)
def tag(row):
return hmac.new(KEY, row.encode(), hashlib.sha256).hexdigest()
rows = ["asha,91", "ravi,78", "meena,85"]
stored = [(r, tag(r)) for r in rows] # saved together
stored[1] = ("ravi,98", stored[1][1]) # someone edits Ravi's marks
for row, t in stored:
ok = hmac.compare_digest(tag(row), t)
print(f"{row:<10} {'OK' if ok else 'TAMPERED'}")
Output:
asha,91 OK
ravi,98 TAMPERED
meena,85 OK
Practice
- Mask an email address so
asha.k@gmail.comprints asa*****@gmail.com. - Change one letter of
"pay Ravi 500"and print both SHA-256 hashes in full. How many of the 64 characters stay the same? - Add a
"principal"role to Demo 4 that may read marks but not change them. Writeread_marks(user, password). - Which letter of the CIA triad does each break? (a) a DDoS attack takes a shopping site offline; (b) a virus changes figures in a spreadsheet; (c) a laptop with customer data is left in a taxi.
- Is a plain hash enough to check that a file you downloaded wasn't corrupted? Is it enough to stop an attacker who controls the download site?
Solutions
1.
def mask_email(email):
name, domain = email.split("@")
return name[0] + "*" * (len(name) - 1) + "@" + domain
print(mask_email("asha.k@gmail.com"))
Output:
a*****@gmail.com
- (Run it: almost every character changes. That's the avalanche effect, episode 13.)
import hashlib
for m in ["pay Ravi 500", "pay Ravi 501"]:
print(hashlib.sha256(m.encode()).hexdigest())
3.
PASSWORDS = {"asha": "chai@123", "ravi": "cricket7", "dr_rao": "school#1"}
ROLE = {"asha": "teacher", "ravi": "student", "dr_rao": "principal"}
MARKS = {"ravi": 78}
def read_marks(user, password):
if PASSWORDS.get(user) != password:
return "who are you?"
if ROLE[user] not in ("teacher", "principal"):
return "not allowed"
return MARKS
print(read_marks("dr_rao", "school#1"))
print(read_marks("ravi", "cricket7"))
Output:
{'ravi': 78}
not allowed
- (a) availability; (b) integrity; (c) confidentiality (and possession, in the hexad).
- For corruption: yes, compare against the hash published by the source. Against an attacker who controls the site: no, they can publish a new hash too. You need something they can't forge: a key they don't have (HMAC) or a digital signature from the publisher.
Quick quiz
A hospital's records are encrypted. Nobody stole or changed anything. But ransomware locked the files, and doctors can't open them for two days. Which letter broke?
A. confidentiality · B. integrity · C. availability · D. non-repudiation
Answer
C, availability. Nothing was seen and nothing was changed, but the records couldn't be used when they were needed.
Interview questions
- Explain the CIA triad with an example of each being broken. Confidentiality: only authorised people see data (a leaked database breaks it). Integrity: data is correct and unchanged (a tampered transaction). Availability: systems work when needed (a DoS attack).
- Authentication vs authorization? Authentication proves who you are; authorization decides what you may do. You can be authenticated and still not authorized.
- Why isn't a hash enough to prove a message wasn't tampered with by an attacker? Anyone can recompute a plain hash after changing the message. You need a keyed MAC (like HMAC) or a digital signature.
- Does HMAC give non-repudiation? No. Both parties share the key, so either could have produced the tag. Non-repudiation needs a digital signature made with a private key only the signer holds.
- What is AAA? Authentication, authorization and accounting. Accounting (logging who did what) enables accountability.
- What does the Parkerian hexad add to CIA? Possession or control, utility, and (as its own element) authenticity.
- Give a trade-off between confidentiality and availability. Encrypting everything with keys held by one person protects confidentiality but if that person or key is lost, availability is gone. Backups help availability but add more copies that could leak.
- Privacy vs security? Privacy is about what personal data may be collected and how it's used; security is the set of protections that enforce those promises.
Glossary
| Term | Meaning in plain words | Example |
|---|---|---|
| Confidentiality | Only the right people can see the information | Marks on the board, phone numbers hidden |
| Integrity | Data is correct and unchanged, and changes are noticed | "pay Ravi 500" stays 500 |
| Availability | The system works when the right people need it | The marks service keeps answering |
| CIA triad | Confidentiality, integrity and availability together | The three questions: who sees it, is it unchanged, can I use it |
| Authenticity | Proof that something really came from its claimed source | The bank knows the note is from Asha |
| Non-repudiation | The sender can't deny having sent something | A digitally signed contract |
| Accountability | Every action can be traced to one person, who is responsible | "ravi: tried to change marks" in the log |
| AAA | Authentication, authorization, accounting | Hotel: ID check, room key, itemised bill |
| Authentication | Proving who you are | Entering the right password |
| Authorization | Deciding what an identified user may do | Only teachers may change marks |
| Accounting (security) | Recording who did what, and when | The log list |
| Access control | Rules and mechanisms deciding who may see or do what | The role check in change_marks |
| Masking | Hiding part of a value so it's recognisable but not usable | ******3210 |
| Encryption | Scrambling data so only someone with the key can read it | A locked WhatsApp message (episode 10) |
| Hash | A short fingerprint computed from data; any change gives a different fingerprint | SHA-256 of "pay Ravi 500" |
| SHA-256 | A standard cryptographic hash function with a 256-bit output | hashlib.sha256(...) |
| HMAC | A hash made with a secret key, so only key holders can make a valid one | hmac.new(KEY, msg, hashlib.sha256) |
| Digital signature | A proof made with a private key only the signer holds | Episode 16 |
| Constant-time comparison | A comparison that takes the same time wherever the values differ | hmac.compare_digest |
| Service | A program that answers requests from many users | The average-marks loop |
| Denial of service (DoS) | Making a service unavailable to its real users | Flooding it with junk requests |
| Ransomware | Malicious software that locks files and demands payment | Hospital records locked for two days |
| Redundancy | Spare copies or machines that take over when one fails | A second server, a backup |
| Parkerian hexad | Donn Parker's six elements (1998): C, possession, I, authenticity, A, utility | — |
| Possession or control | You still hold and control the information | Lost when the sealed envelope is stolen |
| Utility | The information is still useful in practice | Lost when the decryption key is lost |
| Privacy | A person's rights over their personal data | What an app may collect about you |
| Data minimisation | Collecting and showing only the data you really need | Not printing phone numbers at all |
| FIPS 199 | A US federal standard that defines C, I and A and how to rate them | "Preserving authorized restrictions on..." |
Summary
- Confidentiality: only the right people see it. Protect with access control, masking, encryption, and by not collecting what you don't need.
- Integrity: it's correct and unchanged. A plain hash catches accidents; an attacker can re-make it.
- Authenticity: it really came from who it claims. HMAC (a keyed hash) gives integrity and authenticity between key holders. Compare tags with
hmac.compare_digest. - Non-repudiation: the sender can't deny it; needs digital signatures, not a shared key.
- Availability: it works when needed. One unhandled error can take a service down for everyone; handle bad input and keep serving.
- AAA: authentication (who), authorization (what may you do), accounting (what did you do), which enables accountability.
- The Parkerian hexad adds possession or control and utility. Privacy is about rights over personal data; security enforces the promises.
- You can't max out C, I and A at once: choose per asset, using risk.
Next episode: core security design principles: least privilege, defence in depth, fail secure, secure by default, complete mediation, open design and Kerckhoffs's principle.
Sources: NIST FIPS 199, definitions from 44 U.S.C. § 3542; Wikipedia, "Parkerian Hexad" (Donn B. Parker, Fighting Computer Crime, Wiley, 1998). Fetched 27 Oct 2026.