0

What is the most efficient method / cryptography provider for encrypting strings which results in the shortest possible string. Our goal is that we have to encrypt a string and we want to achieve the shortest possible string after encryption.

So far we have tested with Tripple DES and Rijndael and both resulted in exactly the same encrypted length. I have also played around with longer and shorter key sizes but that also did not make much difference.

I'm not much of an expert on cryptography so I don't know if there is perhaps some mathematical reason or explanation why a string of length y can only be encrypted to length x - hoping to hear from your expert opinions.

Ghlouw
  • 1,440
  • 16
  • 19
  • 6
    MD5 is *not* an "encryption" algorythm. All hash functions produce the same length output regardless of the length of the input. Also, hashes are not reversible (you can't "decrypt" them) – Andrew Barber Jul 06 '12 at 08:24
  • You might also want to specify how strong the encryption needs to be. You could just add +1 to all the char values and that would technically be encrypted and would produce an output string the same length as the input string - it would just be very poor encryption! – vaughandroid Jul 06 '12 at 08:36
  • Good points. 128 bit should be good starting point. – Ghlouw Jul 06 '12 at 09:12
  • ROT13 encrypted strings are the same length as the original. – Colonel Panic Jul 06 '12 at 09:26
  • How many different strings do you want to be able to encrypt? What character set do you allow in the input? What character set do you want to allow in the output? – AakashM Jul 06 '12 at 10:28
  • 4
    `most crypto methods return the encrypted string in base64` - no, most crypto methods don't have anything to do with Base64, or substantially increase the length of their inputs (barring padding). Base64 is simply a way to encode arbitrary binary data (such as the output of an encryption routine) using a constrained set of printable characters. If you can directly store the binary output of the crypto routine, just don't bother running it through Base64. – anton.burger Jul 06 '12 at 10:35
  • `Producing the shortest string with encryption` is probably a better title – Chris S Jul 06 '12 at 10:54

1 Answers1

1

How long are your strings? Very long strings can be compressed before encryption.

To produce a cyphertext the same length as the plaintext you can:

  • use a stream cypher such as RC4, or one of the eSTREAM cyphers

  • use a block cypher (e.g. AES) in CTR mode.

If your strings are all exactly 8 bytes or all 16 bytes, then you could use a block cypher with the appropriate block size in ECB mode and no padding.

rossum
  • 15,344
  • 1
  • 24
  • 38
  • The strings are 120 or less chars so too short for compression. Thanks for the other suggestions, I will have a look at it. :) – Ghlouw Jul 06 '12 at 10:29
  • 1
    If you are not looking for high levels of security, then a classical cypher, like Vigenère might be useful. – rossum Jul 06 '12 at 10:58