Exemple #1
0
 function invMixColumns($state)
 {
     $s_prime = array();
     for ($i = 0; $i < sizeof($state); $i++) {
         #for each column in the state
         $column = array();
         foreach ($state as $index => $row) {
             #get the column
             $column[] = $row[$i];
         }
         foreach ($this->invMixState as $index => $row) {
             #matrix multiplication
             if (!array_key_exists($index, $s_prime)) {
                 $s_prime[$index] = array();
             }
             $next = array();
             for ($j = 0; $j < sizeof($column); $j++) {
                 $next[] = AES::ffMultiply($column[$j], $row[$j]);
             }
             for ($j = 1; $j < sizeof($next); $j++) {
                 $first = str_pad(base_convert($next[0], 16, 2), 8, "0", STR_PAD_LEFT);
                 $second = str_pad(base_convert($next[$j], 16, 2), 8, "0", STR_PAD_LEFT);
                 $next[0] = AES::ffAdd($first, $second);
             }
             $s_prime[$index][] = $next[0];
         }
     }
     //        $this->printState($s_prime);
     return $s_prime;
 }