encrypt/decrypt

Discussion in 'PHP' started by grandpa, Feb 13, 2007.

  1. #1
    what the best way to encrypt alphanumeric string to another alphanumeric (no unique char)? and also decryptable...

    thx
     
    grandpa, Feb 13, 2007 IP
  2. Icheb

    Icheb Peon

    Messages:
    1,092
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If you don't have to decrypt it you can just use md5() or something like it, for example for passwords.
     
    Icheb, Feb 13, 2007 IP
  3. grandpa

    grandpa Active Member

    Messages:
    185
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    75
    #3
    i need decryptable one, thx
     
    grandpa, Feb 13, 2007 IP
  4. Icheb

    Icheb Peon

    Messages:
    1,092
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You could use str_rot13(). :p
     
    Icheb, Feb 13, 2007 IP
  5. Choller

    Choller Peon

    Messages:
    388
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    
    /**
     * Encrypt/decrypt url
     * Encrypts and decrypts url
     * Usage example: - 'index.php?A='.encrypt_url("somedata")
     *                - decrypt_url($GET['A'])
     */
    function encrypt_url($string) {
            $key = "123abc"; //preset key to use on all encrypt and decrypts.
            $result = '';
       for($i=0; $i<strlen($string); $i++) {
         $char = substr($string, $i, 1);
         $keychar = substr($key, ($i % strlen($key))-1, 1);
         $char = chr(ord($char)+ord($keychar));
         $result.=$char;
       }
       return urlencode(base64_encode($result));
    }
    function decrypt_url($string) {
            $key = "123abc";
            $result = '';
            $string = base64_decode(urldecode($string));
       for($i=0; $i<strlen($string); $i++) {
         $char = substr($string, $i, 1);
         $keychar = substr($key, ($i % strlen($key))-1, 1);
         $char = chr(ord($char)-ord($keychar));
         $result.=$char;
       }
       return $result;
    }
    
    PHP:
     
    Choller, Feb 13, 2007 IP
  6. designcode

    designcode Well-Known Member

    Messages:
    738
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    118
    #6
    I just currently installed mcrypt library for a project, Nice one, very hard to decrypt data unless you know the key. But encrypted value has loads of special or must say very special characters :D
     
    designcode, Feb 14, 2007 IP
  7. grandpa

    grandpa Active Member

    Messages:
    185
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    75
    #7
    @Choller
    THX!!
    this is exactly what I need!
    and its true i use it for url (html get) purpose
     
    grandpa, Feb 14, 2007 IP