Skip to content
LUDA · 學思辨行

LUDA · 學思辨行

Learn extensively, Understand deeply, Discern clearly, and Act resolutely.

  • About
  • Learning Path

Category: Algorithms

Hash table — look up a key in the slot its hash names

November 21, 2026By HoHo Zhao

A hash table finds a key by turning it into a slot number and reading that slot. It fits a collection that will be asked many times, when the only question is whether the key is present. It does not fit a single query, a request for the next…

Algorithms, SearchingLeave a comment

How X25519 multiplies a point on Curve25519

November 13, 2026By HoHo Zhao

Short answer: X25519 is Diffie-Hellman on Curve25519. The scalar is clamped before the ladder runs: the low three bits of the first byte are cleared, the high bit of the last byte is cleared, and bit 254 is set. The Montgomery ladder multiplies the u-coordinate by that scalar. The…

Algorithms, CryptographyLeave a comment

How Triple DES encrypts with three DES operations

November 13, 2026By HoHo Zhao

Short answer: Triple DES applies DES three times in encrypt-decrypt-encrypt order. The key is three 8-byte DES keys. Decryption is decrypt with K3, encrypt with K2, and decrypt with K1. When the three keys are equal, the middle decryption cancels one encryption and the map is single DES. What…

Algorithms, CryptographyLeave a comment

How Shamir sharing reconstructs a secret by interpolation

November 13, 2026By HoHo Zhao

Short answer: Shamir secret sharing splits a secret into points on a polynomial over a prime field. A polynomial of degree 2 is fixed by any 3 points. The fragment uses the field modulo 101 and the polynomial 42 + 7x + 3x^2. The shares at x = 1,…

Algorithms, CryptographyLeave a comment

How SHA-3 absorbs a message into a Keccak sponge

November 13, 2026By HoHo Zhao

Short answer: SHA3-256 is a Keccak sponge, not a Merkle-Damgard hash. The state is twenty-five 64-bit lanes. SHA3-256 absorbs 136 bytes at a time and pads with the domain byte 0x06, zeros, and a final byte whose high bit is set. Each absorbed block is xored into the state,…

Algorithms, CryptographyLeave a comment

How SHA-256 compresses a padded message

November 13, 2026By HoHo Zhao

Short answer: SHA-256 maps a message to a 32-byte digest. It pads with a 1 bit, zeros, and the 64-bit length, then compresses each 64-byte block into eight 32-bit words. The initial words are the first 32 bits of the fractional square roots of the first eight primes. The…

Algorithms, CryptographyLeave a comment

How SHA-1 compresses a padded message

November 13, 2026By HoHo Zhao

Short answer: SHA-1 maps a message to a 20-byte digest. It pads like SHA-256, with a 1 bit, zeros, and the length, then runs eighty rounds on five 32-bit words. The digest of abc is a9993e364706816aba3e25717850c26c9cd0d89d. Distinct messages can share a SHA-1 digest. A collision is practical, so the…

Algorithms, CryptographyLeave a comment

How scrypt stretches a password with a large table

November 13, 2026By HoHo Zhao

Short answer: scrypt stretches a password by filling a table and walking it at random. PBKDF2-HMAC-SHA-256 expands the password and salt into p blocks. Each block is mixed by ROMix. ROMix stores N successive BlockMix outputs, then walks N more steps, using the last 64 bytes as an index…

Algorithms, CryptographyLeave a comment

How RC4 generates a keystream from a permutation

November 13, 2026By HoHo Zhao

Short answer: RC4 builds a 256-byte permutation from the key, then walks that permutation to emit a keystream byte. The key schedule adds the next key byte into an index and swaps. The generator increments i, adds S[i] into j, swaps, and emits S[(S[i] + S[j]) mod 256]. The…

Algorithms, CryptographyLeave a comment

How Poly1305 authenticates a message under a one-time key

November 13, 2026By HoHo Zhao

Short answer: Poly1305 computes a 16-byte tag under a one-time 32-byte key. The first 16 bytes, with selected bits cleared, are the evaluation point r. The last 16 bytes are the pad s. The message is read in 16-byte chunks. Each chunk gains a trailing 0x01 byte and is…

Algorithms, CryptographyLeave a comment

