ParagonIE_Sodium_Core_Base64_Original::decode6Bits

Advertisement

Summery Summery

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

Syntax Syntax

ParagonIE_Sodium_Core_Base64_Original::decode6Bits( int $src )

Description Description

Base64 character set: [A-Z] [a-z] [0-9] + / 0x41-0x5a, 0x61-0x7a, 0x30-0x39, 0x2b, 0x2f

Parameters Parameters

$src

(Required)

Return Return

(int)

Source Source

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

    protected static function decode6Bits($src)
    {
        $ret = -1;

        // if ($src > 0x40 && $src < 0x5b) $ret += $src - 0x41 + 1; // -64
        $ret += (((0x40 - $src) & ($src - 0x5b)) >> 8) & ($src - 64);

        // if ($src > 0x60 && $src < 0x7b) $ret += $src - 0x61 + 26 + 1; // -70
        $ret += (((0x60 - $src) & ($src - 0x7b)) >> 8) & ($src - 70);

        // if ($src > 0x2f && $src < 0x3a) $ret += $src - 0x30 + 52 + 1; // 5
        $ret += (((0x2f - $src) & ($src - 0x3a)) >> 8) & ($src + 5);

        // if ($src == 0x2b) $ret += 62 + 1;
        $ret += (((0x2a - $src) & ($src - 0x2c)) >> 8) & 63;

        // if ($src == 0x2f) ret += 63 + 1;
        $ret += (((0x2e - $src) & ($src - 0x30)) >> 8) & 64;

        return $ret;
    }

Advertisement

Advertisement

Leave a Reply