ParagonIE_Sodium_Core_Base64_UrlSafe::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_UrlSafe::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

(int) (Required)

Return Return

(int)

Source Source

File: wp-includes/sodium_compat/src/Core/Base64/UrlSafe.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 == 0x2c) $ret += 62 + 1;
        $ret += (((0x2c - $src) & ($src - 0x2e)) >> 8) & 63;

        // if ($src == 0x5f) ret += 63 + 1;
        $ret += (((0x5e - $src) & ($src - 0x60)) >> 8) & 64;

        return $ret;
    }

Advertisement

Advertisement

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.