From 8762d68466b825382f4708a0eebbd3074e32c5c5 Mon Sep 17 00:00:00 2001 From: cynic Date: Wed, 13 Sep 2023 22:24:02 -0500 Subject: add structure for `Oracles' (special answers depending on queries + a few implementations (#10) incl. a calculator, a hash encoder + rot13 and b64!, and a "what time is it" with timezone selection frontend injected in $payload["left"] in web.php you can see this live [on my instance](https://4get.silly.computer/web?s=7%2B8(9%5E2)&scraper=brave&nsfw=yes) (there are some issues that aren't related to this PR. favicons, etc. I'll fix them later.) Reviewed-on: https://git.lolcat.ca/lolcat/4get/pulls/10 Co-authored-by: cynic Co-committed-by: cynic --- oracles/encoder.php | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 oracles/encoder.php (limited to 'oracles/encoder.php') diff --git a/oracles/encoder.php b/oracles/encoder.php new file mode 100644 index 0000000..00b5ad0 --- /dev/null +++ b/oracles/encoder.php @@ -0,0 +1,40 @@ + "text encoder/hasher" + ]; + private $special_types = [ + "rot13", + "base64" + ]; + public function check_query($q) { + $types = array_merge($this->special_types, hash_algos()); + foreach ($types as $type) { + $type .= " "; + if (str_starts_with($q, $type)) { + return true; + } + } + return false; + } + public function generate_response($q) + { + $type = explode(" ", $q)[0]; + $victim = substr($q, strlen($type)+1); + if (in_array($type, hash_algos())) { + return [$type." hash" => hash($type, $victim)]; + } + switch ($type) { + case "rot13": + return ["rot13 encoded" => str_rot13($victim)]; + case "base64": + return [ + "base64 encoded" => base64_encode($victim), + "base64 decoded" => base64_decode($victim) + ]; + } + return ""; + } +} +?> \ No newline at end of file -- cgit v1.2.3