5 * Original code from LexZEUS <lexzeus@mifinca.com>
6 * and josh@superfork.com (extracted from php manual)
7 * Adapted for MailFetch by Philippe Mingo <mingo@rotedic.com>
12 function hex2bin( $data ) {
14 /* Original code by josh@superfork.com */
17 for( $i=0; $i < $len; $i +
= 2 ) {
18 $newdata .= pack( "C", hexdec( substr( $data, $i, 2) ) );
23 function mf_keyED( $txt ) {
27 if( !isset( $MF_TIT ) ) {
28 $MF_TIT = "MailFetch Secure for SquirrelMail 1.x";
31 $encrypt_key = md5( $MF_TIT );
34 for( $i = 0; $i < strlen( $txt ); $i++
) {
35 if( $ctr == strlen( $encrypt_key ) ) $ctr=0;
36 $tmp.= substr( $txt, $i, 1 ) ^
substr( $encrypt_key, $ctr, 1 );
42 function encrypt( $txt ) {
44 srand( (double) microtime() * 1000000 );
45 $encrypt_key = md5( rand( 0, 32000 ) );
48 for( $i = 0; $i < strlen( $txt ); $i++
) {
49 if ($ctr==strlen($encrypt_key)) $ctr=0;
50 $tmp.= substr($encrypt_key,$ctr,1) .
51 (substr($txt,$i,1) ^
substr($encrypt_key,$ctr,1));
54 return bin2hex( mf_keyED( $tmp ) );
58 function decrypt( $txt ) {
60 $txt = mf_keyED( hex2bin( $txt ) );
62 for ( $i=0; $i < strlen( $txt ); $i++
) {
63 $md5 = substr( $txt, $i, 1 );
65 $tmp.= ( substr( $txt, $i, 1 ) ^
$md5 );