Short answer: ECDSA signs with the same two-value shape as DSA, on an elliptic curve. The fragment uses y^2 = x^3 + 2x + 2 over the field of 17 elements. The point (5, 1) has order 19. The private scalar is 7, the message stand-in is 9, and…
Category: Algorithms
How ECDH multiplies a shared elliptic-curve point
Short answer: ECDH agrees on a shared point. Each side multiplies the public base point by its own scalar and publishes the result. Each side then multiplies the other side’s point by its own scalar. The two products are the same point, because scalar multiplication commutes. The fragment uses…
How DSA signs a hash in a prime-order subgroup
Short answer: DSA signs a hash with an exponent in a prime-order subgroup. The public parameters are a prime p, a prime q dividing p – 1, and a base g of order q. The private key x is in 1 through q – 1, and the public key…
How DES encrypts a block with sixteen Feistel rounds
Short answer: DES encrypts an 8-byte block with sixteen Feistel rounds. PC-1 drops the parity bits of a 64-bit key and leaves a 56-bit schedule. Each round expands the right half to 48 bits, xors a subkey, splits the result into eight 6-bit pieces, and replaces each piece by…
How counter mode turns AES into a keystream
Short answer: Counter mode encrypts a counter block and xors the result with the plaintext. The fragment increments the last four bytes as a big-endian integer, which is the NIST SP 800-38A counter. Decryption is the same xor. The plaintext does not pass through the block cipher. What the…
How ChaCha20 expands a key into a keystream block
Short answer: ChaCha20 turns a 32-byte key, a 12-byte nonce, and a 32-bit block counter into a 64-byte keystream block. The state is sixteen little-endian words: the constant expand 32-byte k, the key, the counter, and the nonce. Ten double-rounds mix it. Each double-round is four column quarter-rounds and…
How CBC chains ciphertext into the next plaintext block
Short answer: Cipher block chaining xors each plaintext block with the previous ciphertext block, then applies the block cipher. The first block is xored with an initialization vector. The fragment uses AES-128, the SP 800-38A key 2b7e151628aed2a6abf7158809cf4f3c, the IV 000102030405060708090a0b0c0d0e0f, and one plaintext block. Decryption applies the inverse cipher…
How Blowfish builds its state from the digits of pi
Short answer: Blowfish is a 16-round Feistel cipher on 8-byte blocks. Eighteen P-words and four S-boxes of 256 words start as the fractional hexadecimal digits of pi. The key is xored into the P-array, and the cipher then encrypts a running block to replace every P-word and every S-box…
How AES encrypts one block in ten rounds
Short answer: AES encrypts a 16-byte block. AES-128 expands a 16-byte key into eleven round keys and runs ten rounds. Each of the first nine rounds is SubBytes, ShiftRows, MixColumns, and AddRoundKey. The last round skips MixColumns. The FIPS 197 key 000102030405060708090a0b0c0d0e0f and plaintext 00112233445566778899aabbccddeeff encrypt to 69c4e0d86a7b0430d8cdb78070b4c55a. What…
How Welzl encloses points in a disk
Short answer: Welzl’s algorithm computes the smallest enclosing disk of a finite planar point set. It is incremental and randomized. The recursive call returns the smallest disk of a subset, defined by at most three boundary points. A point that falls outside that disk is moved onto the boundary…
How weighted intervals choose by dynamic programming
Short answer: Weighted interval scheduling picks a compatible set of intervals whose weights sum to the maximum. Sort by finishing time. For each interval j, let p(j) be the rightmost interval that finishes before j starts. Then the optimum for the first j intervals is the larger of weight(j)…
How union-find almost flattens a disjoint-set forest
Short answer: Union-find maintains a partition of elements under union and under “are these two in the same set.” Each set is a tree of parent pointers. Union by rank attaches the shorter tree under the taller one, and path compression points every node on a lookup path at…
How unbounded knapsack reuses a capacity row
Short answer: Unbounded knapsack, and the classic coin-change combination count, let each item be used any number of times. The same capacity array as 0-1 knapsack is scanned upward. When the loop reaches t, dp[t−w] already includes the choices just made for this item, so the item may be…
How Ukkonen builds a suffix tree online
Short answer: Ukkonen’s algorithm builds a suffix tree, the compacted trie of all suffixes, online in O(n) time for a fixed alphabet. It processes the string left to right and keeps an active point, the place where the next character must be inserted for every suffix that has not…
How two-phase commit records one decision
Short answer: Two-phase commit makes a set of participants install one outcome, commit or abort, for a single transaction. The coordinator collects a vote. A participant who votes yes first writes a record that it will accept the coordinator’s later decision. If every vote is yes, the coordinator writes…
How topological sort orders a directed acyclic graph
Short answer: Topological sort orders a directed graph so every edge points forward. Kahn’s algorithm peels vertices of indegree zero and reduces their successors’ indegrees. Depth-first search emits vertices in reverse order of finish time. Both run in Θ(V+E). If Kahn’s queue empties before every vertex is emitted, or…
How Tonelli-Shanks takes a square root mod p
Short answer: Tonelli-Shanks computes a square root of a modulo an odd prime p, given that a is a quadratic residue. Write p−1 = q·2^s with q odd. Find a quadratic nonresidue z, set an initial guess from a^{(q+1)/2}, and then walk a 2-power tower that corrects the guess…
How timsort merges natural runs
Short answer: Timsort finds runs that are already ordered, extends short ones with insertion sort, and merges them under a stack invariant that keeps the merge cost at O(n log n). A strictly descending run is reversed so equal keys stay put, and the merge takes the left element…
