A computer-implemented method comprising: providing an engine on a client with an access to plaintext values x 1,..., x i,..., X n, 0≤x i <N; causing the engine on the client to execute an order-preserving encryption algorithm encrypting the plaintext values to create corresponding ciphertext values y 1,..., y i,..., y n, 0≤y i <M, wherein x jl,..., x jn and y jl,..., y jn are an ordered sequence of distinct plaintext values and ciphertext values, respectively; wherein the encryption is stateful and stores an ordered list of plaintext-ciphertext pairs initialized to <-1,-1>, <N, M> and the algorithm comprises constructing a binary search tree comprising n nodes by: finding <x jk, y jk > and <x jk+1, y jk+1 > such that x jk ≤x i < x jk+1; if x i = x jk, returning y jk as y i; if y jk+1) = y jk = 1, updating all ciphertext values and returning y jk+1 as y i; otherwise, returning y jk + [(y jk+1 - y jk)/2] as y i; and wherein the first plaintext value inserted and corresponding ciphertext is the root and subsequent plaintext values are placed to the left or right depending on their order relation; and wherein to reduce the update probability the plaintext space is N = 2 1 and the ciphertext space is M = 2 λl with λ ≥ 4.31107+2; causing the engine on the client to create further encrypted data from the ciphertext values; causing the engine on the client to send the further encrypted data to a database server; and causing the engine on the client to send a cryptographic key to the server to allow decryption of the further encrypted data. providing an engine on a client with an access to plaintext values x 1,..., x i,..., X n, 0≤x i <N; causing the engine on the client to execute an order-preserving encryption algorithm encrypting the plaintext values to create corresponding ciphertext values y 1,..., y i,..., y n, 0≤y i <M, wherein x jl,..., x jn and y jl,..., y jn are an ordered sequence of distinct plaintext values and ciphertext values, respectively; wherein the encryption is stateful and stores an ordered list of plaintext-ciphertext pairs initialized to <-1,-1>, <N, M> and the algorithm comprises constructing a binary search tree comprising n nodes by: finding <x jk, y jk > and <x jk+1, y jk+1 > such that x jk ≤x i < x jk+1; if x i = x jk, returning y jk as y i; if y jk+1) = y jk = 1, updating all ciphertext values and returning y jk+1 as y i; otherwise, returning y jk + [(y jk+1 - y jk)/2] as y i; and wherein the first plaintext value inserted and corresponding ciphertext is the root and subsequent plaintext values are placed to the left or right depending on their order relation; and wherein to reduce the update probability the plaintext space is N = 2 1 and the finding <x jk, y jk > and <x jk+1, y jk+1 > such that x jk ≤x i < x jk+1; if x i = x jk, returning y jk as y i; if y jk+1) = y jk = 1, updating all ciphertext values and returning y jk+1 as y i; otherwise, returning y jk + [(y jk+1 - y jk)/2] as y i; and wherein the first plaintext value inserted and corresponding ciphertext is the root and subsequent plaintext values are placed to the left or right depending on their order relation; and wherein to reduce the update probability the plaintext space is N = 2 1 and the ciphertext space is M = 2 λl with λ ≥ 4.31107+2; causing the engine on the client to create further encrypted data from the ciphertext values; causing the engine on the client to send the further encrypted data to a database server; and causing the engine on the client to send a cryptographic key to the server to allow decryption of the further encrypted data.