Char.compareto#

usencrypt.cipher.Char.compareto(self, other, match_case=False)#

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

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

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

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

Parameters
  • other (usencrypt.cipher.Char or str of length 1) – The other encrypted character for self to be compared with.

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

Returns

An encrypted integer 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

usencrypt.cipher.Int

Note

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

Examples
>>> import usencrypt as ue
>>> ue_s = ue.encrypt('abcdef')
>>> ue_c1 = ue_s[0]
>>> ue_c2 = ue_s[1]
>>> ue.decrypt(ue_c1.compareto(ue_c2))
-1
>>> ue.decrypt(ue_c2.compareto(ue_c1))
1
>>> ue.decrypt(ue_c1.compareto(ue_c1))
0