MediaWiki  1.33.0
base32.php
Go to the documentation of this file.
1 <?php
24 class Base32 {
25 
26  private static $lut = array(
27  "A" => 0, "B" => 1,
28  "C" => 2, "D" => 3,
29  "E" => 4, "F" => 5,
30  "G" => 6, "H" => 7,
31  "I" => 8, "J" => 9,
32  "K" => 10, "L" => 11,
33  "M" => 12, "N" => 13,
34  "O" => 14, "P" => 15,
35  "Q" => 16, "R" => 17,
36  "S" => 18, "T" => 19,
37  "U" => 20, "V" => 21,
38  "W" => 22, "X" => 23,
39  "Y" => 24, "Z" => 25,
40  "2" => 26, "3" => 27,
41  "4" => 28, "5" => 29,
42  "6" => 30, "7" => 31
43  );
44 
48  public static function decode($b32) {
49 
50  $b32 = strtoupper($b32);
51 
52  if (!preg_match('/^[ABCDEFGHIJKLMNOPQRSTUVWXYZ234567]+$/', $b32, $match))
53  throw new Exception('Invalid characters in the base32 string.');
54 
55  $l = strlen($b32);
56  $n = 0;
57  $j = 0;
58  $binary = "";
59 
60  for ($i = 0; $i < $l; $i++) {
61  // Move buffer left by 5 to make room
62  $n = $n << 5;
63  // Add value into buffer
64  $n = $n + self::$lut[$b32[$i]];
65  // Keep track of number of bits in buffer
66  $j = $j + 5;
67 
68  if ($j >= 8) {
69  $j = $j - 8;
70  $binary .= chr(($n & (0xFF << $j)) >> $j);
71  }
72  }
73 
74  return $binary;
75  }
76 
80  public static function encode($string) {
81 
82  if (empty($string))
83  throw new Exception('Empty string.');
84 
85  $b32 = "";
86  $binary = "";
87 
88  $bytes = str_split($string);
89  $length = count( $bytes );
90  for ($i = 0; $i < $length; $i++) {
91  $bits = base_convert(ord($bytes[$i]), 10, 2);
92  $binary .= str_pad($bits, 8, '0', STR_PAD_LEFT);
93  }
94 
95  $map = array_keys(self::$lut);
96  $fivebits = str_split($binary, 5);
97  $length = count( $fivebits );
98  for ($i = 0; $i < $length; $i++) {
99  $dec = base_convert(str_pad($fivebits[$i], 5, '0'), 2, 10);
100  $b32 .= $map[$dec];
101  }
102 
103  return $b32;
104  }
105 }
Base32\$lut
static $lut
Definition: base32.php:26
captcha-old.count
count
Definition: captcha-old.py:249
Base32\encode
static encode($string)
Encodes a binary string into a base32 string according to RFC 4648 (no padding).
Definition: base32.php:80
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
Base32\decode
static decode($b32)
Decodes a base32 string into a binary string according to RFC 4648.
Definition: base32.php:48
Base32
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Ge...
Definition: base32.php:24