Results 1 to 5 of 5

Thread: PHP Help

  1. #1
    xuxoxux's Avatar Reader BT Rep: +4
    Join Date
    Nov 2008
    Location
    127.0.0.1
    Posts
    226
    Ok, So I am making a matrix encryption script. I know it is not the most secure, but for what I need it, it is sufficient.

    The encryption part works just fine.....
    The problem is that I am needing to also later decrypt the message...lol.

    I dont know what is stopping this from working. Any help would be much appreciated.

    I know for a fact the math is 100% correct. There must be some little PHP error in there that I am just constantly missing.
    I am asking for syntax help.

    Script ( matrix.php ):

    PHP Code:
    <?php

    /*
    Author: Eric ( xuxoxux )
     */

    function matrix_encrypt($string) {

        
    $a rand(1,9);
        
    $b rand(1,9);
        
    $c rand(1,9);
        
    $d rand(1,9);
        
        if ( 
    strlen($string)&) {
            
    $string .= ".";
        }
        
        
    $str_array str_split($string);
        
        for ( 
    $i=0$i strlen($string); $i++ ) {
            
    $chr_array[$i] = ord$str_array[$i] );
        }
            
        for ( 
    $j=0$j strlen($string); ) {
            
    $str_A $chr_array[$j];
            
    $str_B $chr_array[$j+1];
            
            
    $end_array[$j] = ( $a $str_A ) + ( $b $str_B );
            
    $end_array[$j+1] =  ( $c $str_A ) + ( $d $str_B );
            
            
    $j += 2;
        }
            
        for ( 
    $k=0$k strlen($string); $k++ ) {
            
    $final .= $end_array[$k] . "-";
        }
        
        
    $key $a $b $c $d;
        
    $final .= $key;
        return 
    $final;
            
    }

    function 
    matrix_decrypt($string) {

        
    $enc_msg explode("-"$string);

        
    $len count($enc_msg);

        
    $key_s $enc_msg[$len-1];
        
    $key_str str_split($key_s);
        
        
    $key_a $key_str[0];
        
    $key_b $key_str[1];
        
    $key_c $key_str[2];
        
    $key_d $key_str[3];
        
        
    $Ia $key_d * (1/($key_a*$key_d $key_b*$key_c));
        
    $Ib $key_b * (-1/($key_a*$key_d $key_b*$key_c));
        
    $Ic $key_c * (-1/($key_a*$key_d $key_b*$key_c));
        
    $Id $key_a * (1/($key_a*$key_d $key_b*$key_c));
        
        
    array_pop($enc_msg);
        
        for ( 
    $j=0$j <= count($enc_msg); ) {
            
    $str_A $enc_msg[$j];
            
    $str_B $enc_msg[$j+1];
            
            
    $end_array[$j] = ( $Ia $str_A ) + ( $Ib $str_B );
            
    $end_array[$j+1] =  ( $Ic $str_A ) + ( $Id $str_B );
            
            
    $j += 2;
        }
            
        for ( 
    $i=0$i count($enc_msg); $i++ ) {
            
    $chrs .= chrround($end_array[$i]) );
        }
        
        return 
    $chrs;
        
    }

    $enc matrix_encrypt("Message");
    echo 
    $enc;
    echo 
    "<br><br>";
    echo 
    matrix_decrypt($enc);

    ?>
    Last edited by xuxoxux; 06-23-2009 at 12:10 AM.

  2. Internet, Programming and Graphics   -   #2
    tesco's Avatar woowoo
    Join Date
    Aug 2003
    Location
    Canadia
    Posts
    21,669
    umm, it works fine here.
    https://filesharingtalk.com/test2.php


    What is it you think is wrong with it?


    Only thing I noticed is that it adds a period (.) to the end of the message if it's an even number of characters, but doesn't remove it after decrypting...

    Anyway, this is some nice work you did. Not secure but defiantly good enough for some little projects.
    Mind if I hold onto it and maybe use it one day?

  3. Internet, Programming and Graphics   -   #3
    xuxoxux's Avatar Reader BT Rep: +4
    Join Date
    Nov 2008
    Location
    127.0.0.1
    Posts
    226
    Humm....I found my fix by doing the following:

    PHP Code:
    $key_a = (int)$key_str[0];
    $key_b = (int)$key_str[1];
    $key_c = (int)$key_str[2];
    $key_d = (int)$key_str[3]; 
    Oh well. To do the encryption, you needed to have an even number of letters of the message. So i decided it would be a period, though a space would be more appropriate.

    Go ahead and store/use/redistribute, as long as you give me a little credit.

  4. Internet, Programming and Graphics   -   #4
    tesco's Avatar woowoo
    Join Date
    Aug 2003
    Location
    Canadia
    Posts
    21,669
    I see.
    What version of PHP were you testing this on? Because it worked fine on this server, no errors, with php5.2

    Quote Originally Posted by xuxoxux View Post
    To do the encryption, you needed to have an even number of letters of the message. So i decided it would be a period, though a space would be more appropriate.
    You should program it to remove that added period.
    Last edited by tesco; 06-23-2009 at 10:47 PM. Reason: Automerged Doublepost

  5. Internet, Programming and Graphics   -   #5
    xuxoxux's Avatar Reader BT Rep: +4
    Join Date
    Nov 2008
    Location
    127.0.0.1
    Posts
    226
    PHP Code:
    PHP Version 5.2.9-
    I have already taken the period issue and solved it after thinking about a solution for an hour.....( I am a slow thinker. )

    PHP Code:
    <?php

    /**
    Author: Eric ( xuxoxux )
     */

    function matrix_encrypt($string) {

        
    $a rand(1,9);
        
    $b rand(1,9);
        
    $c rand(1,9);
        
    $d rand(1,9);
        
        if ( 
    strlen($string)&) {
            
    $string .= ".";
            
    $period 1;
        } else {
            
    $period 0;
        }
        
        
    $str_array str_split($string);
        
        for ( 
    $i=0$i strlen($string); $i++ ) {
            
    $chr_array[$i] = ord$str_array[$i] );
        }
        
        for ( 
    $j=0$j strlen($string); ) {
            
    $str_A $chr_array[$j];
            
    $str_B $chr_array[$j+1];
            
            
    $end_array[$j] = ( $a $str_A ) + ( $b $str_B );
            
    $end_array[$j+1] =  ( $c $str_A ) + ( $d $str_B );
            
            
    $j += 2;
        }
            
        for ( 
    $k=0$k strlen($string); $k++ ) {
            
    $final .= $end_array[$k] . "-";
        }
        
        
    $key $a $b $c $d $period;
        
    $final .= $key;
        return 
    $final;
            
    }

    function 
    matrix_decrypt($string) {

        
    $enc_msg explode("-"$string);

        
    $len count($enc_msg);

        
    $key_s $enc_msg[$len-1];
        
    $key_str str_split($key_s);
        
        
    $key_a = (int)$key_str[0];
        
    $key_b = (int)$key_str[1];
        
    $key_c = (int)$key_str[2];
        
    $key_d = (int)$key_str[3];
        
        
    $Ia $key_d * (1/($key_a*$key_d $key_b*$key_c));
        
    $Ib $key_b * (-1/($key_a*$key_d $key_b*$key_c));
        
    $Ic $key_c * (-1/($key_a*$key_d $key_b*$key_c));
        
    $Id $key_a * (1/($key_a*$key_d $key_b*$key_c));
        
        
    array_pop($enc_msg);
        
        for ( 
    $j=0$j <= count($enc_msg); ) {
            
    $str_A $enc_msg[$j];
            
    $str_B $enc_msg[$j+1];
            
            
    $end_array[$j] = ( $Ia $str_A ) + ( $Ib $str_B );
            
    $end_array[$j+1] =  ( $Ic $str_A ) + ( $Id $str_B );
            
            
    $j += 2;
        }
        
        for ( 
    $i=0$i count($enc_msg); $i++ ) {
            
    $chrs .= chrround($end_array[$i]) );
        }
        
        if ( (int)
    $key_str[4] == ) {
            
    $chrs substr($chrs0, -1);
        }
        
        return 
    $chrs;
        
    }

    $enc matrix_encrypt("Message!");
    echo 
    $enc;
    echo 
    "<br>";
    echo 
    matrix_decrypt($enc);

    echo 
    "<br><br>";

    $enc matrix_encrypt("Messages!");
    echo 
    $enc;
    echo 
    "<br>";
    echo 
    matrix_decrypt($enc);

    ?>
    I simply append a number that will flag whether there needs to be a period removed or not.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •