phpDoc fixes
[squirrelmail.git] / plugins / mail_fetch / functions.php
CommitLineData
d622d38a 1<?php
2
4f51df66 3/**
4 * mail_fetch/functions.php
5 *
6 * Copyright (c) 1999-2005 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 * @version $Id$
16 * @package plugins
17 * @subpackage mail_fetch
18 */
d622d38a 19
4f51df66 20/**
21 * hex2bin - document me
22 */
23function hex2bin( $data ) {
d622d38a 24
4f51df66 25 /* Original code by josh@superfork.com */
d622d38a 26
4f51df66 27 $len = strlen($data);
28 $newdata = '';
29 for( $i=0; $i < $len; $i += 2 ) {
30 $newdata .= pack( "C", hexdec( substr( $data, $i, 2) ) );
d622d38a 31 }
4f51df66 32 return $newdata;
33}
d622d38a 34
4f51df66 35function mf_keyED( $txt ) {
d622d38a 36
4f51df66 37 global $MF_TIT;
d622d38a 38
4f51df66 39 if( !isset( $MF_TIT ) ) {
40 $MF_TIT = "MailFetch Secure for SquirrelMail 1.x";
41 }
d622d38a 42
4f51df66 43 $encrypt_key = md5( $MF_TIT );
44 $ctr = 0;
45 $tmp = "";
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 );
49 $ctr++;
d622d38a 50 }
4f51df66 51 return $tmp;
52}
d622d38a 53
4f51df66 54function encrypt( $txt ) {
d622d38a 55
4f51df66 56 srand( (double) microtime() * 1000000 );
57 $encrypt_key = md5( rand( 0, 32000 ) );
58 $ctr = 0;
59 $tmp = "";
60 for( $i = 0; $i < strlen( $txt ); $i++ ) {
d622d38a 61 if ($ctr==strlen($encrypt_key)) $ctr=0;
4f51df66 62 $tmp.= substr($encrypt_key,$ctr,1) .
63 (substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1));
d622d38a 64 $ctr++;
d622d38a 65 }
4f51df66 66 return bin2hex( mf_keyED( $tmp ) );
67
68}
d622d38a 69
4f51df66 70function decrypt( $txt ) {
d622d38a 71
4f51df66 72 $txt = mf_keyED( hex2bin( $txt ) );
73 $tmp = '';
74 for ( $i=0; $i < strlen( $txt ); $i++ ) {
75 $md5 = substr( $txt, $i, 1 );
76 $i++;
77 $tmp.= ( substr( $txt, $i, 1 ) ^ $md5 );
d622d38a 78 }
4f51df66 79 return $tmp;
80}
d622d38a 81
91e0dccc 82?>