eolib.encrypt¶
Utilities to handle EO data encryption.
- interleave(data) None[source]¶
Interleaves a sequence of bytes. When encrypting EO data, bytes are “woven” into each other.
Used when encrypting packets and data files.
Example
>>> interleave([0, 1, 2, 3, 4, 5]) [0, 5, 1, 4, 2, 3]
This is an in-place operation.
- Parameters:
data (
bytearray) – The data to interleave.
- deinterleave(data) None[source]¶
Deinterleaves a sequence of bytes. This is the reverse of interleave.
Used when decrypting packets and data files.
Example
>>> deinterleave([0, 1, 2, 3, 4, 5]) [0, 2, 4, 5, 3, 1]
This is an in-place operation.
- Parameters:
data (
bytearray) – The data to deinterleave.
- flip_msb(data) None[source]¶
Flips the most significant bits of each byte in a sequence of bytes. (Values 0 and 128 are not flipped.)
Used when encrypting and decrypting packets.
Example
>>> flip_msb([0, 1, 127, 128, 129, 254, 255]) [0, 129, 255, 128, 1, 126, 127]
This is an in-place operation.
- Parameters:
data (
bytearray) – The data to flip most significant bits on.
- swap_multiples(data, multiple) None[source]¶
Swaps the order of contiguous bytes in a sequence of bytes that are divisible by a given multiple value.
Used when encrypting and decrypting packets and data files.
Example
>>> swap_multiples([10, 21, 27], 3) [10, 27, 21]
This is an in-place operation.
- Parameters:
- Raises:
ValueError – If multiple is less than 1.
- server_verification_hash(challenge) int[source]¶
This hash function is used by the game client to verify communication with a genuine server during connection initialization.
- Parameters:
challenge (
int) – The challenge value sent by the client. Should be no larger than 11,092,110.- Returns:
The hashed challenge value.
Remarks
The client sends an integer value to the server in the
INIT_INITclient packet, where it is referred to as thechallenge.The server hashes the value and sends the hash back in the
INIT_INITserver packet.The client hashes the value and compares it to the hash sent by the server.
If the hashes do not match, the client drops the connection.
Warning
Oversized challenges may result in negative hash values, which cannot be represented properly in the EO protocol.