I am wondering is there any encryption algorithm available which produces comparable string.

I am expecting the output as shown below.

Data        |       output
testData    |  uTrildHcKpM
testData_1  |  uTrildHcKpMiopu

Please let me know if you happen to know such algorithms.

  • $\begingroup$ Do you want order-preserving encryption, or prefix-preserving one, or both? $\endgroup$ Oct 11, 2012 at 17:48
  • $\begingroup$ I am not sure what is search order-preserving encryption and prefix-preserving. Could you plese let me know about it? $\endgroup$
    – Narendra
    Oct 11, 2012 at 21:13
  • 2
    $\begingroup$ If I understand your desired property correctly, then the inherent weaknesses of that property lead to far too weak encryption. $\endgroup$ Oct 11, 2012 at 21:46
  • $\begingroup$ In particular, I suspect it's possible to show that the only kind of cipher that offers this property is a substitution cipher that works on single characters. $\endgroup$ Oct 11, 2012 at 21:46
  • $\begingroup$ @Narendra: order preserving means $a < b \Rightarrow E(a) < E(b)$, for some (natural) ordering on the plaintexts and ciphertexts. Prefix preserving means that $E(ab) = E(a)x$ for some $x$. $\endgroup$ Oct 12, 2012 at 8:03

2 Answers 2


It is somewhat unclear what you mean by comparable strings. But from the example you give, one might construe that you want the same substrings in different plaintext messages to be encrypted in the same way. This property is obviously very bad for an encryption scheme (given a number of plaintext/ciphertext pairs it would be easy to derive a lot of information about the encryption scheme).

There are however early instances of encryption with such a bad property like the monoalphabetic substitutions (Caesar's cipher for example).

  • $\begingroup$ I think it's easy to show that monoalphabetic substitution is the only kind of cipher that has this property. $\endgroup$ Oct 11, 2012 at 21:54

In cryptography terms, you are looking for an algorithm that has high confusion but no diffusion. Stream ciphers like RC4 satisfy this property when used with a fixed initialization vector, since they process the input stream byte by byte.

However, this is an absolutely dangerous way to use cryptography. The contents of the data will not be secure.

  • $\begingroup$ A stream cipher (with the same key and IV as correctly stated) will only provide the same ciphertext for two plaintext strings starting with the same substring, thus a very specific type of substrings (though the one given in the example above). Hence the lack of clarity about what is actually asked. $\endgroup$
    – bob
    Oct 12, 2012 at 17:27

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.