im trying to take an md5 string return and change it into an integer........i'm VERY new to all this type setting stuff, and ive tried everything i can think of. hexdec,dechex,bin2hex, none of that is what i'm looking for. i just want to turn a string into a hexadeciamal integer. can anyone plese help?
md5 to hex int
Actually, there isn't really any difference in the internal representation of data.
An integer is an integer... it may be output in decimal form, or hexadecimal form...
And actually, PHP doesn't keep track whether a value is a string or what:
$string = "2";
$string = $string + 2;
// will output 4
echo $string;
that said, try:
integer hexdec(string hexadecimal_number)
The hexdec function converts a string that represents a hexadecimal number into an integer. Preceeding the number with "0x" is optional.
Isn't that what you want?
waht i'm trying to do is look at each character of the md5 string and do something to it, then stick it together. this is my code; this is the first time i've ever tried this and im still relatively new to PHP although i'll probably understand what you say.
<?php
$s="This is a String";
$sa = md5($s);
for ($x=0;$x<32;$x++) {
echo $sa[$x];
}
echo "<br />";
$hash='';
for ($i=0;$i<32;$i++) {
$ss = $sa[$i];
$ss=hexdec($ss);
$ss+=3;
$n = dechex($ss);
$hash .= $n;
}
//$hash = "0x".$hash;
echo $hash;
?>
this doesn't give me any errors, but just outputs 1s and 0s generally. this is the output of that:
80b2959a8f7c38e52d7daa1660eafed7
b3e5c8cdb12af6b118510a10dd499311d121110a
any idea how or why this is happening?
I'm not sure what your 'do something to it' is, but you could try:
<?php
$s = "This is a String";
$sa = md5($s);
echo $sa . "<br />";
$hash = '';
/* Shift each hexadecimal digit by 3
Use modulo 16 so that it will not get out of range */
for ($i = 0; $i < 32; $i++) {
$num = hexdec($sa[$i]);
$num += 3;
$num %= 16;
$hash .= dechex($num);
}
//$hash = "0x".$hash;
echo $hash;
?>
Still not sure what you are trying to do.
However, you should be aware that you can copy strings just like integers.
$string2 = "hello world";
$string1 = $string2;
If you are trying to get the string back out of the MD5 value, it can't be done. MD5 encryption is one way only.
The mcrypt functions allow deciphering as well as encryption. MD5 is one way only.