Add Base32 decoding method and implement SecretOtp class with serialization methods
Some checks are pending
CI / release (push) Waiting to run
CI / debug (push) Waiting to run
CI / release_executable (push) Waiting to run
CI / debug_executable (push) Waiting to run
CI / check-phpunit (push) Waiting to run
CI / check-phpdoc (push) Waiting to run
CI / generate-phpdoc (push) Blocked by required conditions
CI / test (push) Blocked by required conditions
CI / release-documentation (push) Blocked by required conditions
CI / release-artifacts (push) Blocked by required conditions

This commit is contained in:
netkas 2025-03-27 14:09:56 -04:00
parent b6aa591f8c
commit 200b6a7c1f
Signed by: netkas
GPG key ID: 4D8629441B76E4CC
3 changed files with 83 additions and 2 deletions

View file

@ -106,4 +106,33 @@
{
return new SocialClient(self::generateRandomPeer($domain, $length, $prefix));
}
/**
* Encodes a string to Base32.
*
* @param string $input The string to be encoded.
* @return string Returns the encoded string.
*/
public static function decodeBase32(string $input): string
{
$input = strtoupper($input);
$v = 0;
$k = 0;
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
$output = '';
for ($i = 0; $i < strlen($input); $i++)
{
$v = ($v << 5) | strpos($chars, $input[$i]);
$k += 5;
if ($k >= 8)
{
$k -= 8;
$output .= chr(($v >> $k) & 0xFF);
}
}
return $output;
}
}