# Differences between hashed text and encrypted text

I was wondering if it's possible to tell if the text is hashed or encrypted. For example, if someone has given you a a chain of random characters. Would you be able to tell if it's encrypted? Which you could be able to retrieve the original text by having the private key. Or it's hashed which there is no way to reverse it.

• Does this answer your question? Differences between hash- and encryption algorithms? May 14, 2020 at 12:04
• @kelalaka Nope, I have read this. I know the differences of hash and encryption. Just wondering about the end result. May 14, 2020 at 13:08

Hash is very short, e.g. 8 bytes, 32 bytes, 64 bytes, no matter how long the original text is. Where as encrypted text is actually unlimited.

If the encrypted text is relatively long, you can calculate some statistical values. Where as hash is short and is no sufficient for any statistics. E.g. how will you speak about some frequency if you only have 32 bytes?

Hash is a one way transformation. In a normal case there is no way to restore the original text. If you had a text of 1000000 bytes and hash of 64 bytes, it is clear that there is no way to obtain 1000000 bytes from 64 bytes.

To randomness: It is one of the goals of good encryption to make the encrypted message indistinguishable from a random sequence of bytes.

mentallurg already spoke about the possible length differences. I want to note that if you can intercept several texts you maybe be able to look at some distribution properties. Encrypted texts will frequently be from a particular subspace, say a group and while they may be randomly distributed in that subspace, they may not look randomly distributed in $$\{0,1\}^k$$ whereas hashed text is likely to look randomly distributed in the space $$\{0,1\}^k$$.

I also want to note that none of this is necessary theoretically because you can easily make examples of pairs of encryption schemes and hash schemes whose outputs are identically distributed. If you have more specific details about either function, it would probably go a long way in helping you distinguish between them.

• A good block cipher is expected to be a PRP. Why they will not look randomly distributed? May 22, 2020 at 19:33

If given only the a sequence of bits, I do not think you can distinguish between the two, that's the reason both these mechanisms can be effectively used as PRNGs if implemented correctly.

You would need some more information about this sequence generating blackbox in order to figure out what you are dealing with. For example, let's say you are able to feed it input, and then observe the output to establish correlations between them. If it always gives you a 160 bit output and is also deterministic (i.e., same input results in same output), then, you guessed it right - you have a SHA1 hash. If it's an encryption, then longer the input message longer would be the output (deterministic or not would depend on the encryption method used). In any case, you would need to gather more information such as this before you can say whether it's a hash or an encryption.