1<?PHP2 /**3 * Encryption decryption class, PHP encryption decryption number, for URL encryption4 * This algorithm only supports encrypted numbers. Compare the encryption decryption that applies to the ID field in the database, and the encryption based on the digital display URL. 5 * @version Alpha6 * @ Encryption Principle Tag length + complement + number substitution7 * @ Encryption Step:8 * A-z,a-z,0-9 62 characters, take the first m (number of digits the largest digit) bit as a marker length string, take the m+1 to the M+10 bit as the number substitution string, the remainder is the complement string9 * 1. Calculate the number length n, take the nth bit of garbled characters as the length of the mark. Ten * 2. Calculate the length of the complement, the length of the encrypted string N-1-n is the length of the complement. Gets the complement string based on the specified algorithm. One * 3. Replace the number with a numeric replacement string to get a digitally encrypted string. A * Tag length character + complement string + numeric encrypted string = encrypted strings - * Usage: - * $obj = new Xdeode (9); the * $e _txt = $obj->encode (123); - * echo $e _txt. ' <br/> '; - * echo $key->decode ($e _txt); - */ + classXdeode - { + Private $strbase= "Flpvf70csakvjqgewupxqxsyjizmnh6b1u3b8caekwtd54nrtzomdhog2ylri"; A Private $key,$length,$codelen,$codenums,$codeext; at function__construct ($length= 9,$key= 2543.5415412812){ - $this-Key=$key; - $this->length =$length; - $this->codelen =substr($this->strbase,0,$this-length); - $this->codenums =substr($this->strbase,$this->length,10); - $this->codeext =substr($this->strbase,$this->length + 10); in } - to + functionEncode$nums){ - $rtn= ""; the $numslen=strlen($nums); * //the length of the first digit of the ciphertext tag $ $begin=substr($this->codelen,$numslen-The);Panax Notoginseng - //extension bits of ciphertext the $extlen=$this->length-$numslen-1; + $temp=Str_replace(‘.‘, ‘‘,$nums/$this-Key); A $temp=substr($temp,-$extlen); the + $arrextTemp=Str_split($this-codeext); - $arrext=Str_split($temp); $ foreach($arrext as $v) { $ $rtn.=$arrextTemp[$v]; - } - the $arrnumsTemp=Str_split($this-codenums); - $arrnums=Str_split($nums);Wuyi foreach($arrnums as $v) { the $rtn.=$arrnumsTemp[$v]; - } Wu return $begin.$rtn; - } About $ - functionDecode$code){ - - $begin=substr($code, 0,1); A $rtn= ' '; + $len=Strpos($this->codelen,$begin); the if($len!==false){ - $len++; $ $arrnums=Str_split(substr($code,-$len)); the foreach($arrnums as $v) { the $rtn.=Strpos($this->codenums,$v); the } the } - in return $rtn; the } the } About the $obj=NewXdeode (10); the Echo $obj->encode (1). " <br/> "; the Echo $obj->encode (2). " <br/> "; + Echo $obj->encode (3). " <br/> "; - Echo $obj->encode (4). " <br/> "; the Echo $obj->encode (5). " <br/> ";Bayi Echo $obj->encode (6). " <br/> "; the Echo $obj->encode (7). " <br/> "; the Echo $obj->encode (8). " <br/> "; - Echo $obj->encode (9). " <br/> "; - Echo $obj->encode (10). " <br/> "; the Echo $obj->encode (45762454). " <br/> "; the Echo $obj->encode (1023213123). " <br/> "; the Echo $obj->encode (134320). " <br/> "; the Echo' ; - the Echo $obj->decode (' FZXXMYQZXV '). " <br/> "; the Echo $obj->decode (' FSSYJZXSSJ '). " <br/> "; the Echo $obj->decode (' Fmnyixhxnq '). " <br/> ";94 Echo $obj->decode (' FQJJZHSSJG '). " <br/> "; the Echo $obj->decode (' Fzyqinziye '). " <br/> "; the Echo $obj->decode (' Fizmqynyzw '). " <br/> "; the Echo $obj->decode (' Fnsnsxxjyu '). " <br/> ";98 Echo $obj->decode (' FQNHYNJJHP '). " <br/> "; About Echo $obj->decode (' Fyiqiimiix '). " <br/> "; - Echo $obj->decode (' Lxxmyqzxvk '). " <br/> ";101 Echo $obj->decode (' Csgeuwjgeg '). " <br/> ";102 Echo $obj->decode (' AQSSMNHXXZZJJNVKJQJVQVJQ '). " <br/> ";103 Echo $obj->decode (' 7ziiVqgqjk '). " <br/> ";104 the //FZXXMYQZXV106 //FSSYJZXSSJ107 //FMNYIXHXNQ108 //FQJJZHSSJG109 //fzyqinziye the //FIZMQYNYZW111 //fnsnsxxjyu the //FQNHYNJJHP113 //fyiqiimiix the //LXXMYQZXVK the //csgeuwjgeg the //AQSSMNHXXZZJJNVKJQJVQVJQ117 //7ZIIVQGQJK118 //1119 //2 - //3121 //4122 //5123 //6124 //7 the //8126 //9127 //10 - //45762454129 //1023213123 the //134320
PHP Encrypted decryption number