<?php
//echo $_GET["key"];
if (!class_exists('crm_hardlock')) require_once("common_cadline_libraries/crm_hardlock.class.php");

$action = trim(strtolower($_GET['encode']));

switch ($action) {
    case 'true': {
            $data = crm_hardlock::encode($_GET["privateKey"], $_GET["publicKey"], "Use std::stringstream to convert integers into strings and its special");

            echo $data;
            break;
        }
    case 'false': {
            //header('Content-type: text/html; charset=utf-8');
            $data = crm_hardlock::decode($_GET["privateKey"], $_GET["publicKey"], $_GET["data"]);

            echo $data;

            //echo crmHelper::decode($_GET["privateKey"], $_GET["publicKey"], $_GET["data"]);
            break;
        }
}

    /*
        public static function encode($string,$key) {
            $key = sha1($key);
            $strLen = strlen($string);
            $keyLen = strlen($key);
            for ($i = 0; $i < $strLen; $i++) {
                $ordStr = ord(substr($string,$i,1));
                if ($j == $keyLen) { $j = 0; }
                $ordKey = ord(substr($key,$j,1));
                $j++;
                $hash .= strrev(base_convert(dechex($ordStr + $ordKey),16,36));
            }
            return $hash;
        }
    */
