usencrypt.cipher.String.compareto(self, other, end_on_nul=True, match_case=False)#

Compares the encrypted string \(E(x)\) to another encrypted string \(E(y)\). It returns the following:

  • An encrypted -1, if the other encrypted string is lexicographically after self.

  • An encrypted 1, if the other encrypted string is lexicographically before self.

  • An encrypted 0, if both encrypted strings are lexicographically similar.

  • other (usencrypt.cipher.String or str) – The other encrypted string for self to be compared with.

  • end_on_nul (bool) – Indicates if the comparison should end if one of the strings has a null term. Defaults to True.

  • match_case (bool) – Indicates whether to terminate when a pad is encountered. Defaults to False.


A usencrypt.cipher.Int object containing an encrypted -1 if other is lexicographically after self, an encrypted 1 if other is lexicographically before self, or and encrypted 0 if both encrypted characters are lexicographically similar.

Return type



This function works similarly to Java’s compareTo() method.

>>> import usencrypt as ue
>>> ue_a = ue.encrypt('abc')
>>> ue_b = ue.encrypt('def')
>>> result = ue_a.compareto(ue_b)
>>> result
(0x7fe5785dbca0) Int: 0x385a7ce288a4f8c6cf50cc0eb007ddf6b46d49d04ddcf8a00007d2a7cd9171c4
>>> ue.decrypt(result)