Home  >  Article  >  Backend Development  >  Use PHP to carry out simple character encryption_PHP tutorial

Use PHP to carry out simple character encryption_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:27:18747browse

I had nothing to do and wanted to try encryption, so I used PHP, which I am familiar with, to write it...

Principle:

Convert the characters into ASCII codes, then convert the ASCII codes, convert the results into characters again, and the encryption is completed.

 ?

Implementation:

Enter the characters to be encrypted:

error_reporting(255);

 if ( isset($val) )

 {

 ?//Encrypt

 ??for($i=0; $i

 ?{

 ??$c = $value[$i];

 ??$c = ord($c);

 ??if ( $c>31 && $c<107 )

 ??{

 ???$c = $c+20;

 ???print( "Characters before encryption: ". $val );

 ???print( "

Encrypted characters: ". chr($c) );

 ???print( "

 ");

 ??}?

 ??elseif ( $c>106 && $c<127)

 ??{

 ???$c = $c-75;

 ???print( "Characters before encryption: ". $val );

 ???print( "

Encrypted characters: ". chr($c) );

 ???print( "

 ");??

 ??}

 ?}

 }

else

 {

 ?print("Please enter the characters you want to encrypt");

 }

 ?>

When converting asc, you should pay attention to some issues. For example, asc is from 0-127, so when converting, there should be no asc greater than 127 or less than 0. This must be controlled well. It is best to list the results yourself. Take a look at the table.

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/820404.htmlTechArticleI had nothing to do and wanted to try encryption, so I used PHP, which I am familiar with, to write... Principle: Convert characters into ASCII codes, then convert the ASCII codes, convert the results into characters, and the encryption is completed...
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