# Encryption algorithm which produces comparable results for substrings

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.

-
Do you want order-preserving encryption, or prefix-preserving one, or both? –  Paŭlo Ebermann Oct 11 '12 at 17:48
I am not sure what is search order-preserving encryption and prefix-preserving. Could you plese let me know about it? –  Narendra Oct 11 '12 at 21:13
If I understand your desired property correctly, then the inherent weaknesses of that property lead to far too weak encryption. –  CodesInChaos Oct 11 '12 at 21:46
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. –  CodesInChaos Oct 11 '12 at 21:46
@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$. –  Paŭlo Ebermann Oct 12 '12 at 8:03
show 1 more comment

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).

-
I think it's easy to show that monoalphabetic substitution is the only kind of cipher that has this property. –  CodesInChaos Oct 11 '12 at 21:54