Skip to content
Book 7: Computer Systems

Book 7 · Chapter 4

Data integrity and cybersecurity

§4.1§4.2Exam craftB7·4

This chapter is in the ebook.

Read it in full on cswithzak.com. Every question has its mark scheme and every program is ready to run. The free practice for each section is below, with the short code the book prints beside it.

Open in the ebook

§4.1 Data integrity

Short code B7·4·1

§4.2 Cybersecurity

Short code B7·4·2

How errors get into data

Short code B7·4·10

Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.

Parity bits

Short code B7·4·11

data = "1100101"
ones = 0
for bit in data:
    if bit == "1":
        ones = ones + 1
if ones % 2 == 0:
    print("even:", "0" + data, " odd:", "1" + data)
else:
    print("even:", "1" + data, " odd:", "0" + data)
Both parity bits for the data 1100101: count the 1s, then pick the bit that obeys each rule.

Output

even: 01100101  odd: 11100101
Run and checked before printing

Parity blocks and the parity byte

Short code B7·4·12

def ones(b):
    n = 0
    for bit in b:
        if bit == "1":
            n = n + 1
    return n
rows = ["01100101", "10101100", "00011011", "11011101"]
pbyte = ""
for c in range(8):
    col = ""
    for r in rows:
        col = col + r[c]
    if ones(col) % 2 == 0:
        pbyte = pbyte + "0"
    else:
        pbyte = pbyte + "1"
print("parity byte:", pbyte)
The parity byte for the block above, worked out column by column (even parity). Notice each column is counted on its own.

Output

parity byte: 00001111
Run and checked before printing

Echo checks and checksums

Short code B7·4·13

Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.

Check digits

Short code B7·4·14

Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.

Automatic repeat request

Short code B7·4·15

Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.

Choosing an error check

Short code B7·4·16

Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.

The five core principles

Short code B7·4·17

Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.

How the principles are threatened

Short code B7·4·18

Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.

Attacks on passwords, networks and servers

Short code B7·4·19

print("PIN, 4 digits:", 10 ** 4)
print("8 small letters:", 26 ** 8)
print("8 of a-z A-Z 0-9:", 62 ** 8)
How many passwords a brute-force attack might have to try. Each extra character multiplies the total.

Output

PIN, 4 digits: 10000
8 small letters: 208827064576
8 of a-z A-Z 0-9: 218340105584896
Run and checked before printing

Malware

Short code B7·4·20

Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.

Tricking people and websites

Short code B7·4·21

def build(name, pw):
    q = "SELECT * FROM Users"
    q = q + " WHERE Name = '" + name
    q = q + "' AND Password = '"
    return q + pw + "'"

print(build("ali", "secret123"))
print(build("ali", "x' OR '1'='1"))
A badly written log-in check joins the typed text into its query. Notice how the attacker's input changes the query's meaning.

Output

SELECT * FROM Users WHERE Name = 'ali' AND Password = 'secret123'
SELECT * FROM Users WHERE Name = 'ali' AND Password = 'x' OR '1'='1'
Run and checked before printing

Keeping people and accounts safe

Short code B7·4·22

Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.

Guarding software and networks

Short code B7·4·23

Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.

Why encrypt?

Short code B7·4·24

Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.

Symmetric and asymmetric encryption

Short code B7·4·25

def xor(bits, key):
    out = ""
    for i in range(len(bits)):
        if bits[i] == key[i]:
            out = out + "0"
        else:
            out = out + "1"
    return out

plain = "01001000"
key = "10110110"
cipher = xor(plain, key)
print("ciphertext:", cipher)
print("decrypted: ", xor(cipher, key))
A toy symmetric cipher: XOR each bit with the key. Running the same function with the same key decrypts.

Output

ciphertext: 11111110
decrypted:  01001000
Run and checked before printing

Past-paper practice

Short code B7·4·90

Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.

Workbook: Data integrity and cybersecurity

Short code W7·4 · Computer Systems Workbook

The write-in workbook for this chapter has drills, exam-style practice, trace tables, fix-the-mistake and mark-it-yourself pages. Its full mark schemes and an interactive version arrive here with the chapter.

Ask Z about Data integrity and cybersecurity
Buy ZAK's books — WhatsApp the books desk: Buy the booksPrint or ebook