Because we need a mapping that is format-preserving, pseudorandom permutations are top of mind. Unfortunately, plugging a card number directly into a standard-issue block cipher such as AES is not helpful. This is because the block size is far too big: there is a high probability that the output will not be a valid card number. Instead, we must craft a block cipher that has just the right width.
There are 1016 possible card numbers. Because we like to design modes that operate in base 2, we need to calculate the number of bits we need to represent any card number. We simply need to solve the inequality 2b ≥ 1016 for integer b. Taking the integer constraint into account, we obtain b = 54. Therefore, we need to use a 54-bit pseudorandom permutation. One way of achieving this is by constructing a Feistel network with a sufficient number of rounds.
Unfortunately, it is not as simple as plugging the plaintext card number into the 54-bit SPRP. The problem is that occasionally, the SPRP will map the input to a card number that is not valid, because 254 > 1016. Thankfully, there is an elegant solution: if the encryption operation outputs an out-of-range card number, we simply take the invalid output and encrypt it. We iterate this process until we land on a valid number. This is known as cycle walking. In the example visualized below, the entire area within the square represents the domain and range of the 54-bit SPRP. The white portion represents the space of all valid card numbers, and the gray portion represents out-of-range card numbers.
Decryption follows the same process but in reverse order: we start at C and stop when we arrive at a valid P. The probability of having to perform > i steps decays approximately geometrically: