Home  >  Article  >  Backend Development  >  用PHP开展简单的字符加密

用PHP开展简单的字符加密

WBOY
WBOYOriginal
2016-06-13 11:58:35815browse

用PHP进行简单的字符加密

原作者:http://www.verydemo.com/demo_c116_i52209.html

无事可做,想试试加密,于是就使用了自己熟悉的PHP来写了...

原理:

把字符转化成ASCII码,然后对ASCII码进行换算,把结果再转化成字符,加密完成.

?

实现:


输入要加密的字符:

?

error_reporting(255);
if ( isset($val) )
{
?//进行加密
??for($i=0; $i
?{
??$c = $value[$i];
??$c = ord($c);
??if ( $c>31 && $c??{
???$c = $c+20;
???print( "加密前的字符: ". $val );
???print( "
加密后的字符: ". chr($c) );
???print( "

");
??}?
??elseif ( $c>106 && $c??{
???$c = $c-75;
???print( "加密前的字符: ". $val );
???print( "
加密后的字符: ". chr($c) );
???print( "

");??
??}
?}
}
else
{
?print("请输入你要加密的字符");
}

?>

对asc进行转换的过程中要注意一些问题,比如asc是从0-127,那么进行转化的时候就不能出现大于127或者小于0的asc,这个要控制好,最好成绩自己列张表看看.

....................................................................

Statement:
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