Terms used across the book, with a link to the page that introduces each one. When a page links a term here, you can point at the link to read the definition without leaving the page.
- additive inverse
- A number that adds to another to give 0. Modulo 26, the additive inverse of a key is . Adding it undoes a Caesar shift. See Relating Modular Arithmetic to the Caesar Cipher.
- affine cipher
- A substitution cipher that multiplies each letter’s value by a multiplicative key and then adds an additive key: . See Affine Cipher.
- algorithm
- A step-by-step method. In cryptography, the method a cipher uses to turn plaintext into ciphertext. See Terminology.
- argument
- A value you give a function when you call it. In
shift(20, 9), the arguments are20and9. Each argument becomes the value of the matching parameter. See Functions. - assignment operator
- An operator such as
+=that updates a variable using its own value, sox += 2is the same asx = x + 2. See Python Shortcuts. - Atbash cipher
- The substitution cipher that writes the alphabet backwards under itself, so
abecomesZandbbecomesY. It’s the affine cipher with . See Atbash Cipher. - autokey cipher
- A polyalphabetic cipher whose keystream is a short keyword followed by the plaintext itself. The keystream never repeats, but most of it is English. See The Autokey Cipher.
- Bézout’s identity
- For any integers and , not both 0, there are integers and with . See The Euclidean Algorithm.
- Bifid cipher
- A fractionating cipher invented by Félix Delastelle. It writes each letter’s row and column numbers from a 5 x 5 key square, reads off all the row numbers and then all the column numbers, and pairs them back into letters. See The Bifid Cipher.
- bit
- A single binary digit, either 0 or 1. Each position of a binary number stores one bit. See Positional Number Systems.
- block cipher
- A cipher that splits the message into blocks of a fixed size and encrypts one whole block at a time. Every bit of a ciphertext block can depend on every bit of the plaintext block and every bit of the key. See Block Ciphers.
- blocking
- Writing ciphertext in groups (blocks) of 5 letters, which hides the lengths of the words. The recipient puts the spaces back after deciphering. See Formatting Conventions.
- Boolean
- A value that is either
TrueorFalse, named after the mathematician George Boole. Python’s name for the type isbool. Comparisons give Booleans, andifstatements andwhileloops use them to make decisions. See Data Types. - brute force
- Trying every possible key and looking for the one that produces a readable message. It only works when there aren’t too many keys. See Brute Force.
- byte
- A group of 8 bits. A byte is always exactly 2 hexadecimal digits, and this book stores every character in one byte. See Positional Number Systems.
- Caesar cipher
- A substitution cipher that shifts every letter the same number of places down the alphabet: . Also called an additive cipher or a rotation (ROT) cipher. See Caesar Cipher.
- CBC mode
- Cipher block chaining, a mode of operation that XORs each plaintext block with the previous ciphertext block before encrypting it: . The first block is XORed with an initialization vector. See BabyBlock, DES and Modes of Operation.
- An organization that everyone already trusts, which signs certificates saying that a public key belongs to a name, such as a website. Browsers and operating systems come with the public keys of a few dozen trusted root certificate authorities built in. See Digital Signatures and Hashing.
- characteristic polynomial
- The polynomial that describes the taps of an -bit LFSR, where if bit is tapped and if it isn’t. See Linear Feedback Shift Register (LFSR) Stream Ciphers.
- check digit
- An extra digit added to the end of a number so a calculation on all the digits gives a fixed result, such as a sum equal to 0 modulo 11. If a digit is copied wrong, the check fails. See Parity and ISBN Numbers.
- chi-squared statistic
- A score for how far a text’s letter counts are from the counts expected in English: , where is the actual count of letter and is its expected count. A low score means the text is close to English. See Chi-Squared Scoring.
- cipher
- A method (algorithm) for turning plaintext into ciphertext. A cipher works on individual letters or bits, whatever the message says. See Terminology.
- ciphertext
- The unreadable, enciphered form of a message. This book writes ciphertext in uppercase. See Terminology.
- ciphertext-only attack
- An attack in which the attacker has nothing but the ciphertext. Brute force and statistical analysis can work with ciphertext alone. See Introduction to Cryptanalysis.
- code
- A system that replaces whole words or phrases with other words, numbers or symbols listed in a codebook. Compare with a cipher, which works letter by letter. See Terminology.
- columnar transposition
- A transposition cipher that writes the plaintext in rows under a keyword, then reads the columns in the alphabetical order of the keyword’s letters. Also called keyed columnar transposition. See Columnar Transposition.
- concatenation
- Combining two strings end-to-end with
+, as in'hello' + 'student'. Unlike addition, the order is important: the strings are combined left to right. See String Operations, Methods, and Functions. - conditional statement
- A multi-line statement that lets Python choose among different alternatives based on the truth value of an expression. It starts with an
ifclause, and can have any number ofelifclauses and an optionalelseclause. See Conditional Statements. - confusion
- Hiding the relationship between the plaintext (and key) and the ciphertext. Substitution, such as an S-box, provides confusion. See Block Ciphers.
- congruent
- Two integers and are congruent modulo , written , if is a multiple of . See Modular Arithmetic.
- cryptanalysis
- Recovering the plaintext from a ciphertext without knowing the key, and sometimes without knowing the cipher. Also called codebreaking. See Terminology.
- cryptography
- The writing and deciphering of messages using secret codes and ciphers. It hides a message’s meaning, not the fact that the message exists. See Terminology.
- deciphering
- Turning ciphertext back into plaintext with the key. Also called decrypting. See Cracking the Warm-up Cipher.
- determinant
- For a matrix with rows and , the determinant is . A Hill cipher key works only when its determinant has a multiplicative inverse mod 26. See The Hill Cipher.
- Diffie–Hellman key exchange
- A method for two people to agree on a shared secret over a channel anyone can listen to. They publicly agree on a prime and a base , send each other and , and each computes . See Diffie–Hellman Key Exchange.
- diffusion
- Spreading the influence of each plaintext symbol over many ciphertext symbols. The goal is that changing one symbol of the plaintext changes about half of the ciphertext symbols. See Block Ciphers.
- digital signature
- A number made with the signer’s private key that depends on the exact message it signs, so anyone with the signer’s public key can check who sent the message and that nobody changed it. With RSA, the signature is , and checking it means testing whether . See Digital Signatures and Hashing.
- digraph
- A pair of letters. A cipher that works on digraphs has possible pairs instead of 26 letters, so codebreakers count pairs instead of single letters. See Introduction to Polygraphic Ciphers.
- discrete logarithm problem
- Given a prime , a base and a number , find an exponent with . No known method solves it quickly when is large, which is what keeps Diffie–Hellman and ElGamal secure. See Diffie–Hellman Key Exchange.
- ECB mode
- Electronic codebook, the mode of operation that encrypts each block on its own with the same key. Equal plaintext blocks give equal ciphertext blocks, so patterns in the message survive. See BabyBlock, DES and Modes of Operation.
- ElGamal encryption
- Public key encryption built on Diffie–Hellman. Alice multiplies her message by a masking key , made from Bob’s public key and a fresh random number , and sends along with it so Bob can recompute the masking key and divide it back out. See ElGamal Encryption.
- elliptic curve
- The set of points that satisfy , where . Points on a curve can be added, and elliptic curve cryptography uses this addition mod to get the same security as RSA with much smaller keys. See Elliptic Curve Cryptography.
- enciphering
- Turning plaintext into ciphertext with a cipher and a key. Also called encrypting. See Cracking the Warm-up Cipher.
- Enigma machine
- The German electromechanical rotor machine patented by Arthur Scherbius in 1918. A plugboard, three rotors and a reflector give a new substitution alphabet for every key press, and no letter is ever enciphered as itself. See Cipher Machines.
- Euclidean algorithm
- A method for finding without factoring: replace the larger number by its remainder when divided by the smaller one, until the remainder is 0. The last non-zero remainder is the gcd. See The Euclidean Algorithm.
- Euler’s phi function
- The number of integers with that are relatively prime to , written . Also called Euler’s totient function. For two different primes and , . See RSA.
- Extended Euclidean Algorithm
- The Euclidean algorithm with extra bookkeeping that also finds the and in Bézout’s identity. When , it gives the multiplicative inverse of modulo . See The Euclidean Algorithm.
- factorial
- For a nonnegative integer , , with . There are ways to rearrange the alphabet. See General Substitution.
- Feistel network
- A block cipher design that changes only half of the block in each round: XOR of the right half and the round key into the left half, then swap the halves. Decryption runs the same steps with the round keys in reverse order, so doesn’t need to be invertible. See Block Ciphers.
- fractionation
- Splitting each plaintext character into pieces. ADFGVX turns each character into two symbols, and a transposition then pulls the two symbols apart. See The ADFGVX Cipher.
- frequency analysis
- Cracking a cipher by using how often each letter appears. Letters don’t all appear equally often in a language, and a cipher that swaps each letter for another one keeps those patterns. See Frequency Analysis.
- function
- A named block of code that takes inputs, does a task, and sends back an output with
return. You call it by name, so you don’t have to rewrite the same code over and over. See Functions. - greatest common divisor
- The largest positive integer that divides both and , written . See The Euclidean Algorithm.
- Hamming (7,4) code
- A code with 7-bit code words. Four bits carry the message and three are parity bits. It can correct any single error, or detect up to two errors. See Hamming (7,4).
- Hamming distance
- The number of places where two code words differ. For example,
1110and1100have a Hamming distance of 1. See Hamming Distance. - hash function
- A function that turns a message of any length into a number of a fixed size. For a cryptographic hash function such as SHA-256, changing one letter changes about half the bits of the hash, and nobody can find two messages with the same hash. See Digital Signatures and Hashing.
- helper function
- A small function that does one job other functions need, such as turning a letter into its number. Helper functions keep a cipher function short, and other ciphers can reuse them. See Programming the Caesar Cipher.
- Hill cipher
- A polygraphic cipher that writes each block of letters as a column of numbers and multiplies it by an key matrix : . See The Hill Cipher.
- index of coincidence
- The probability that two letters picked at random from a text (without putting the first one back) are the same letter: . It is about 0.066 for English or a monoalphabetic cipher, and close to 0.0385 for a polyalphabetic cipher. See Identifying a Polyalphabetic Cipher.
- initialization vector
- The block that CBC mode XORs with the first plaintext block, since that block has no previous ciphertext block. It doesn’t need to be secret, but each message should get a new one. Also called an IV. See BabyBlock, DES and Modes of Operation.
- Kasiski test
- A way to find the length of a Vigenère keyword from fragments that repeat in the ciphertext. The keyword length divides the distances between the copies, so it divides their greatest common divisor. See The Kasiski Test.
- Kerckhoffs’s principle
- A cipher should stay secure even if the enemy knows exactly how it works. Only the key needs to be secret. See Types of Cryptography.
- key
- The piece of information a cipher needs to create the ciphertext, and to undo it. Usually a number or a word. See Terminology.
- key schedule
- The rule a block cipher uses to make all of its round keys from the one secret key. See Block Ciphers.
- keystream
- The string of key letters or bits that a cipher combines with the plaintext, one for each plaintext letter or bit. In the Vigenère cipher it’s the key written above the plaintext. In a stream cipher it’s a long string of bits, almost always combined with XOR. See The Tabula Recta and Stream Ciphers.
- keyword substitution cipher
- A monoalphabetic substitution cipher whose ciphertext alphabet starts with a keyword, with repeated letters removed, followed by the rest of the alphabet in order. See Keyword Substitution.
- KidRSA
- A simple public key system whose keys and satisfy . Encrypting multiplies by and decrypting multiplies by . It isn’t secure, because the Extended Euclidean Algorithm finds from the public key. See KidRSA.
- known-plaintext attack
- An attack in which you know (or correctly guess) part of the plaintext and use it to work out the key. See Solving Congruences.
- linear feedback shift register
- A row of 1-bit cells (LFSR for short). On each tick the right-most bit is output, every bit moves one cell to the right, and the XOR of a few chosen cells, the taps, enters on the left. See Linear Feedback Shift Register (LFSR) Stream Ciphers.
- list
- A Python data type that holds an ordered collection of objects, written in square brackets, such as
['caesar', 'affine']. See Lists. - loop
- A block of code that iterates, or repeats. A
whileloop repeats as long as a condition isTrue, and aforloop runs once for each item in a sequence. See Loops. - man-in-the-middle attack
- An attack in which an active attacker sits between two people and replaces the messages they send with her own. Against Diffie–Hellman, the attacker swaps each public value for her own, so she shares one secret with each side and can read and change everything. See Man-in-the-Middle Attacks.
- minimum distance
- The smallest Hamming distance between two different code words of a code , written . A code with minimum distance can detect up to errors, or correct up to . See Hamming Distance.
- mode of operation
- The rule for using a block cipher on a whole message, which is usually longer than one block. ECB and CBC are modes of operation. See BabyBlock, DES and Modes of Operation.
- module
- A Python file of functions and other objects that you can import into any notebook with
import. See Modules. - modulus
- The number in “modulo ”: how many values there are before arithmetic wraps around. A clock’s modulus is 12, and the English alphabet’s is 26. See Modular Arithmetic.
- monoalphabetic substitution cipher
- A substitution cipher with one ciphertext alphabet, so each plaintext letter is always sent to the same ciphertext letter, and no two letters are sent to the same letter. See Substitution.
- multiplicative cipher
- A substitution cipher that multiplies each letter’s value by the key: . A key works only when . See Multiplicative Ciphers.
- multiplicative inverse
- Modulo , the multiplicative inverse of is the number with . It exists exactly when . Multiplying by it undoes a multiplicative key. See Multiplicative Ciphers.
- mutable
- Able to be changed after it’s created. Lists are mutable, but strings aren’t: a string can only be replaced by a new string. See Lists.
- null
- A junk letter, usually a rare one such as
QorJ, used to fill the empty spaces in a grid. The recipient drops the nulls after deciphering. See Route Cipher. - one-time pad
- A cipher that combines each plaintext letter with a letter from a truly random keystream at least as long as the message, used for one message only. Used correctly, it can’t be broken. See The One-Time Pad.
- one-way function
- A process that is easy to do but hard to undo, such as computing or multiplying two large primes. Every public key system depends on one. See The Key Exchange Problem.
- package
- A collection of modules grouped together, such as
matplotlib. Many packages are shared on the Python Package Index. See Modules. - parameter
- A name in a function’s definition that stands for one of its inputs. In
def shift(number, key):, the parameters arenumberandkey. When the function is called, each parameter gets the value of the matching argument. See Functions. - parity bit
- One extra bit that says whether a count is even or odd. In a binary code it’s the XOR of the other bits, so it’s 1 when they contain an odd number of 1’s. See Parity and an Error Detecting Riddle.
- perfect secrecy
- A cipher has perfect secrecy when the ciphertext tells an attacker nothing except the length of the message. Claude Shannon proved that the one-time pad has it. See The One-Time Pad.
- period
- The number of steps before something starts repeating. For an LFSR, it’s the number of ticks before it returns to a state it has already been in, and after that its keystream repeats. An -bit LFSR has period at most . See Linear Feedback Shift Register (LFSR) Stream Ciphers.
- plaintext
- The original, readable message. This book writes plaintext in lowercase. See Terminology.
- Playfair cipher
- A polygraphic cipher that enciphers pairs of letters with a 5 x 5 key square. Each pair is enciphered by one of three rules: same row, same column, or the corners of a rectangle. See The Playfair Cipher.
- polyalphabetic cipher
- A cipher that uses two or more ciphertext alphabets that the sender switches between in an agreed order, so one plaintext letter can become different ciphertext letters. See Polyalphabetic Ciphers.
- Polybius square
- A 5 x 5 grid of letters, with
IandJsharing a space. The Playfair and Bifid ciphers use one as their key. See The Playfair Cipher. - polygraphic cipher
- A cipher that enciphers a block of two or more letters as a single unit. Change one letter of the block, and the whole block of ciphertext can change. See Introduction to Polygraphic Ciphers.
- primitive polynomial
- A characteristic polynomial whose LFSR is maximal: it passes through all non-zero states, so its period is . See Linear Feedback Shift Register (LFSR) Stream Ciphers.
- private key
- The half of a public key pair that must remain secret to its owner. The owner uses it to decrypt messages and to make digital signatures. See Introduction to Public Key Cryptography.
- pseudorandom number generator
- A formula that makes numbers that look random, starting from a number called the seed. The same seed always gives the same numbers. Also called a PRNG. See Modules.
- public key
- The half of a public key pair that is shared widely. Anyone can use it to encrypt a message for its owner or to check the owner’s digital signatures. See Introduction to Public Key Cryptography.
- public key cryptography
- Cryptography in which each person has a pair of keys: a public key that is shared widely and a private key that is kept secret. It must be infeasible to calculate the private key from the public key, so nobody has to share a secret key ahead of time. See Introduction to Public Key Cryptography.
- rail fence cipher
- A transposition cipher that writes the plaintext in a zigzag across several rows (rails), then reads the rails from top to bottom. The key is the number of rails. See Rail Fence Cipher.
- reduction
- The one number from 0 to that an integer is congruent to modulo , written with MOD: . In Python,
a % ngives the reduction. See Modular Arithmetic. - relatively prime
- Two integers are relatively prime (or co-prime) when their only common positive divisor is 1, so . See Multiplicative Ciphers.
- reverse cipher
- A transposition cipher that writes the plaintext backwards. It has no key, so anyone who knows the method can read the message. See Reverse Cipher.
- rotor machine
- A cipher machine that builds its keystream with turning wheels (rotors), each wired to scramble the alphabet. The rotors step after each letter, so every letter uses a different substitution alphabet. See Cipher Machines.
- round key
- The key used in one round of a block cipher. The key schedule makes the round keys from the one secret key, so every round is different. See Block Ciphers.
- route cipher
- A transposition cipher that writes the plaintext down the columns of a grid and reads the ciphertext off along a route, such as a spiral. The key is the grid’s size and the route. See Route Cipher.
- RSA
- A public key system published by Rivest, Shamir and Adleman in 1977. The public key is with for two secret primes, encrypting computes and decrypting computes , where . Its security rests on how hard it is to factor . See RSA.
- S-box
- A lookup table that substitutes one small group of bits for another. S-boxes provide the confusion in block ciphers such as BabyBlock, DES and AES. See Block Ciphers.
- scytale
- A Spartan device for transposition: a strip of parchment or leather wound around a rod, with the message written along the length of the rod. The thickness of the rod acts as the key. See Transposition Ciphers.
- seed
- The starting value of a pseudorandom number generator or an LFSR. The same seed always gives the same numbers, so in a stream cipher the seed is the key. In Python,
random.seed()sets it. See Modules and Stream Ciphers. - steganography
- Hiding the fact that a message exists at all, so an eavesdropper doesn’t notice it. Cryptography hides what a message means, and the two are often used together. See Steganography.
- stream cipher
- A cipher that enciphers a message one small piece at a time, usually one bit at a time, by combining each plaintext bit with the matching bit of a keystream, almost always with XOR. See Stream Ciphers.
- string
- A sequence of characters stored together, such as
'hello'. A character can be a number, letter, or symbol. Python’s name for the type isstr. See Data Types. - substitution cipher
- A cipher that replaces each letter or symbol of the plaintext with another letter or symbol, while the letters keep their positions. Compare with a transposition cipher, which moves the letters instead. See Types of Cryptography.
- syntax
- The grammar rules of a programming language. Instructions must follow them exactly for the computer to make sense of them, or Python raises a
SyntaxError. See Introduction to Programming in Python. - tabula recta
- A 26 x 26 table of letters whose rows are the 26 Caesar alphabets, each row shifted one place to the left of the row above. Find the plaintext letter in the top row and the key letter in the left column; the ciphertext letter is where they meet. See The Tabula Recta.
- transposition cipher
- A cipher that rearranges the letters of a message without changing any of them, so the letter frequencies stay the same. See Transposition Ciphers.
- Trithemius cipher
- A polyalphabetic cipher whose keystream steps through the alphabet. In its simplest form the key letters are
A,B,C, and so on. A key is an offset, a direction and a step. See Trithemius Cipher. - variable
- A name for a value, so you can use the value again later. You create one by assigning it a value with a single equals sign, as in
x = 5. See Variables. - Vigenère cipher
- A polyalphabetic cipher that writes a keyword over the plaintext again and again and enciphers each letter with the tabula recta, adding the key value mod 26. It was invented by Giovan Battista Bellaso. See The Vigenère Cipher.
- XOR
- Bitwise addition, written : add each pair of bits modulo 2, with no carrying. Also called exclusive or. XOR-ing with the same key twice gives back what you started with. See Binary Operations.