protected function generateCode($all_chars, $code_break, $last_code = false) { $seed = CASHSystem::getSystemSalt(); $this->consistentShuffle($all_chars, $seed); $this->consistentShuffle($code_break, $seed); if (!$last_code) { $last_code = ''; for ($i = 1; $i <= 10; $i++) { $last_code .= $all_chars[rand(0, count($all_chars) - 1)]; } } $sequential = substr($last_code, 1, $code_break[0]) . substr($last_code, 0 - (7 - $code_break[0])); $sequential = $this->iterateChars($sequential, $all_chars); $new_code = $all_chars[rand(0, count($all_chars) - 1)] . substr($sequential, 0, $code_break[0]) . $all_chars[rand(0, count($all_chars) - 1)] . $all_chars[rand(0, count($all_chars) - 1)] . substr($sequential, 0 - (7 - $code_break[0])); return $new_code; }
/** * Super basic XOR encoding — used for encoding connection data * */ public static function simpleXOR($input, $key = false) { if (!$key) { $key = CASHSystem::getSystemSalt(); } // append key on itself until it is longer than the input while (strlen($key) < strlen($input)) { $key .= $key; } // trim key to the length of the input $key = substr($key, 0, strlen($input)); // Simple XOR'ing, each input byte with each key byte. $result = ''; for ($i = 0; $i < strlen($input); $i++) { $result .= $input[$i] ^ $key[$i]; } return $result; }