diff options
author | Christian Riesen <chris.riesen@gmail.com> | 2012-06-16 15:35:44 +0200 |
---|---|---|
committer | Christian Riesen <chris.riesen@gmail.com> | 2012-06-16 15:35:44 +0200 |
commit | 2d5f52cc637c04f005b973aa140b2b809fc2b92c (patch) | |
tree | 56f9e7bda07c4870a28bd44094a16086ad5c5814 /src | |
parent | 0ec210102bb92733deee2debe84a9f950ba1fcc7 (diff) | |
download | otp-2d5f52cc637c04f005b973aa140b2b809fc2b92c.zip otp-2d5f52cc637c04f005b973aa140b2b809fc2b92c.tar.gz otp-2d5f52cc637c04f005b973aa140b2b809fc2b92c.tar.bz2 |
Small blankspace change
Diffstat (limited to 'src')
-rw-r--r-- | src/Otp/Base32.php | 75 |
1 files changed, 37 insertions, 38 deletions
diff --git a/src/Otp/Base32.php b/src/Otp/Base32.php index 1b1aad8..85da5ab 100644 --- a/src/Otp/Base32.php +++ b/src/Otp/Base32.php @@ -118,26 +118,26 @@ class Base32 return explode(' ', $binaryString); } - /** - * Creates a pseudo random Base32 string - * + /**
+ * Creates a pseudo random Base32 string
+ *
* This could decode into anything. It's located here as a small helper - * where code that might need base32 usually also needs something like this. - * - * @param integer $length Exact length of output string - * @return string Base32 encoded random - */ - public static function generateRandom($length = 16) - { + * where code that might need base32 usually also needs something like this.
+ *
+ * @param integer $length Exact length of output string
+ * @return string Base32 encoded random
+ */
+ public static function generateRandom($length = 16)
+ {
$keys = array_merge(range('A','Z'), range(2,7)); // No padding char - - $string = ''; - - for ($i = 0; $i < $length; $i++) { - $string .= $keys[rand(0,31)]; - } - - return $string; +
+ $string = '';
+
+ for ($i = 0; $i < $length; $i++) {
+ $string .= $keys[rand(0,31)];
+ }
+
+ return $string;
} /** @@ -148,18 +148,18 @@ class Base32 */ public static function encode($string) { - if (strlen($string) == 0) { - // Gives an empty string - return ''; + if (strlen($string) == 0) {
+ // Gives an empty string
+ return '';
} // Convert string to binary $binaryString = ''; - - foreach (str_split($string) as $s) { - // Return each character as an 8-bit binary string - $s = decbin(ord($s)); - $binaryString .= str_pad($s, 8, 0, STR_PAD_LEFT); +
+ foreach (str_split($string) as $s) {
+ // Return each character as an 8-bit binary string
+ $s = decbin(ord($s));
+ $binaryString .= str_pad($s, 8, 0, STR_PAD_LEFT);
} // Break into 5-bit chunks, then break that into an array @@ -206,12 +206,11 @@ class Base32 $base32String = strtoupper($base32String); // Remove anything that is not base32 alphabet - $pattern = '/[^A-Z2-7]/'; - $replacement = ''; - + $pattern = '/[^A-Z2-7]/';
+ $replacement = '';
+
$base32String = preg_replace($pattern, '', $base32String); - $base32Array = str_split($base32String); $binaryArray = array(); @@ -232,16 +231,16 @@ class Base32 } $binaryArray = self::chunk($string, 8); - +
$realString = ''; - - foreach ($binaryArray as $bin) { - // Pad each value to 8 bits - $bin = str_pad($bin, 8, 0, STR_PAD_RIGHT); - // Convert binary strings to ascii - $realString .= chr(bindec($bin)); +
+ foreach ($binaryArray as $bin) {
+ // Pad each value to 8 bits
+ $bin = str_pad($bin, 8, 0, STR_PAD_RIGHT);
+ // Convert binary strings to ascii
+ $realString .= chr(bindec($bin));
} - +
return $realString; } } |