I've been reading papers on variable sized block cipher constructions based on fixed-length block ciphers, and they tend to focus on increasing the block size. They either gloss over or speak too generally about decreasing the block size. (Or I'm just not getting it, which is possible)

On the Construction of Variable-Input-Length Ciphers
Efficient Constructions of Variable-Input-Length Block Ciphers

While these are certainly helpful, I also need a way to encrypt a size much smaller than the usual block ciphers. For example, a credit card has 16 digits, which can be represented in 54 bits. To encrypt a credit card number to another one would require a 54-bit block cipher. (The 54-bits could be brought even lower if you consider that the first and last digits are not random)

Is there a way to do this in such a way that the security isn't brought below the chance of simply guessing the plaintext?

  • 2
    $\begingroup$ Search for Format Preserving Encryption (e.g. FFX mode). $\endgroup$ Jul 6 '17 at 7:41
  • 3
    $\begingroup$ But whenever possible, accept a ciphertext longer than the plaintext and use strong encryption instead. $\endgroup$ Jul 6 '17 at 7:41
  • $\begingroup$ You could use a stream cipher (like AES-CTR) instead of a block cipher. That way, you would only have to pad your data to full bytes and not to a whole block. But you'll have to store the IV instead. $\endgroup$
    – mat
    Jul 6 '17 at 8:25

If I understand your problem, I think the best way would be to pad the plaintext bits to 128 bits (8 bytes) with zeros and then use a strong block cipher like AES (Rijndael). Of course, then your ciphertext will be 128 bits instead of the 54 (or whatever) you started with. You can trim these trailing zeros after decryption. If you want the ciphertext to be the same length, you'll have to use a stream method, but which will not be as strong.

  • 2
    $\begingroup$ Note that Daffy has clicked the format-preserving tag. $\endgroup$
    – Paul Uszak
    May 31 '18 at 20:46
  • $\begingroup$ In case you didn't get this comment: the output of the ciphertext should be 54 bits for an input of 54 bits in case of FPE (Format Preserving Encryption). $\endgroup$
    – Maarten Bodewes
    Feb 21 '19 at 14:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.