This gem implements order-preserving symmetric encryption, as described in Boldyreva, 2009.
require 'ope'
cipher = OPE::Cipher.new(key)
a = cipher.encrypt(456789)
b = cipher.encrypt(891234)
puts b > a # => true
CryptDB provided a reference implementation for the Boldyreva paper. The code from Caesar was helpful in understanding how the scheme worked from a high-level perspective. The hypergeometric distribution code was adapted from a Fortran implementation from the Association for Computing Machinery and a C implementation used by the R project.
This software is released under the GNU Affero General Public License. If this license does not suit your needs, please contact me.