You are here

protected static function ParagonIE_Sodium_Core_Base64_Original::encode6Bits in Automatic Updates 8

Same name and namespace in other branches
  1. 7 vendor/paragonie/sodium_compat/src/Core/Base64/Original.php \ParagonIE_Sodium_Core_Base64_Original::encode6Bits()

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

Parameters

int $src:

Return value

string

1 call to ParagonIE_Sodium_Core_Base64_Original::encode6Bits()
ParagonIE_Sodium_Core_Base64_Original::doEncode in vendor/paragonie/sodium_compat/src/Core/Base64/Original.php

File

vendor/paragonie/sodium_compat/src/Core/Base64/Original.php, line 230

Class

ParagonIE_Sodium_Core_Base64_Original
Class ParagonIE_Sodium_Core_Base64

Code

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);
}