Book 3 · Chapter 17
Security
B3·17This 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.
For the whole chapter
- Topic pageSecurity
B3·17·T - QuizSecurity (A2)
B3·17·Q1 - LabRSA, signatures & the TLS handshake
B3·17·X1
§17.1 Encryption · Encryption protocols and digital certificates
Short code B3·17·1
- FlashcardsFlashcards §17.1: Encryption, signatures, certificates & TLS
B3·17·F1 - FlashcardsFlashcards §17.1: Digital signatures, certificates & TLS
B3·17·F2 - Past-paper questionsPast-paper questions §17.1 (encryption)
- Past-paper questionsPast-paper questions §17.1 (encryption-protocols-and-digital-certificates)
Plaintext, ciphertext and keys
Short code B3·17·10
Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.
Symmetric encryption: one shared key
Short code B3·17·11
FUNCTION Shift(Text : STRING, By : INTEGER) RETURNS STRING
DECLARE Abc : STRING
DECLARE Result : STRING
DECLARE i : INTEGER
DECLARE Pos : INTEGER
DECLARE NewPos : INTEGER
Abc ← "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Result ← ""
FOR i ← 1 TO LENGTH(Text)
Pos ← 1
WHILE MID(Abc, Pos, 1) <> MID(Text, i, 1)
Pos ← Pos + 1
ENDWHILE
NewPos ← (Pos - 1 + By) MOD 26 + 1
Result ← Result & MID(Abc, NewPos, 1)
NEXT i
RETURN Result
ENDFUNCTION
DECLARE Key : INTEGER
DECLARE Cipher : STRING
Key ← 4
Cipher ← Shift("YARD", Key)
OUTPUT Cipher
OUTPUT Shift(Cipher, 26 - Key)Shift("YARD", 4) encrypts; shifting the ciphertext by 26 − 4 = 22 decrypts it. Notice the same key, 4, is needed both ways. That is what makes it symmetric.Output
CEVH YARD
Asymmetric encryption: a pair of keys
Short code B3·17·12
Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.
A verified message to the public
Short code B3·17·13
DECLARE C : INTEGER
C ← Pow(4, 3)
OUTPUT "public key on 4: ", C
OUTPUT "private key on ", C, ": ", Pow(C, 7)
C ← Pow(4, 7)
OUTPUT "private key on 4: ", C
OUTPUT "public key on ", C, ": ", Pow(C, 3)Pow(M, E) multiplies E copies of M together, keeping the remainder after dividing by 33 after each step (the function is online at B3·17·13). Notice each key undoes the other, in either order. Real keys are hundreds of digits long.Output
public key on 4: 31 private key on 31: 4 private key on 4: 16 public key on 16: 4
Symmetric or asymmetric? Comparing the two
Short code B3·17·14
Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.
Quantum cryptography
Short code B3·17·15
Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.
SSL/TLS: purpose and where it is used
Short code B3·17·16
Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.
The TLS handshake
Short code B3·17·17
Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.
Digital certificates
Short code B3·17·18
Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.
Hashing and message digests
Short code B3·17·19
FUNCTION Digest(Msg : STRING) RETURNS INTEGER
DECLARE Abc : STRING
DECLARE Total : INTEGER
DECLARE i : INTEGER
DECLARE Pos : INTEGER
Abc ← "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Total ← 0
FOR i ← 1 TO LENGTH(Msg)
FOR Pos ← 1 TO 26
IF MID(Abc, Pos, 1) = MID(Msg, i, 1)
THEN
Total ← Total + Pos
ENDIF
NEXT Pos
NEXT i
RETURN Total MOD 33
ENDFUNCTION
OUTPUT "SEND SIX -> ", Digest("SEND SIX")
OUTPUT "SEND TEN -> ", Digest("SEND TEN")
OUTPUT "SIX SEND -> ", Digest("SIX SEND")Output
SEND SIX -> 28 SEND TEN -> 15 SIX SEND -> 28
Digital signatures
Short code B3·17·20
PROCEDURE Check(Msg : STRING, Sig : INTEGER)
DECLARE Sent : INTEGER
DECLARE Now : INTEGER
Sent ← Pow(Sig, 3)
Now ← Digest(Msg)
IF Sent = Now
THEN
OUTPUT Msg, ": ", Sent, " = ", Now, " accept"
ELSE
OUTPUT Msg, ": ", Sent, " <> ", Now, " reject"
ENDIF
ENDPROCEDURE
DECLARE Sig : INTEGER
Sig ← Pow(Digest("SEND SIX"), 7)
OUTPUT "Signature: ", Sig
CALL Check("SEND SIX", Sig)
CALL Check("SEND TEN", Sig)Check decrypts the signature with the public key (3, 33) and compares it with a digest of what arrived. Pow and Digest are the functions above (online at B3·17·20). Notice the altered message is rejected.Output
Signature: 19 SEND SIX: 28 = 28 accept SEND TEN: 28 <> 15 reject
Which key, for which job?
Short code B3·17·21
Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.
Past-paper practice
Short code B3·17·90
Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.
Workbook 3: Security
Short code W3·17 · Advanced Theory 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.


