1
$\begingroup$

I need to encrypt a 4-digit number. The cipher-text can be up to 11 digits long and there are no limits for the key size.

Considering that the attacker has access to both the cipher-text and the plain-text but I want the key to remain secret, what algorithm would you recommend?

$\endgroup$
  • $\begingroup$ Do you need a symmetric or asymmetric cipher? $\endgroup$ – Andy Aug 15 at 15:30
  • 4
    $\begingroup$ Format-Preserving Encryption (FPE) can probably do this. $\endgroup$ – SEJPM Aug 15 at 18:26
  • $\begingroup$ @Andy Symmetric cipher $\endgroup$ – Miguel Aug 16 at 6:13
  • $\begingroup$ @SEJPM Thanks, I'll check it out $\endgroup$ – Miguel Aug 16 at 6:13
  • 1
    $\begingroup$ @Ilmari No, neither the plain-text nor the cipher-text can be influenced by the user. $\endgroup$ – Miguel Aug 19 at 8:12
1
$\begingroup$

AES-128 in CTR mode would be more than sufficient. There is no efficient known-plaintext attack publicly known for it. Many others would also do the job.

However, the secrecy of the key depends primarily on the key itself. It should be sufficiently large and sufficiently random, so that it can't be brute-forced.

$\endgroup$
  • $\begingroup$ Thanks, I'll give it a try. Why does it have to be in CTR mode though? $\endgroup$ – Miguel Aug 19 at 8:14
  • 1
    $\begingroup$ @Miguel: CTR mode allows you to use a variable-size nonce and encrypt a variable-length message without increasing its size. For example, you could use a 14-bit plaintext (which is enough to encode 4 decimal digits) and a 22-bit nonce for a total ciphertext size of 36 bits (which fits within 11 decimal digits). $\endgroup$ – Ilmari Karonen Aug 19 at 10:12
  • $\begingroup$ @Ilmari Karonen, thank you very much for the explanation $\endgroup$ – Miguel Aug 19 at 11:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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