ParagonIE_Sodium_Core_Base64_Original::encode6Bits

Advertisement

Summery Summery

Uses bitwise operators instead of table-lookups to turn 8-bit integers into 6-bit integers.

Syntax Syntax

ParagonIE_Sodium_Core_Base64_Original::encode6Bits( int $src )

Parameters Parameters

$src

(Required)

Return Return

(string)

Source Source

File: wp-includes/sodium_compat/src/Core/Base64/Original.php

    protected static function encode6Bits($src)
    {
        $diff = 0x41;

        // if ($src > 25) $diff += 0x61 - 0x41 - 26; // 6
        $diff += ((25 - $src) >> 8) & 6;

        // if ($src > 51) $diff += 0x30 - 0x61 - 26; // -75
        $diff -= ((51 - $src) >> 8) & 75;

        // if ($src > 61) $diff += 0x2b - 0x30 - 10; // -15
        $diff -= ((61 - $src) >> 8) & 15;

        // if ($src > 62) $diff += 0x2f - 0x2b - 1; // 3
        $diff += ((62 - $src) >> 8) & 3;

        return pack('C', $src + $diff);
    }

Advertisement

Advertisement

Leave a Reply