functions.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. ** mail_fetch/functions.php
  4. **
  5. ** Copyright (c) 1999-2002 The SquirrelMail Project Team
  6. ** Licensed under the GNU GPL. For full terms see the file COPYING.
  7. **
  8. ** Functions for the mailfetch plugin.
  9. **
  10. ** Original code from LexZEUS <lexzeus@mifinca.com>
  11. ** and josh@superfork.com (extracted from php manual)
  12. ** Adapted for MailFetch by Philippe Mingo <mingo@rotedic.com>
  13. **
  14. ** $Id$
  15. **/
  16. function hex2bin( $data ) {
  17. /* Original code by josh@superfork.com */
  18. $len = strlen($data);
  19. $newdata = '';
  20. for( $i=0; $i < $len; $i += 2 ) {
  21. $newdata .= pack( "C", hexdec( substr( $data, $i, 2) ) );
  22. }
  23. return $newdata;
  24. }
  25. function mf_keyED( $txt ) {
  26. global $MF_TIT;
  27. if( !isset( $MF_TIT ) ) {
  28. $MF_TIT = "MailFetch Secure for SquirrelMail 1.x";
  29. }
  30. $encrypt_key = md5( $MF_TIT );
  31. $ctr = 0;
  32. $tmp = "";
  33. for( $i = 0; $i < strlen( $txt ); $i++ ) {
  34. if( $ctr == strlen( $encrypt_key ) ) $ctr=0;
  35. $tmp.= substr( $txt, $i, 1 ) ^ substr( $encrypt_key, $ctr, 1 );
  36. $ctr++;
  37. }
  38. return $tmp;
  39. }
  40. function encrypt( $txt ) {
  41. srand( (double) microtime() * 1000000 );
  42. $encrypt_key = md5( rand( 0, 32000 ) );
  43. $ctr = 0;
  44. $tmp = "";
  45. for( $i = 0; $i < strlen( $txt ); $i++ ) {
  46. if ($ctr==strlen($encrypt_key)) $ctr=0;
  47. $tmp.= substr($encrypt_key,$ctr,1) .
  48. (substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1));
  49. $ctr++;
  50. }
  51. return bin2hex( mf_keyED( $tmp ) );
  52. }
  53. function decrypt( $txt ) {
  54. $txt = mf_keyED( hex2bin( $txt ) );
  55. $tmp = '';
  56. for ( $i=0; $i < strlen( $txt ); $i++ ) {
  57. $md5 = substr( $txt, $i, 1 );
  58. $i++;
  59. $tmp.= ( substr( $txt, $i, 1 ) ^ $md5 );
  60. }
  61. return $tmp;
  62. }
  63. ?>