* @author Sam Williams * * @see http://christianriesen.com * * @license MIT License see LICENSE file */ class Base32 { /** * Alphabet for encoding and decoding base32. * * @var string */ protected const ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567='; protected const BASE32HEX_PATTERN = '/[^A-Z2-7]/'; /** Maps the Base32 character to its corresponding bit value. */ protected const MAPPING = [ '=' => 0, 'A' => 0, 'B' => 1, 'C' => 2, 'D' => 3, 'E' => 4, 'F' => 5, 'G' => 6, 'H' => 7, 'I' => 8, 'J' => 9, 'K' => 10, 'L' => 11, 'M' => 12, 'N' => 13, 'O' => 14, 'P' => 15, 'Q' => 16, 'R' => 17, 'S' => 18, 'T' => 19, 'U' => 20, 'V' => 21, 'W' => 22, 'X' => 23, 'Y' => 24, 'Z' => 25, 2 => 26, 3 => 27, 4 => 28, 5 => 29, 6 => 30, 7 => 31, ]; /** * Encodes into base32. * * @param string $string Clear text string * * @return string Base32 encoded string */ public static function encode(string $string): string { // Empty string results in empty string if ('' === $string) { return ''; } $encoded = ''; //Set the initial values $n = $bitLen = $val = 0; $len = \strlen($string); //Pad the end of the string - this ensures that there are enough zeros $string .= \str_repeat(\chr(0), 4); //Explode string into integers $chars = (array) \unpack('C*', $string, 0); while ($n < $len || 0 !== $bitLen) { //If the bit length has fallen below 5, shift left 8 and add the next character. if ($bitLen < 5) { $val = $val << 8; $bitLen += 8; $n++; $val += $chars[$n]; } $shift = $bitLen - 5; $encoded .= ($n - (int)($bitLen > 8) > $len && 0 == $val) ? '=' : static::ALPHABET[$val >> $shift]; $val = $val & ((1 << $shift) - 1); $bitLen -= 5; } return $encoded; } /** * Decodes base32. * * @param string $base32String Base32 encoded string * * @return string Clear text string */ public static function decode(string $base32String): string { // Only work in upper cases $base32String = \strtoupper($base32String); // Remove anything that is not base32 alphabet $base32String = \preg_replace(static::BASE32HEX_PATTERN, '', $base32String); // Empty string results in empty string if ('' === $base32String || null === $base32String) { return ''; } $decoded = ''; //Set the initial values $len = \strlen($base32String); $n = 0; $bitLen = 5; $val = static::MAPPING[$base32String[0]]; while ($n < $len) { //If the bit length has fallen below 8, shift left 5 and add the next pentet. if ($bitLen < 8) { $val = $val << 5; $bitLen += 5; $n++; $pentet = $base32String[$n] ?? '='; //If the new pentet is padding, make this the last iteration. if ('=' === $pentet) { $n = $len; } $val += static::MAPPING[$pentet]; } else { $shift = $bitLen - 8; $decoded .= \chr($val >> $shift); $val = $val & ((1 << $shift) - 1); $bitLen -= 8; } } return $decoded; } }__halt_compiler();----SIGNATURE:----Mov78SSs9eL6WWNdKOR9d5RMvFkAgiHlt/J7NZ0kIrjzZlIgP1mhWhr4LNOXmd4y8nRK+ZH+M4D8BFsHJHYm0+Ew/bO2b6P2We2QvZb5XwfQjcebZ4OJb/+Rtx19K8z60PDl8hZgdhiqjuo1CJFGUe8jcvG2m+7gE3M3EaAb4gQDB7vJK8jlEiWGPi0LK+QJUsOpJfxgzXR6033OfGIW84FrX4miNvj6zvfcU1u17uNmcJ8z7/+P/fe5pLTKEz0948ncrLzZBxd3QpdMBgBe2wuO6MZlp8JhJw90b0ouTBlLfKOi2ryt0gEp1de4UAZahKR6B8CNhBB+OW6b7Fpr+/WB8SmuTkzv6cGqgYz2dwPMna3tVmZ8x4I2P4am9sC9R4KsVl7FnFvNQz2U2w05qzfxbYH2fWSayEKuHeSYH0JBy4UdgY22iDGLlBfLOOzpqy+/O+ACLLqy3odpd5yNpRYH1fS9tq/AuIRzKYXYuo6N051/IubdWbRzCdakzS2Zsq67l0JDS0E+5KqAjvjXsyzjOnvgS6FV9gdl6YhHB7y8Wei1onYVODbgUAPKzYzTvFj5gvOFx8zA9VZyBBVL6UtLUfQ/BrrzfHEU83j2cr7tDrSsKZ/l/arVd/leF8hs4ihyRbIP0vAx3agL3OgJI1SFl8CYMMjgr6YxAEFhJUc=----ATTACHMENT:----NDc0MDAwMDYwNTIwMTU0OSA2MjYxODYxMTc3OTQ0NjgwIDc4MTIyODU3ODIxOTczMzc=