eolib-cpp 0.1.0-beta.7
Core C++ library for writing Endless Online applications
Loading...
Searching...
No Matches
eolib::encrypt::DataEncrypter Class Reference

Functions for encrypting and decrypting EO data. More...

#include <eolib/encrypt/data_encrypter.hpp>

Public Member Functions

 DataEncrypter ()=delete

Static Public Member Functions

static void Interleave (std::uint8_t *data, std::size_t length)
 Interleaves a sequence of bytes in place.
static void Interleave (std::vector< std::uint8_t > &data)
 Interleaves a sequence of bytes in place.
static void Interleave (std::string &data)
 Interleaves a sequence of bytes in place.
static void Deinterleave (std::uint8_t *data, std::size_t length)
 Deinterleaves a sequence of bytes in place.
static void Deinterleave (std::vector< std::uint8_t > &data)
 Deinterleaves a sequence of bytes in place.
static void Deinterleave (std::string &data)
 Deinterleaves a sequence of bytes in place.
static void FlipMsb (std::uint8_t *data, std::size_t length) noexcept
 Flips the most significant bits of each byte in a sequence of bytes in place.
static void FlipMsb (std::vector< std::uint8_t > &data) noexcept
 Flips the most significant bits of each byte in a sequence of bytes in place.
static void FlipMsb (std::string &data) noexcept
 Flips the most significant bits of each byte in a sequence of bytes in place.
static void SwapMultiples (std::uint8_t *data, std::size_t length, int multiple)
 Swaps the order of contiguous bytes in a sequence of bytes that are divisible by a given multiple value, in place.
static void SwapMultiples (std::vector< std::uint8_t > &data, int multiple)
 Swaps the order of contiguous bytes in a sequence of bytes that are divisible by a given multiple value, in place.
static void SwapMultiples (std::string &data, int multiple)
 Swaps the order of contiguous bytes in a sequence of bytes that are divisible by a given multiple value, in place.

Detailed Description

Functions for encrypting and decrypting EO data.

Encryption is applied to packet data after the 2-byte packet ID and before the packet length is prepended. The data is encrypted with SwapMultiples, Interleave and then FlipMsb, and decrypted with FlipMsb, Deinterleave and then SwapMultiples.

All functions transform the data in place. To keep the original data, transform a copy.

Constructor & Destructor Documentation

◆ DataEncrypter()

eolib::encrypt::DataEncrypter::DataEncrypter ( )
delete

Member Function Documentation

◆ Interleave() [1/3]

void eolib::encrypt::DataEncrypter::Interleave ( std::uint8_t * data,
std::size_t length )
static

Interleaves a sequence of bytes in place.

When encrypting EO data, this function is called second.

Example: {0, 1, 2, 3, 4, 5} becomes {0, 5, 1, 4, 2, 3}.

Parameters
dataa pointer to the data to interleave.
lengththe number of bytes to interleave.

◆ Interleave() [2/3]

void eolib::encrypt::DataEncrypter::Interleave ( std::vector< std::uint8_t > & data)
inlinestatic

Interleaves a sequence of bytes in place.

When encrypting EO data, this function is called second.

Example: {0, 1, 2, 3, 4, 5} becomes {0, 5, 1, 4, 2, 3}.

Parameters
datathe data to interleave.

◆ Interleave() [3/3]

void eolib::encrypt::DataEncrypter::Interleave ( std::string & data)
inlinestatic

Interleaves a sequence of bytes in place.

When encrypting EO data, this function is called second.

Example: {0, 1, 2, 3, 4, 5} becomes {0, 5, 1, 4, 2, 3}.

Parameters
datathe data to interleave.

◆ Deinterleave() [1/3]

void eolib::encrypt::DataEncrypter::Deinterleave ( std::uint8_t * data,
std::size_t length )
static

Deinterleaves a sequence of bytes in place.

This is the reverse of Interleave. When decrypting EO data, this function is called second.

