# Type(s) of Hashing function that keeps the ordering information

I am asking this question from a perspective that we need to store a set of hashed data that can be queried later for in an ordered fashion.

My situation is that some data has to be encrypted, I am thinking is there any function that I can store the ordering information relative to other data without getting the original value. So that I can sort the collection without original value but with another hashed value or any information that does not leak details on the original value.

process expected:
Saving A -> store encrypted(A) , store hash(A)
Saving B -> store encrypted(B) , store hash(B)
Saving C -> store encrypted(C) , store hash(C)
.....

Sort List:
if hash(A) < hash(B) < hash(C) then returns [ C, B , A ]

Any hashing function or another function that can do this mathematically ?

lets assume A or B is always numeric based value.

• So you want hash(X) < hash(Y) iff X < Y, correct? – PyRulez Aug 19 '15 at 4:11
• Yes. But has the property of hashing function that is not reversible. – Seng Zhe Aug 19 '15 at 4:12
• If the hash function is order-preserving, and an attacker knows the hash function and hash(X), then they can recover the most significant part of X by binary search. Is that acceptable? – Chris Culter Aug 19 '15 at 5:11
• Sorry, I am not familiar with the term 'significant part'. Can you take an example like A as 11323 , what is the significant part? – Seng Zhe Aug 19 '15 at 5:23
• The most significant part of some data is the part that most affects the sort order. For a five-digit number 11323, the first three digits 113__ are more significant than the last two digits ___23. The exact amount of data recoverable from a hash depends on the length of the hash. – Chris Culter Aug 19 '15 at 5:27