0

hello everyone
im working on my masters thesis project, i need a help on how to convert md5 password into binary andthen generate a randomly number, then calculate there exclusive OR, i mean that suppose i have attechd the code in this msg. but the PROBLEM here is that it not showing the correct result, it is always showing TRUE value in $calculate variable.

<?php
 // function for converting md5 user password into binary
 function binary_convert($md5_1){

    $hexadecimal_number=$md5_1;    
    $hexadecimal_to_convert_to_binary_testable = strtolower($hexadecimal_number);   
    $length_of_text_to_convert_to_binary = strlen($hexadecimal_number);
    $results_of_hexadecimal_to_binary_conversion = "";

    for($i = 0; $i < $length_of_text_to_convert_to_binary; $i++)
    {
        $current_char_of_hexadecimal_for_conversion = $hexadecimal_to_convert_to_binary_testable[$i];

        switch($current_char_of_hexadecimal_for_conversion)
        {
            case '0':
                $results_of_hexadecimal_to_binary_conversion .= "0000";
                break;

            case '1':
                $results_of_hexadecimal_to_binary_conversion .= "0001";
                break;

            case '2':
                $results_of_hexadecimal_to_binary_conversion .= "0010";
                break;

            case '3':
                $results_of_hexadecimal_to_binary_conversion .= "0011";
                break;

            case '4':
                $results_of_hexadecimal_to_binary_conversion .= "0100";
                break;

            case '5':
                $results_of_hexadecimal_to_binary_conversion .= "0101";
                break;

            case '6':
                $results_of_hexadecimal_to_binary_conversion .= "0110";
                break;

            case '7':
                $results_of_hexadecimal_to_binary_conversion .= "0111";
                break;

            case '8':
                $results_of_hexadecimal_to_binary_conversion .= "1000";
                break;

            case '9':
                $results_of_hexadecimal_to_binary_conversion .= "1001";
                break;

            case 'a':
                $results_of_hexadecimal_to_binary_conversion .= "1010";
                break;

            case 'b':
                $results_of_hexadecimal_to_binary_conversion .= "1011";
                break;

            case 'c':
                $results_of_hexadecimal_to_binary_conversion .= "1100";
                break;

            case 'd':
                $results_of_hexadecimal_to_binary_conversion .= "1101";
                break;

            case 'e':
                $results_of_hexadecimal_to_binary_conversion .= "1110";
                break;

            case 'f':
                $results_of_hexadecimal_to_binary_conversion .= "1111";
                break;
        }
    }   

     return $results_of_hexadecimal_to_binary_conversion;
     }

$md5_1=md5($_POST['user_pass']); //encrypted md5 user password,which is coming from user form
$random_num = rand(0,100); //randomly generated number between 0-100
$converted_md5_binary = binary_convert($md5_1); //calling function here, to convert MD5 user password into binary 
$converted_random_num =decbin($random_num); //converted random number into binary   
$calculate=$converted_random_num^$converted_md5_binary ;

?>
4
Contributors
11
Replies
59
Views
2 Years
Discussion Span
Last Post by cereal
Featured Replies
  • 1
    diafol 3,669   2 Years Ago

    gmp may need to be installed. Read More

  • 1
    cereal 1,419   2 Years Ago

    Check if in your system there is the **php_gmp.dll** file, then edit php.ini and append: extension=php_gmp.dll Restart Apache and it should work. Check the comments for more information: * http://php.net/manual/en/gmp.installation.php Otherwise, if you cannot find the dll file, you can use [Math_BigInteger](http://pear.php.net/package/Math_BigInteger), you can install it by using pear or … Read More

0

Maybe:

$xor1 = gmp_init(md5('test'), 16);
$xor2 = gmp_init(decbin(rand(0, 100)), 2);
$xor3 = gmp_xor($xor1, $xor2);

echo gmp_strval($xor3);

?

0

IMHO, the hashed user_pass is not necessarily be the subject of un-needed iteration.

if

$md5_1=md5($_POST['user_pass']);

is equal to 'password', then the hashed password is now equal to

$md5_1 = '5f4dcc3b5aa765d61d8327deb882cf99';

and this

print_r(str_split($md5_1));

will deliver $md5_1 as an array.

Array ( [0] => 5 [1] => f [2] => 4 [3] => d [4] => c [5] => c [6] => 3 [7] => b [8] => 5 [9] => a [10] => a [11] => 7 [12] => 6 [13] => 5 [14] => d [15] => 6 [16] => 1 [17] => d [18] => 8 [19] => 3 [20] => 2 [21] => 7 [22] => d [23] => e [24] => b [25] => 8 [26] => 8 [27] => 2 [28] => c [29] => f [30] => 9 [31] => 9 ) 

just apply minor manipulation to convert those items into whatever format you want and you should be done.

Hint: Look for the array functions here. That should help you in the conversion to binary and I am sure it is a lot faster than what you have using switch statement.

0

This is what I meant by without iteration on conversion. I used foreach loop to prove successful conversion..

<?php 

$pass = '5f4dcc3b5aa765d61d8327deb882cf99';

print_r(str_split($pass));

$replacements = array(

  '0'=> "0000", '1' => "0001", '2' => "0010", '3' => "0011", '4' => "0100", '5' => "0101", '6'=> "0110", '7' => "0111",
  '8'=> "1000",'9' => "1001", 'a' => "1010", 'b' => "1011", 'c' => "1100", 'd' => "1101", 'e' => "1110", 'f' => "1111" );

$x = (str_replace(array_keys($replacements), $replacements, $pass));

echo '<br/> this is the converted md5 password : '. $x .'<br/>';

/*
* we can further split the converted md5 password as proof
*/
echo 'below are the split converted md5 as proof <br/>';

$x_array = (str_split($x,4));

foreach($x_array as $value){

        echo $value.'<br/>';

}

the rest is all up to you. Good luck on your Master thesis.

0

Fatal error: Call to undefined function gmp_init() in C:\xampp\htdocs\test\test.1.php on line 14
its giving this error

0

sir,veedeoo
thanku, but my problme is still there,can u please give me any simple expamle of that, to get XOR of md5 and randmly numbr

1

Check if in your system there is the php_gmp.dll file, then edit php.ini and append:

extension=php_gmp.dll

Restart Apache and it should work. Check the comments for more information:

Otherwise, if you cannot find the dll file, you can use Math_BigInteger, you can install it by using pear or composer:

pear install Math_BigInteger
composer require pear/math_biginteger

In both cases you need to install the pear client or the composer client:

There's also BC Math which sometimes is shipped with the PHP core installation, but it depends a lot on the PHP version in use, I'm not sure about Windows situation. All these libraries treats the numbers as strings, which gives you the ability to not be limited by the CPU architecture. Math_BigInteger, when available, will use GMP or BC_Math to speed up the execution.

Example:

<?php

    require_once '/path/vendor/autoload.php';

    $a = new Math_BigInteger(rand(0,100), 10);
    $b = new Math_BigInteger(md5('test'), 16);

    echo $a->bitwise_xor($b);

By the way, I'm not sure this example is what you need, I'm just replicating my first example ^_^'

edit

I was forgetting, Math_BigInteger is also available on GitHub:

Just donwload library and include it in your script. This does not require for you to install pear or composer... bye!

Edited by cereal

Votes + Comments
great post!
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.