Home >Backend Development >PHP Tutorial >Use PHP to carry out simple character encryption_PHP tutorial
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.
................................................ .............