I have searched forums for this and didn't find any answer.

I want an encryption algorithm with the following requirements:

1) It can be decrypted and should have the key feature like mcrypt function.

2) I also want that if the string to be encrypted is 9 chars long then encrypted string should also be 9 chars long.

3) String input should result in string output and integer inputs should result in integer outputs.

MD5 and mcrypt both doesn't support length feature.

Following is the link that meet most of my requierments but not very secure.

http://www.hansanderson.com/php/crypto/

Regards,

Atiq

    As far as I know, there are no cryptographically secure algorithms that meet your criteria.

      it's your requirements that make it insecure. encrypting to the same length, and alpha to alpha, numeric to numeric, mean that any decent hacker would be able to break it in minutes. it's a bit like asking for a padlock with a 10 digit code to open it - but making the lock out of paper.

        Actually, it might be possible with a specially designed one time pad cryptosystem, but a one time pad doesnt fit the key criterion.

          Originally posted by Atiq
          Following is the link that meet most of my requierments but not very secure.

          http://www.hansanderson.com/php/crypto/

          What makes you think thats insecure? Polyalphabetic transposition cyphers (which is what that does) will defeat 95% of people. What are you doing that requires more than that?

            How about the crypto system I use.

            It turns:

            account

            into

            ½Ð<žÈ

            and has a key like you require.

            🙂

              Originally posted by Kudose
              How about the crypto system I use.

              It turns:

              account

              into

              ½Ð<žÈ

              and has a key like you require.

              🙂

              What is that system please explain. It looks like it has the length feature.
              There are 7 chars in account and 7 chars in the encrypted string.
              I think this will help me.

              Thanks for the help to all of you guys!

                Aes_encrypt & Aes_decrypt work well for me in MySQL if that helps you any.

                  functions.inc.php

                  <?
                  function bytexor($a,$b,$l)
                    {
                     $c="";
                     for($i=0;$i<$l;$i++) {
                       $c.=$a{$i}^$b{$i};
                     }
                     return($c);
                    }
                  
                    function binmd5($val)
                    {
                     return(pack("H*",md5($val)));
                    }
                  
                  function decrypt_md5($msg,$heslo)
                    {
                     $key=$heslo;$sifra="";
                     $key1=binmd5($key);
                     while($msg) {
                       $m=substr($msg,0,16);
                       $msg=substr($msg,16);
                       $sifra.=$m=bytexor($m,$key1,16);
                       $key1=binmd5($key.$key1.$m);
                     }
                     echo "\n";
                     return($sifra);
                    }
                  
                    function crypt_md5($msg,$heslo)
                    {
                     $key=$heslo;$sifra="";
                     $key1=binmd5($key);
                     while($msg) {
                       $m=substr($msg,0,16);
                       $msg=substr($msg,16);
                       $sifra.=bytexor($m,$key1,16);
                       $key1=binmd5($key.$key1.$m);
                     }
                     echo "\n";
                     return($sifra);
                    }
                    $key = "the is the key to the password";
                  

                  you encrypt and decrypt like this

                  $password = crypt_md5($password, $key);
                  $password = decrypt_md5($password, $key);

                  Hope that helps.

                    Write a Reply...