Support Forums
Encode/Decode - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: PHP The Hypertext Preprocessor (https://www.supportforums.net/forumdisplay.php?fid=21)
+---- Thread: Encode/Decode (/showthread.php?tid=23324)



Encode/Decode - HF~Legend - 11-18-2011

PHP Code:
/**
     * Encode
     *
     * Encodes the message string using bitwise XOR encoding.
     * The key is combined with a random hash, and then it
     * too gets converted using XOR. The whole thing is then run
     * through mcrypt (if supported) using the randomized key.
     * The end result is a double-encrypted message string
     * that is randomized with each call to this function,
     * even if the supplied message and key are the same.
     *
     * @access    public
     * @param    string    the string to encode
     * @param    string    the key
     * @return    string
     */
    
function encode($string$key '')
    {
        
$key $this->get_key($key);

        if (
$this->_mcrypt_exists === TRUE)
        {
            
$enc $this->mcrypt_encode($string$key);
        }
        else
        {
            
$enc $this->_xor_encode($string$key);
        }

        return 
base64_encode($enc);
    }

    
// --------------------------------------------------------------------

    /**
     * Decode
     *
     * Reverses the above process
     *
     * @access    public
     * @param    string
     * @param    string
     * @return    string
     */
    
function decode($string$key '')
    {
        
$key $this->get_key($key);

        if (
preg_match('/[^a-zA-Z0-9\/\+=]/'$string))
        {
            return 
FALSE;
        }

        
$dec base64_decode($string);

        if (
$this->_mcrypt_exists === TRUE)
        {
            if ((
$dec $this->mcrypt_decode($dec$key)) === FALSE)
            {
                return 
FALSE;
            }
        }
        else
        {
            
$dec $this->_xor_decode($dec$key);
        }

        return 
$dec;
    } 



RE: Encode/Decode - Benjamin Franklin - 12-06-2011

Why would you post incomplete code? You are using $this and your code is not even within a class.
Did you copy and paste these?