可加密64编码解码,用于对ID的编码解码
可加密64编码解码,用于对ID的编码解码
<?php /** * 可加密64编码解码,用于对ID的编码解码 */ class code { private $key = null; function __construct($key) { $this->key = $key; } /** * 对数字编码 */ function encode($value) { $x = sprintf("%d", intval($value) ^ intval($this->key)); $y = $this->encode_b64(intval($x)); return $y; } /** *解码 */ function decode($pwd) { $pwd = $this->decode_b64($pwd); $re = strval(intval($pwd) ^ intval($this->key)); return $re; } /** * 重置密钥 */ function reset_key($key) { $this->key = $key; } /** * 64进位编码 */ public function encode_b64($n) { $table = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_'; $result = array(); $temp = $n; if (0 == $temp) { $result[] = '0'; } else { while (0 < $temp) { $result[] = $table[$temp % 64]; $temp = intval($temp / 64); } } //反转数组 krsort($result); return implode('', $result); } /** * 64进位解码 */ public function decode_b64($str) { $table = array("0"=> 0,"1"=> 1,"2"=> 2,"3"=> 3,"4"=> 4,"5"=> 5, "6"=> 6,"7"=> 7,"8"=> 8,"9"=> 9, "a"=> 10,"b"=> 11,"c"=> 12,"d"=> 13,"e"=> 14,"f"=> 15,"g"=> 16, "h"=> 17,"i"=> 18,"j"=> 19,"k"=> 20,"l"=> 21,"m"=> 22,"n"=> 23, "o"=> 24,"p"=> 25,"q"=> 26,"r"=> 27,"s"=> 28,"t"=> 29,"u"=> 30, "v"=> 31,"w"=> 32,"x"=> 33,"y"=> 34,"z"=> 35, "A"=> 36,"B"=> 37,"C"=> 38,"D"=> 39,"E"=> 40,"F"=> 41,"G"=> 42, "H"=> 43,"I"=> 44,"J"=> 45,"K"=> 46,"L"=> 47,"M"=> 48,"N"=> 49, "O"=> 50,"P"=> 51,"Q"=> 52,"R"=> 53,"S"=> 54,"T"=> 55,"U"=> 56, "V"=> 57,"W"=> 58,"X"=> 59,"Y"=> 60,"Z"=> 61, "-"=> 62,"_"=> 63); $result = 0; foreach (range(0, strlen($str) - 1) as $i) { $result *= 64; $result += $table[$str[$i]]; } return $result; } } $d = new code('123123'); echo $d->encode(222584587),"n"; echo $d->decode('dhr_U'),"n"; $d = new code('333333'); echo $d->encode(222584587),"n"; echo $d->decode('dgkAu'),"n";
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article
What's New in Windows 11 KB5054979 & How to Fix Update Issues
3 weeks ago
By DDD
How to fix KB5055523 fails to install in Windows 11?
2 weeks ago
By DDD
InZoi: How To Apply To School And University
4 weeks ago
By DDD
How to fix KB5055518 fails to install in Windows 10?
2 weeks ago
By DDD
Roblox: Dead Rails – How To Summon And Defeat Nikola Tesla
1 months ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
