Posted By

gdonald on 09/27/06


Tagged

poor mans crypt


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Cory


PHP poor man's crypt


 / Published in: PHP
 

  1. function encrypt( $string )
  2. {
  3. $key = 'BXcfTYewQ';
  4. $result = '';
  5. for( $i = 1; $i <= strlen( $string ); $i++ )
  6. {
  7. $char = substr( $string, $i - 1, 1 );
  8. $keychar = substr( $key, ( $i % strlen( $key ) ) - 1, 1 );
  9. $char = chr( ord( $char ) + ord( $keychar ) );
  10. $result .= $char;
  11. }
  12. return $result;
  13. }
  14.  
  15. function decrypt( $string )
  16. {
  17. $key = 'BXcfTYewQ';
  18. $result = '';
  19. for( $i = 1; $i <= strlen( $string ); $i++ )
  20. {
  21. $char = substr( $string, $i - 1, 1 );
  22. $keychar = substr( $key, ( $i % strlen( $key ) ) - 1, 1);
  23. $char = chr( ord( $char ) - ord( $keychar ) );
  24. $result .= $char;
  25. }
  26. return $result;
  27. }

Report this snippet  

You need to login to post a comment.