PHP语言的^运算符经常用来做加密的运算,解密也直接用^就行,但是和其他语言通信时,其他语言例如objective-c未必能解的出来PHP的^,尤其是当php使用多个字符串如:abc^def,这样的运算时,其他语言少有这种直接可运算的,更不能解的出来 计算原理: a^b: a和b
PHP语言的^运算符经常用来做加密的运算,解密也直接用^就行,但是和其他语言通信时,其他语言例如objective-c未必能解的出来PHP的^,尤其是当php使用多个字符串如:'abc'^'def',这样的运算时,其他语言少有这种直接可运算的,更不能解的出来
计算原理:
'a'^'b' :
a和b的ASCII分别为97和98,转换2进制后分别为:1100001,1100010
然后使用此二位进行异或运算,得到结果:11
再用把二进制数11转换为字符串
在windon命令行下计算结果会显示一个乱码
注:如果在PHP下欲将二进制11转换为此结果需要使用附录一的函数bin2str,网上也有其他字符串转二进制的方法,但有的在此处使用结果不一致,需注意
上面是两个单个字符串的简单异或运算,网上也有介绍,但是关于多个字符串的异或运算,网上没查到相关资料,楼主在这儿大致解释一下PHP这么搞的原理,其他语言照这个思路和逻辑一样能解密PHP的^
'abc' ^ 'def':
a,b,c的ASCII分别为97,98,99,转换2进制后分别为:1100001,1100010,1100011
d,e,f的ASCII分别为100,101,102,转换2进制后分别为:1100100,1100101,1100110
按左边对其,分别比较a和d,b和e,c和f的ASCII码二进制的异或值:101 111 101
然后对这三个分别二进制转字符串进行拼接
'abc' ^ 'defgh':
有的语言也能实现上面的字符串异或运算,当看到这个就会愣了一下,因为发现为啥两边字符数不一样也能异或运算
很简单 php按左对齐只比较两者的短的字符串的那个长度,后面的都舍去了
楼主个人网站:https://www.riji.info
function str2bin($str = ''){ $bin_arr = array(); $str_arr = preg_split('//u', $str, 0, PREG_SPLIT_NO_EMPTY); foreach ($str_arr as $val) { if (ord($val) > 127) { $bin_arr[] = hex2bin(str_replace('%', '', urlencode($val))); } else { $bin_arr[] = decbin(ord($val)); } } return implode(' ', $bin_arr); } function bin2str($bin_str = ''){ $str = ''; $bin_str = explode(' ', $bin_str); foreach ($bin_str as $val) { if (bindec($val) < 127) { $str .= chr(bindec($val)); } else { $str .= urldecode('%' . implode('%', str_split(bin2hex($val), 2))); } } return $str; }

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Chinese version
Chinese version, very easy to use

Dreamweaver Mac version
Visual web development tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft