Simple character encryption with PHP _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Use PHP for simple character encryption. There is nothing to do. I want to try encryption, so I used my familiar PHP to write it... principle: convert a character into an ASCII code, convert the ASCII code, convert the result into a character, and complete encryption. try encryption, so I used my familiar PHP to write...

Principle:

Convert characters into ASCII codes, convert the ASCII codes, convert the results into characters, and complete encryption.

?

Implementation:

Enter the characters to encrypt:

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 ("character before encryption:". $ val );

??? Print ("

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

??? Print ("

");

??}?

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

?? {

??? $ C = $ C-75;

??? Print ("character before encryption:". $ val );

??? Print ("

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

??? Print ("

");??

??}

?}

}

Else

{

? Print ("Enter the characters you want to encrypt ");

}

?>

During the conversion process of asc, pay attention to some problems. for example, if asc is from 0 to 127, then asc Greater than 127 or less than 0 cannot appear during conversion, this should be well controlled. it is best to make a table by yourself.

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

Principle: convert the character into ASCII code, convert the ASCII code, convert the result into a character, and complete encryption...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.