How PBKDF2 stretches a password by repeating HMAC

November 13, 2026By HoHo Zhao

Short answer: PBKDF2 stretches a password by repeating HMAC. For one block, the first value is HMAC of the password and the salt followed by a block counter. Each later value is HMAC of the password and the previous value. The block is the xor of those values. The…

Algorithms, CryptographyLeave a comment

How OAEP encodes a short message before the RSA exponent

November 13, 2026By HoHo Zhao

Short answer: OAEP encodes a short message before the RSA public exponent. With SHA-256, a seed of 32 bytes is masked with MGF1, and a data block is masked with MGF1 of the masked seed. The data block is the hash of the empty label, a run of zero…

Algorithms, CryptographyLeave a comment

How MD5 compresses a padded message

November 13, 2026By HoHo Zhao

Short answer: MD5 maps a message to a 16-byte digest. The words are little-endian. Sixty-four rounds use four Boolean functions, a left rotation, and a constant. The constants are the integer parts of 2^32 times the absolute value of the sine of 1 through 64. The digest of abc…

Algorithms, CryptographyLeave a comment

How HMAC-SHA-256 mixes a key into a hash

November 13, 2026By HoHo Zhao

Short answer: HMAC-SHA-256 turns a key and a message into a 32-byte tag. A key longer than 64 bytes is hashed first. The key is padded with zeros to 64 bytes. The inner hash is SHA-256 of the key xored with 0x36, followed by the message. The outer hash…

Algorithms, CryptographyLeave a comment

How HKDF extracts and expands a shared secret

November 13, 2026By HoHo Zhao

Short answer: HKDF-SHA-256 turns a shared secret into key bytes of a chosen length. Extract sets the pseudorandom key to HMAC of the salt and the input keying material. Expand appends HMAC of that key, the previous block, the info string, and a counter, starting from an empty previous…

Algorithms, CryptographyLeave a comment

How GCM authenticates ciphertext with GHASH

November 13, 2026By HoHo Zhao

Short answer: GCM encrypts with counter mode and authenticates with GHASH. H is the AES encryption of the zero block. For a 12-byte nonce, J0 is the nonce followed by 00000001. Encryption starts at the next counter. GHASH multiplies each ciphertext block by H in GF(2^128). The last field…

Algorithms, CryptographyLeave a comment

How ElGamal encrypts a message as a pair of powers

November 13, 2026By HoHo Zhao

Short answer: ElGamal encrypts an integer as a pair. The public key is g^x mod p. A ciphertext is (g^k mod p, m * (g^x)^k mod p). Decryption divides the second element by the first element raised to x, which is multiplication by the modular inverse. The fragment uses…

Algorithms, CryptographyLeave a comment

How Ed25519 signs a message on an Edwards curve

November 13, 2026By HoHo Zhao

Short answer: Ed25519 signs a message on the twisted Edwards curve related to Curve25519. SHA-512 of the 32-byte secret splits into a clamped scalar and a prefix. The public key is the base point times that scalar. The nonce is SHA-512 of the prefix and the message, reduced modulo…

Algorithms, CryptographyLeave a comment

Posts pagination

1 2 3 … 12 Next
  • Algorithms
  • Arithmetic
  • Authelia
  • Clustering
  • Coding
  • Compression
  • Cryptography
  • CSS
  • Distributed Systems
  • Docker
  • Dynamic Programming
  • Exact Algorithms
  • Games
  • Geometry
  • Grafana
  • Graphs
  • Greedy
  • Heaps
  • Homelab
  • IPsec
  • LDAP
  • Linear Algebra
  • Logging
  • Loki
  • nginx
  • Number Theory
  • Numerical
  • Optimization
  • Parsing
  • Prometheus
  • Randomization
  • Range Queries
  • Sampling
  • Scheduling
  • Search
  • Searching
  • Sequences
  • Sketches
  • Sorting
  • Streams
  • Strings
  • SVG
  • Synchronization
  • Systems
  • Transforms
  • Trees

Docker EAP-MSCHAPv2 FreeRADIUS Grafana gzip IKEv2 IPsec LogQL Loki OpenLDAP Promtail StrongSwan

© 2026 LUDA · 學思辨行. Powered by WordPress.