| @@ 93-116 (lines=24) @@ | ||
| 90 | * |
|
| 91 | * @return boolean Returns true |
|
| 92 | */ |
|
| 93 | public function encrypt(&$text) |
|
| 94 | { |
|
| 95 | $this->operation(parent::ENCRYPT); |
|
| 96 | ||
| 97 | for ($i = 1; $i <= 32; ++$i) |
|
| 98 | { |
|
| 99 | $pos = (4 * $i) - 4; |
|
| 100 | $subkey = substr($this->expanded_key, $pos, 4); |
|
| 101 | ||
| 102 | if ($i >= 1 && $i <= 8) { |
|
| 103 | $this->ruleA($text, $subkey, $i); |
|
| 104 | } |
|
| 105 | ||
| 106 | if ($i >= 9 && $i <= 16) { |
|
| 107 | $this->ruleB($text, $subkey, $i); |
|
| 108 | } |
|
| 109 | ||
| 110 | if ($i >= 17 && $i <= 24) { |
|
| 111 | $this->ruleA($text, $subkey, $i); |
|
| 112 | } |
|
| 113 | ||
| 114 | if ($i >= 25 && $i <= 32) { |
|
| 115 | $this->ruleB($text, $subkey, $i); |
|
| 116 | } |
|
| 117 | } |
|
| 118 | ||
| 119 | return true; |
|
| @@ 128-151 (lines=24) @@ | ||
| 125 | * |
|
| 126 | * @return boolean Returns true |
|
| 127 | */ |
|
| 128 | public function decrypt(&$text) |
|
| 129 | { |
|
| 130 | $this->operation(parent::DECRYPT); |
|
| 131 | ||
| 132 | for ($i = 32; $i >= 1; --$i) |
|
| 133 | { |
|
| 134 | $pos = ($i - 1) * 4; |
|
| 135 | $subkey = substr($this->expanded_key, $pos, 4); |
|
| 136 | ||
| 137 | if ($i <= 32 && $i >= 25) { |
|
| 138 | $this->ruleB($text, $subkey, $i); |
|
| 139 | } |
|
| 140 | ||
| 141 | if ($i <= 24 && $i >= 17) { |
|
| 142 | $this->ruleA($text, $subkey, $i); |
|
| 143 | } |
|
| 144 | ||
| 145 | if ($i <= 16 && $i >= 9) { |
|
| 146 | $this->ruleB($text, $subkey, $i); |
|
| 147 | } |
|
| 148 | ||
| 149 | if ($i <= 8 && $i >= 1) { |
|
| 150 | $this->ruleA($text, $subkey, $i); |
|
| 151 | } |
|
| 152 | } |
|
| 153 | ||
| 154 | return true; |
|