← Back to the tool

Payments · Under the hood

CVV/CVC calculator

What each button in the tool actually computes, step by step — with the real formulas.

A DES pass, a 3DES pass, and decimalization

"Compute all three" concatenates the PAN, expiry date, and service code, pads them with zeros to 32 digits, and splits that into two 8-byte blocks. It encrypts the first block with single DES under CVK A alone, XORs that result with the second block, encrypts again with 3DES under CVK A ‖ CVK B, and decimalizes the final 8 bytes down to 3 digits.

The real two-block CVV algorithm
function computeCvv(pan, expiryYYMM, serviceCode, cvk) {
  const data = (pan + expiryYYMM + serviceCode).padEnd(32, "0"); // zero-pad to 2 blocks
  const block1 = hexToBigInt(data.slice(0, 16));
  const block2 = hexToBigInt(data.slice(16, 32));

  const { k1, k2, k3 } = keyHalves(cvk);
  const encrypted1 = desEncryptBlock(block1, k1);                 // single DES, CVK A only
  const encrypted2 = tdesEncryptBlock(encrypted1 ^ block2, k1, k2, k3); // 3DES, CVK A ‖ B

  return decimalize(bigIntToHex(encrypted2, 8), 3);
}

Every decimal digit of the input doubles as one hex nibble directly — no separate encoding step, since PAN digits are already 0–9. Checked against the published test vector: PAN 4123456789012345, expiry 8701, service code 101, CVK A 0123456789ABCDEF, CVK B FEDCBA9876543210 → CVV 561.

Decimalization: a fixed, public table

3DES output is 16 hex digits, but a CVV has to be entirely numeric. Decimalization takes two passes: first it keeps only the digits 0–9, left to right; then it scans again, folding A–F down onto 0–5, and appends those — a fixed, publicly known transformation. None of the security comes from keeping this table secret; all of it comes from the CVK never leaving the issuer's HSM.

Digits first, then A–F folded onto 0–5
function decimalize(hex, digits) {
  const decimal = hex.replace(/[^0-9]/g, "");          // pass 1: 0–9 as they are
  const folded = hex.replace(/[^A-F]/g, "")            // pass 2: A→0 … F→5
    .split("").map(c => parseInt(c, 16) - 10).join("");
  return (decimal + folded).slice(0, digits);
}

Only the first 3 decimalized digits become the printed CVV — the rest of the 3DES output is simply discarded, which is also why a CVV alone can't be reversed back into a key or a PAN.

Why CVV1, CVV2, and iCVV never cross-validate

The "Compute all three" button runs the identical function three times, changing only the 3-digit service code: 101 for CVV1 (magstripe), 000 for CVV2 (printed, card-not-present), and 999 for iCVV (chip). Because the service code feeds directly into block 2 before the second encryption, a one-digit change there cascades into a completely unrelated final cryptogram — there's no partial credit, no shared prefix, nothing that links the three values except that they came from the same PAN, expiry, and CVK.

Now try it

Back to CVV/CVC calculator →

Compute a real CVV1, CVV2, and iCVV from the same PAN, expiry, and Card Verification Key — watch all three diverge from one formula, purely because the service code input differs.