Home > Backend Development > PHP Tutorial > paip. Cross-platform and cross-language custom encryption method_PHP tutorial

paip. Cross-platform and cross-language custom encryption method_PHP tutorial

WBOY
Release: 2016-07-13 17:52:51
Original
840 people have browsed it

paip. Cross-platform and cross-language custom encryption method

Today we are mainly going to transfer parameters between ASP and PHP system modules. For convenience, MD5 signature is not needed and we are ready to use it directly

DES encryption. . However, ASP and PHP's DES cannot encrypt each other. . . Fortunately, there are other CBC modes, IV vectors, etc.

. There are a lot of them. After adjusting them for a long time, it still doesn't work. Forget it, let's write the encryption method by ourselves. .

The main method of password encryption is substitution and shifting. . In addition, my requirement is that the key must be used, and the algorithm

Simple. . The DES algorithm looks like a big deal at first glance, MD is difficult to use. PASS. . . Although the effect is good, it is a bit complicated and difficult to rewrite

. .

Here, I have conceived the idea of ​​​​encryption:

1. Reverse the string first
2. Add the string and KEY group in a loop
3. The added results are converted into hexadecimal characters and concatenated. . Mainly to save some space. .
4. Just return the result. . .
5. The decryption process can be reversed. .

dim key_L71723
key_L71723="iluvnjyn"
dim msg
msg="admin"

dim newstr
newstr=atiEncode(msg,key_L71723)
response.Write(newstr) 'Show the encryption result is D7D5E2DACF
response.Write( atiDecode(newstr,key_L71723) )

---------------------------------------------
function atiEncode(msg,key)

msg=back_str(msg) 'Reverse string
dim key_L71723
key_L71723= key
​ key_L71723=key_L71723+key_L71723
key_L71723=key_L71723+key_L71723
Key_L71723=key_L71723+key_L71723
dim msgarr
msgarr=str2array(msg)
dim keyarr
keyarr=str2array(key_L71723)
dim newstr
newstr=""
'Perform cyclic addition with KEY group
for i=0 to ubound(msgarr)
dim char
​​​​ char=msgarr(i)
dim newchar 'int format
newchar = asc (char)+asc(keyarr(i))
newchar= hex(newchar)

newstr=newstr+cstr(newchar)
next

atiEncode=newstr
end function

function atiDecode(msg,key)

dim key_L71723
key_L71723= key
​ key_L71723=key_L71723+key_L71723
key_L71723=key_L71723+key_L71723
Key_L71723=key_L71723+key_L71723
dim msgarr
msgarr=str2arrayx(msg,2)
dim keyarr
keyarr=str2array(key_L71723)
dim newstr
newstr=""

for i=0 to ubound(msgarr)
dim charInt

​​​​​ charInt=chn10(msgarr(i) ) 'encode char

dim newchar www.2cto.com
newchar=chr( charInt-ascw(keyarr(i)))
newstr=newstr+newchar
next

newstr=back_str(newstr)
atiDecode=newstr
end function


Author:attilax

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478092.htmlTechArticlepaip. Cross-platform and cross-language custom encryption method Today is mainly about parameter transfer between ASP and PHP system modules , for convenience, no MD5 signature is needed, and DES encryption is directly used. . But...
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template