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