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

1 Answer 1

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$
3
  • $\begingroup$ Thanks, I'll give it a try. Why does it have to be in CTR mode though? $\endgroup$
    – Miguel
    Commented Aug 19, 2019 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$ Commented Aug 19, 2019 at 10:12
  • $\begingroup$ @Ilmari Karonen, thank you very much for the explanation $\endgroup$
    – Miguel
    Commented Aug 19, 2019 at 11:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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