Documentation

StringEncodingUtils
in package

Provides utility functions for encoding and decoding strings.

This class provides static utility functions for encoding and decoding strings in a reversible manner. The encoding process inverts the characters of a string within a specific ASCII range and then reverses the entire string. The decoding process reverses the string and then inverts the characters back to their original values. This method is used to obfuscate strings in a reversible way.

Table of Contents

Methods

bytesToString()  : string
Converts an array of bytes to a string.
decodeString()  : string
Decodes a previously encoded string by reversing its order and inverting its characters.
encodeString()  : array<string|int, int>
Encodes a string by inverting its characters and reversing the entire string.
stringToBytes()  : array<string|int, int>
Converts a string to an array of bytes.
invertCharacters()  : void
Inverts characters within an ASCII range to transform a string.

Methods

bytesToString()

Converts an array of bytes to a string.

public static bytesToString(array<string|int, int> $bytes) : string

This function converts an array of bytes to a string, where each byte in the array represents a character in the string. The bytes are concatenated in the order they appear in the array.

Parameters
$bytes : array<string|int, int>

The array of bytes to convert.

Return values
string

The string represented by the bytes.

decodeString()

Decodes a previously encoded string by reversing its order and inverting its characters.

public static decodeString(array<string|int, int> $bytes) : string

This function reverses the operations performed by encodeString, restoring the original text from an encoded string by first reversing its order and then inverting its characters.

Parameters
$bytes : array<string|int, int>

The encoded string to decode.

Return values
string

The decoded string.

encodeString()

Encodes a string by inverting its characters and reversing the entire string.

public static encodeString(string $string) : array<string|int, int>

This function applies a transformation that inverts each character's ASCII value within a specific range and then reverses the order of the entire string. This method is used to obfuscate strings in a reversible way.

Parameters
$string : string

The string to encode

Return values
array<string|int, int>

The encoded string as an array of bytes.

stringToBytes()

Converts a string to an array of bytes.

public static stringToBytes(string $string) : array<string|int, int>

This function converts a string to an array of bytes, where each byte represents a character in the string. The bytes are stored in an array in the order they appear in the string.

Parameters
$string : string

The string to convert.

Return values
array<string|int, int>

An array of bytes representing the string.

invertCharacters()

Inverts characters within an ASCII range to transform a string.

private static invertCharacters(array<string|int, int> &$bytes) : void

This internal function inverts characters within the printable ASCII range (0x22 to 0x7E) by applying a transformation that reflects each character around a central point in the range. The inversion can be adjusted slightly based on whether the character's index is odd or even, which adds a level of obfuscation.

Parameters
$bytes : array<string|int, int>

The string whose characters are to be inverted, passed by reference.


        
On this page

Search results