<?php 

	class Encryption{
		private static function keyCode(){
			$key = SECRET_KEY;
			$keycode = 0;

			for ($i=0; $i < strlen($key); $i++) {
				$keycode += ord($key[$i]);
			}

			return $keycode;
		}

		public static function encode($string){
			$string = strval($string);
			$chars = [
				"1" => "&dfc",
				"2" => "Usb4",
				"3" => "H8%p",
				"4" => "Jj0v",
				"5" => "fcUs",
				"6" => "%p&d",
				"7" => "Aq5%",
				"8" => "Ytr7",
				"9" => "r7Aq",
				"0" => "8%df",
				"-" => "Ax&d"
			];

			$keycode = self::keyCode();

			$crypt = "";

			for ($i=0; $i < strlen($string); $i++) {
				$crypt .= (ord($string[$i]) * $keycode);
				
				if (($i+1) < strlen($string)) {
					$crypt .= "-";
				}
			}

			$new_crypt = "";

			for ($i=0; $i < strlen($crypt); $i++) {
				$new_crypt .= $chars[$crypt[$i]];
			}

			return base64_encode(strrev(gzdeflate($new_crypt, 9)));
		}

		public static function decode($crypt){
			$chars = [
				"&dfc" => "1",
				"Usb4" => "2",
				"H8%p" => "3",
				"Jj0v" => "4",
				"fcUs" => "5",
				"%p&d" => "6",
				"Aq5%" => "7",
				"Ytr7" => "8",
				"r7Aq" => "9",
				"8%df" => "0",
				"Ax&d" => "-"
			];

			$aux = gzinflate(strrev(base64_decode($crypt)));

			$aux2 = "";

			for ($i=0; $i < (strlen($aux)/4); $i++) {
				$aux2 .= $chars[substr($aux, (4*$i), 4)];
			}

			$aux3 = explode("-", $aux2);

			$keycode = self::keyCode();

			$string = "";

			for ($i=0; $i < count($aux3); $i++) {
				$string .= chr(intval($aux3[$i])/$keycode);
			}

			return $string;
		}
	}

?>