Use PHP to carry out simple character encryption

Source: Internet
Author: User

Have nothing to do, want to try encryption, and then use their familiar php to write ...

Principle:

Convert the characters to ASCII, then convert the ASCII code, convert the result into a character, and the encryption is done.

?

Realize:

Enter the characters you want to encrypt:

Error_reporting (255);

if (Isset ($val))

{

?//For encryption

?? for ($i =0; $i

? {

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

?? $c = Ord ($c);

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

?? {

??? $c = $c +20;

??? Print ("Pre-encrypted character:".) $val);

??? Print ("

Encrypted character: ". Chr ($c));

??? Print ("

");

??}?

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

?? {

??? $c = $c-75;

??? Print ("Pre-encrypted character:".) $val);

??? Print ("

Encrypted character: ". Chr ($c));

??? Print ("

");??

??}

?}

}

Else

{

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

}

?>

The process of conversion to ASC should pay attention to some problems, such as ASC is from 0-127, then the conversion can not appear greater than 127 or less than 0 ASC, this should be controlled, the best results of their own list to see.

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

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.