# 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

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

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.

-
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. – bob Oct 12 '12 at 17:27
Good point! Thanks for the clarification. – Stephen Touset Oct 12 '12 at 19:13