Example: {0, 1, 2, 3, 4, 5} becomes {0, 2, 4, 5, 3, 1}.

Parameters
dataa pointer to the data to deinterleave.
lengththe number of bytes to deinterleave.

◆ Deinterleave() [2/3]

void eolib::encrypt::DataEncrypter::Deinterleave ( std::vector< std::uint8_t > & data)
inlinestatic

Deinterleaves a sequence of bytes in place.

This is the reverse of Interleave. When decrypting EO data, this function is called second.

Example: {0, 1, 2, 3, 4, 5} becomes {0, 2, 4, 5, 3, 1}.

Parameters
datathe data to deinterleave.

◆ Deinterleave() [3/3]

void eolib::encrypt::DataEncrypter::Deinterleave ( std::string & data)
inlinestatic

Deinterleaves a sequence of bytes in place.

This is the reverse of Interleave. When decrypting EO data, this function is called second.

Example: {0, 1, 2, 3, 4, 5} becomes {0, 2, 4, 5, 3, 1}.

Parameters
datathe data to deinterleave.

◆ FlipMsb() [1/3]

void eolib::encrypt::DataEncrypter::FlipMsb ( std::uint8_t * data,
std::size_t length )
staticnoexcept

Flips the most significant bits of each byte in a sequence of bytes in place.

Values 0x00 and 0x80 are not flipped. This function is called last when encrypting EO data, and first when decrypting it.

Parameters
dataa pointer to the data to flip.
lengththe number of bytes to flip.

◆ FlipMsb() [2/3]

void eolib::encrypt::DataEncrypter::FlipMsb ( std::vector< std::uint8_t > & data)
inlinestaticnoexcept

Flips the most significant bits of each byte in a sequence of bytes in place.

Values 0x00 and 0x80 are not flipped. This function is called last when encrypting EO data, and first when decrypting it.

Parameters
datathe data to flip.

◆ FlipMsb() [3/3]

void eolib::encrypt::DataEncrypter::FlipMsb ( std::string & data)
inlinestaticnoexcept

Flips the most significant bits of each byte in a sequence of bytes in place.

Values 0x00 and 0x80 are not flipped. This function is called last when encrypting EO data, and first when decrypting it.

Parameters
datathe data to flip.

◆ SwapMultiples() [1/3]

void eolib::encrypt::DataEncrypter::SwapMultiples ( std::uint8_t * data,
std::size_t length,
int multiple )
static

Swaps the order of contiguous bytes in a sequence of bytes that are divisible by a given multiple value, in place.

This function is called first when encrypting EO data, and last when decrypting it.

Parameters
dataa pointer to the data to swap.
lengththe number of bytes to swap.
multiplethe multiple value; a value of 0 leaves the data unchanged.
Exceptions
std::invalid_argumentif the multiple is negative. The data is not modified.

◆ SwapMultiples() [2/3]

void eolib::encrypt::DataEncrypter::SwapMultiples ( std::vector< std::uint8_t > & data,
int multiple )
inlinestatic

Swaps the order of contiguous bytes in a sequence of bytes that are divisible by a given multiple value, in place.

This function is called first when encrypting EO data, and last when decrypting it.

Parameters
datathe data to swap.
multiplethe multiple value; a value of 0 leaves the data unchanged.
Exceptions
std::invalid_argumentif the multiple is negative. The data is not modified.

◆ SwapMultiples() [3/3]

void eolib::encrypt::DataEncrypter::SwapMultiples ( std::string & data,
int multiple )
inlinestatic

Swaps the order of contiguous bytes in a sequence of bytes that are divisible by a given multiple value, in place.

This function is called first when encrypting EO data, and last when decrypting it.

Parameters
datathe data to swap.
multiplethe multiple value; a value of 0 leaves the data unchanged.
Exceptions
std::invalid_argumentif the multiple is negative. The data is not modified.