Alternative application of phpmd5 encryption

Source: Internet
Author: User
Alternative application of phpmd5 encryption

  1. // Iterative algorithm
  2. Function md5_1_1 ($ data, $ times = 32)
  3. {
  4. // Use MD5 repeatedly
  5. For ($ I = 0; $ I <$ times; $ I ++ ){
  6. $ Data = md5 ($ data );
  7. }
  8. Return $ data;
  9. }
  10. // Recursive algorithm
  11. Function md5_1_2 ($ data, $ times = 32)
  12. {
  13. If ($ times> 0 ){
  14. $ Data = md5 ($ data );
  15. $ Times --;
  16. Return md5_1_2 ($ data, $ times); // implement recursion
  17. } Else {
  18. Return $ data;
  19. }
  20. }
  21. ?>

Transformation 2:Ciphertext segmentation MD5

  1. // Divide the ciphertext into two segments, each of which contains 16 characters
  2. Function md5_2_1 ($ data)
  3. {
  4. // Encrypt the password into a 32-character ciphertext
  5. $ Data = md5 ($ data );
  6. // Split the password into two segments
  7. $ Left = substr ($ data, 0, 16 );
  8. $ Right = substr ($ data, 16, 16 );
  9. // Encrypt the data separately before merging.
  10. $ Data = md5 ($ left). md5 ($ right );
  11. // Finally, the long string is re-encrypted to a 32-character ciphertext.
  12. Return md5 ($ data );
  13. }
  14. // Divide the ciphertext into 32 segments, each of which contains 1 character
  15. Function md5_2_2 ($ data)
  16. {
  17. $ Data = md5 ($ data );
  18. // Cyclically intercept each character in the ciphertext and encrypt and connect it
  19. For ($ I = 0; $ I <32; $ I ++ ){
  20. $ Data. = md5 ($ data {$ I });
  21. }
  22. // At this time, $ data is 1024 characters in length, and an MD5 operation is performed again.
  23. Return md5 ($ data );
  24. }
  25. ?>

Transformation 3:Append string interference

  1. // Append the string to the end of the original data
  2. Function md5_3_1 ($ data, $ append)
  3. {
  4. Return md5 ($ data. $ append );
  5. }
  6. // Append the string to the header of the original data
  7. Function md5_3_2 ($ data, $ append)
  8. {
  9. Return md5 ($ append. $ data );
  10. }
  11. // Append the string to the beginning and end of the original data
  12. Function md5_3_3 ($ data, $ append)
  13. {
  14. Return md5 ($ append. $ data. $ append );
  15. }
  16. ?>

Transformation 4:Case-sensitive conversion interferenceSince all English letters in the ciphertext returned by the md5 () function provided by PHP are in lower case, we can convert all of them into upper case and then perform an MD5 operation.

  1. Function md5_4 ($ data)
  2. {
  3. // Obtain the ciphertext of the password first
  4. $ Data = md5 ($ data );
  5. // Convert all the English letters in the ciphertext into uppercase letters.
  6. $ Data = strtotime ($ data );
  7. // Perform the MD5 operation again and return the result
  8. Return md5 ($ data );
  9. }
  10. ?>

Transformation 5:String order interferenceAfter the sequence of the ciphertext string after the MD5 operation is adjusted, the MD5 operation is performed again.

  1. Function md5_5 ($ data)
  2. {
  3. // Obtain the ciphertext of the data
  4. $ Data = md5 ($ data );
  5. // Re-convert the character sequence of the ciphertext string
  6. $ Data = strrev ($ data );
  7. // Perform the MD5 operation again and return the result
  8. Return md5 ($ data );
  9. }
  10. ?>

Using the php md5 () function can reduce security risks by making more efforts to encrypt user information.

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.