Skip to content

Instantly share code, notes, and snippets.

@divinity76
Created April 9, 2023 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save divinity76/f4aff8f07c328f3d4e4650d9d9db4f82 to your computer and use it in GitHub Desktop.
Save divinity76/f4aff8f07c328f3d4e4650d9d9db4f82 to your computer and use it in GitHub Desktop.
base64 encoded length/efficiency thingy..
<?php
// https://3v4l.org/XsSjl
function base64url_encode($data) {
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
$str="";
for($i=1;$i<30;++$i){
$str.=chr($i);
$encoded_base = base64url_encode($str);
$encoded_base_length = strlen($encoded_base);
$encoded_hex = bin2hex($str);
$encoded_hex_length = strlen($encoded_hex);
echo "{$i}: base64: {$encoded_base_length}: hex: {$encoded_hex_length}: {$encoded_base}\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment