functions.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. for( $i=0; $i < $len; $i += 2 ) {
  20. $newdata .= pack( "C", hexdec( substr( $data, $i, 2) ) );
  21. }
  22. return $newdata;
  23. }
  24. function mf_keyED( $txt ) {
  25. global $MF_TIT;
  26. if( !isset( $MF_TIT ) ) {
  27. $MF_TIT = "MailFetch Secure for SquirrelMail 1.x";
  28. }
  29. $encrypt_key = md5( $MF_TIT );
  30. $ctr = 0;
  31. $tmp = "";
  32. for( $i = 0; $i < strlen( $txt ); $i++ ) {
  33. if( $ctr == strlen( $encrypt_key ) ) $ctr=0;
  34. $tmp.= substr( $txt, $i, 1 ) ^ substr( $encrypt_key, $ctr, 1 );
  35. $ctr++;
  36. }
  37. return $tmp;
  38. }
  39. function encrypt( $txt ) {
  40. srand( (double) microtime() * 1000000 );
  41. $encrypt_key = md5( rand( 0, 32000 ) );
  42. $ctr = 0;
  43. $tmp = "";
  44. for( $i = 0; $i < strlen( $txt ); $i++ ) {
  45. if ($ctr==strlen($encrypt_key)) $ctr=0;
  46. $tmp.= substr($encrypt_key,$ctr,1) .
  47. (substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1));
  48. $ctr++;
  49. }
  50. return bin2hex( mf_keyED( $tmp ) );
  51. }
  52. function decrypt( $txt ) {
  53. $txt = mf_keyED( hex2bin( $txt ) );
  54. $tmp = '';
  55. for ( $i=0; $i < strlen( $txt ); $i++ ) {
  56. $md5 = substr( $txt, $i, 1 );
  57. $i++;
  58. $tmp.= ( substr( $txt, $i, 1 ) ^ $md5 );
  59. }
  60. return $tmp;
  61. }
  62. ?>