functions.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. ** mail_fetch/functions.php
  4. **
  5. ** Copyright (c) 1999-2004 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. * @package plugins
  16. * @subpackage mail_fetch
  17. **/
  18. /**
  19. * hex2bin - document me
  20. */
  21. function hex2bin( $data ) {
  22. /* Original code by josh@superfork.com */
  23. $len = strlen($data);
  24. $newdata = '';
  25. for( $i=0; $i < $len; $i += 2 ) {
  26. $newdata .= pack( "C", hexdec( substr( $data, $i, 2) ) );
  27. }
  28. return $newdata;
  29. }
  30. function mf_keyED( $txt ) {
  31. global $MF_TIT;
  32. if( !isset( $MF_TIT ) ) {
  33. $MF_TIT = "MailFetch Secure for SquirrelMail 1.x";
  34. }
  35. $encrypt_key = md5( $MF_TIT );
  36. $ctr = 0;
  37. $tmp = "";
  38. for( $i = 0; $i < strlen( $txt ); $i++ ) {
  39. if( $ctr == strlen( $encrypt_key ) ) $ctr=0;
  40. $tmp.= substr( $txt, $i, 1 ) ^ substr( $encrypt_key, $ctr, 1 );
  41. $ctr++;
  42. }
  43. return $tmp;
  44. }
  45. function encrypt( $txt ) {
  46. srand( (double) microtime() * 1000000 );
  47. $encrypt_key = md5( rand( 0, 32000 ) );
  48. $ctr = 0;
  49. $tmp = "";
  50. for( $i = 0; $i < strlen( $txt ); $i++ ) {
  51. if ($ctr==strlen($encrypt_key)) $ctr=0;
  52. $tmp.= substr($encrypt_key,$ctr,1) .
  53. (substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1));
  54. $ctr++;
  55. }
  56. return bin2hex( mf_keyED( $tmp ) );
  57. }
  58. function decrypt( $txt ) {
  59. $txt = mf_keyED( hex2bin( $txt ) );
  60. $tmp = '';
  61. for ( $i=0; $i < strlen( $txt ); $i++ ) {
  62. $md5 = substr( $txt, $i, 1 );
  63. $i++;
  64. $tmp.= ( substr( $txt, $i, 1 ) ^ $md5 );
  65. }
  66. return $tmp;
  67. }
  68. ?>