3 * A Packing Mode implementation of the ISO 10126 standard
7 * @category PHPCryptLib
9 * @subpackage PackingMode
10 * @author Anthony Ferrara <ircmaxell@ircmaxell.com>
11 * @copyright 2011 The Authors
12 * @license http://www.opensource.org/licenses/mit-license.html MIT License
13 * @version Build @@version@@
16 namespace CryptLib\Encryption\PackingMode
;
19 * A Packing Mode implementation of the ISO 10126 standard
21 * @category PHPCryptLib
23 * @subpackage PackingMode
24 * @author Anthony Ferrara <ircmaxell@ircmaxell.com>
26 class ISO10126
implements \CryptLib\Encryption\PackingMode
{
29 * Pad the string to the specified size
31 * @param string $string The string to pad
32 * @param int $blockSize The size to pad to
34 * @return string The padded string
36 public function pad($string, $blockSize = 32) {
37 $pad = $blockSize - (strlen($string) %
$blockSize);
39 for ($i = 1; $i < $pad; $i++
) {
40 $padstr .= chr(mt_rand(0, 255));
42 return $string . $padstr . chr($pad);
46 * Strip the padding from the supplied string
48 * @param string $string The string to trim
50 * @return string The unpadded string
52 public function strip($string) {
53 $end = ord(substr($string, -1));
54 $len = strlen($string) - $end;
55 return substr($string, 0, $len);