Why a PIN isn't just encrypted as four ASCII digits
Encrypting "1234" as plain text would leak its length and its digit-only alphabet to anyone who could guess or brute-force short inputs against a known block cipher — a 4-to-12-digit numeric value is an extremely small search space. The payments industry standard (ISO 9564-1) instead packs the PIN into a fixed-width 8-byte structure called a PIN block before any encryption happens, so every PIN — whether 4 digits or 12 — produces a block of the exact same size and shape, and the block's own construction ties it to one specific card.
The most common layout, Format 0 (also called ISO-0), reserves the first nibble for a format control code, the second nibble for the PIN length, the PIN digits themselves, then padding nibbles (0xF) out to 16 hex digits (8 bytes) total.
ISO-0 PIN block, PIN = 1234
16 hex nibbles total (8 bytes) — the fixed width every PIN gets packed into, regardless of its actual length.
Practice
A 6-digit PIN is packed into an ISO-0 PIN block: 1 control nibble, 1 length nibble, the PIN digits, then 0xF padding out to 16 hex digits total. How many padding nibbles does a 6-digit PIN get?
Binding the block to one card: XOR with the PAN field
A PIN block on its own would encrypt identically for every customer who happens to share the same PIN — a real weakness, since short PINs collide often. ISO-0 fixes this by building a second 8-byte block from the customer's own card number (the rightmost 12 digits of the PAN, excluding the check digit, padded with two leading zero nibbles), then XOR-ing the PIN block with this PAN block before encryption. Two customers with an identical PIN now produce completely different ciphertext, because their PANs differ.
Practice
Two customers, Alice and Bob, both choose the PIN 7890 but have different card numbers. After each PIN block is XOR'd with its own PAN field, are their two clear PIN blocks the same or different?
Format 3: the same idea, resistant to a guessing attack
ISO-0's fixed 0xF padding is itself a small weakness: an attacker with access to the encryption oracle (not the key) can narrow down candidate PINs faster than pure brute force, because every correct guess produces a block with predictable padding nibbles. Format 3 (ISO-3) closes this by filling the padding nibbles with cryptographically random hex digits instead of a fixed pattern, so no structural property distinguishes a correct guess from an incorrect one before decryption. The PIN field, the PAN XOR step, and the encryption itself are otherwise identical to Format 0 — this is a hardening of the padding, not a different mechanism.
Translation: why the PIN gets decrypted and re-encrypted at every hop
A PIN entered at a merchant's terminal has to travel through an acquirer's network, a card scheme's switch, and finally the issuer's host before it can be verified — and every one of those hops uses its own encryption key (a Zone PIN Key, or ZPK) shared only with its immediate neighbor, never end to end. That means the PIN block has to be decrypted under the incoming link's key and re-encrypted under the outgoing link's key at every single hop, which is the one operation an ordinary server must never be allowed to do in plaintext memory: it's the exact job a payment HSM like a payShield exists for. The HSM decrypts the incoming block, re-encrypts it under the next hop's ZPK, and returns only the new ciphertext — the plaintext PIN exists nowhere but inside the HSM's own protected memory, for microseconds, and is never logged, swapped to disk, or visible to the application calling it.
A PIN's journey, one hop at a time
- 1
Terminal encrypts under the Terminal PIN Key (TPK)
The PIN never leaves the PIN pad's own secure boundary in the clear.
- 2
Acquirer HSM translates TPK → ZPK₁
Decrypt under the terminal's key, immediately re-encrypt under the key shared with the network.
- 3
Network switch HSM translates ZPK₁ → ZPK₂
Same operation, one more hop closer to the issuer.
- 4
Issuer HSM translates ZPK₂ → LMK (or verifies directly)
The issuer's HSM performs the final decryption and the actual PIN verification — often without the PIN ever existing outside HSM-to-HSM hops at all.
Practice
A PIN block crosses 3 hops (terminal→acquirer, acquirer→network, network→issuer), each requiring one decrypt and one re-encrypt at an HSM. How many total 3DES operations does that require across the whole journey?
Verification almost never means "decrypt and compare"
Even at the issuer, the HSM rarely decrypts the PIN just to compare it against a stored value — storing plaintext PINs anywhere, even encrypted at rest, is exactly what the whole design avoids. Instead, the issuer host holds a PIN Verification Value (PVV) or an IBM 3624 offset computed once, at PIN-set time, from the actual PIN and a PIN Verification Key — a one-way derivation, not an encryption that can be reversed. Verifying a PIN means asking the HSM to compute the same PVV from the just-decrypted PIN block and compare it to the stored value; a match returns a boolean, nothing else leaves the HSM. This is the same underlying idea as password hashing (covered in the key derivation functions module) applied to a 4-digit secret: the host never needs to reconstruct the original PIN to confirm it's correct.