SHA1 Problems with PHP

Source: Internet
Author: User
Tags printable characters sha1

  
   

I want these 20 characters instead of these binary things what's the easy way?

Make it clear: this function will output a binary length of 160bit (that is, 20byte), where each 8bit binary corresponds to one character of the ASCII code, so this 160bit binary corresponds to 20 characters, which I want is the 20 characters.

This issue has been closed because of a duplicate of an existing problem

Reply content:


  
   

I want these 20 characters instead of these binary things what's the easy way?

Make it clear: this function will output a binary length of 160bit (that is, 20byte), where each 8bit binary corresponds to one character of the ASCII code, so this 160bit binary corresponds to 20 characters, which I want is the 20 characters.

If I do not understand it correctly, it returns the "binary" is exactly what you want, you may fall into the trap of your own thoughts.

This is a simple program that outputs 20-character ASCII values in turn, and it's easy to see that many of the non-printable characters (values less than 32) and extended regions (values greater than 127) are used to encode the UTF8 and GB series encoded in the extended area, So in these environments, the single byte of the coded area is meaningless, which is garbled.

$x = sha1("Shanghai", true);for ($i = 0; $i < strlen($x); $i++) {    echo $x[$i] . "\t" . ord($x[$i]) . "\n";}

See also ASCII table: http://www.ascii-code.com/

Downstairs please ignore this answer

Don't know if this is the result you want:


  
   

参考: http://php.net/manual/en/function.sha1.php

  • Related Article

    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.