File: functions.php

package info (click to toggle)
squirrelmail 2%3A1.4.4-11
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,496 kB
  • ctags: 6,546
  • sloc: php: 32,906; perl: 3,049; sh: 166; ansic: 122; makefile: 83
file content (77 lines) | stat: -rw-r--r-- 2,048 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php

   /**
    **  mail_fetch/functions.php
    **
    **  Copyright (c) 1999-2005 The SquirrelMail Project Team
    **  Licensed under the GNU GPL. For full terms see the file COPYING.
    **
    **  Functions for the mailfetch plugin.
    **
    **  Original code from LexZEUS <lexzeus@mifinca.com>
    **  and josh@superfork.com (extracted from php manual)
    **  Adapted for MailFetch by Philippe Mingo <mingo@rotedic.com>
    **
    **  $Id: functions.php,v 1.5.2.2 2004/12/27 15:03:58 kink Exp $
    **/

    function hex2bin( $data ) {

        /* Original code by josh@superfork.com */

        $len = strlen($data);
        $newdata = '';
        for( $i=0; $i < $len; $i += 2 ) {
            $newdata .= pack( "C", hexdec( substr( $data, $i, 2) ) );
        }
        return $newdata;
    }

    function mf_keyED( $txt ) {

        global $MF_TIT;

        if( !isset( $MF_TIT ) ) {
            $MF_TIT = "MailFetch Secure for SquirrelMail 1.x";
        }

        $encrypt_key = md5( $MF_TIT );
        $ctr = 0;
        $tmp = "";
        for( $i = 0; $i < strlen( $txt ); $i++ ) {
            if( $ctr == strlen( $encrypt_key ) ) $ctr=0;
            $tmp.= substr( $txt, $i, 1 ) ^ substr( $encrypt_key, $ctr, 1 );
            $ctr++;
        }
        return $tmp;
    }

    function encrypt( $txt ) {

        srand( (double) microtime() * 1000000 );
        $encrypt_key = md5( rand( 0, 32000 ) );
        $ctr = 0;
        $tmp = "";
        for( $i = 0; $i < strlen( $txt ); $i++ ) {
        if ($ctr==strlen($encrypt_key)) $ctr=0;
            $tmp.= substr($encrypt_key,$ctr,1) .
                (substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1));
        $ctr++;
        }
        return bin2hex( mf_keyED( $tmp ) );

    }

    function decrypt( $txt ) {

        $txt = mf_keyED( hex2bin( $txt ) );
        $tmp = '';
        for ( $i=0; $i < strlen( $txt ); $i++ ) {
            $md5 = substr( $txt, $i, 1 );
            $i++;
            $tmp.= ( substr( $txt, $i, 1 ) ^ $md5 );
        }
        return $tmp;
    }

?>