4
** mail_fetch/functions.php
6
** Copyright (c) 1999-2003 The SquirrelMail Project Team
7
** Licensed under the GNU GPL. For full terms see the file COPYING.
9
** Functions for the mailfetch plugin.
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>
15
** $Id: functions.php,v 1.6 2003/10/27 22:24:40 tassium Exp $
17
* @subpackage mail_fetch
21
* hex2bin - document me
23
function hex2bin( $data ) {
25
/* Original code by josh@superfork.com */
29
for( $i=0; $i < $len; $i += 2 ) {
30
$newdata .= pack( "C", hexdec( substr( $data, $i, 2) ) );
35
function mf_keyED( $txt ) {
39
if( !isset( $MF_TIT ) ) {
40
$MF_TIT = "MailFetch Secure for SquirrelMail 1.x";
43
$encrypt_key = md5( $MF_TIT );
46
for( $i = 0; $i < strlen( $txt ); $i++ ) {
47
if( $ctr == strlen( $encrypt_key ) ) $ctr=0;
48
$tmp.= substr( $txt, $i, 1 ) ^ substr( $encrypt_key, $ctr, 1 );
54
function encrypt( $txt ) {
56
srand( (double) microtime() * 1000000 );
57
$encrypt_key = md5( rand( 0, 32000 ) );
60
for( $i = 0; $i < strlen( $txt ); $i++ ) {
61
if ($ctr==strlen($encrypt_key)) $ctr=0;
62
$tmp.= substr($encrypt_key,$ctr,1) .
63
(substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1));
66
return bin2hex( mf_keyED( $tmp ) );
70
function decrypt( $txt ) {
72
$txt = mf_keyED( hex2bin( $txt ) );
74
for ( $i=0; $i < strlen( $txt ); $i++ ) {
75
$md5 = substr( $txt, $i, 1 );
77
$tmp.= ( substr( $txt, $i, 1 ) ^ $md5 );