Brandon_R Posted July 2, 2009 Share Posted July 2, 2009 Hello i am VERY new to PHP and would like to know how to convert ascii to hex and return the output in reversed order in lines of 4 while generating whats left with zeros. Lets say a person enters the word Hello World in a form and press submit. I would like for the php script to return the output hex values in reversed order (starting from left going right) skipping a line after every 4 while generating whats left (the counter) with zeros so it would be like this. 6c6c6548=lleh 6f57206f=oW 0 00646c72=dlr 0000000 Please Help Me Accomplish this. Thanks you. Link to comment https://forums.phpfreaks.com/topic/164529-how-to-convert-text-to-hex-and-return-the-output-reversed/ Share on other sites More sharing options...
rhodesa Posted July 2, 2009 Share Posted July 2, 2009 $string = "Hello World"; print implode("\n",array_map(create_function('$a','return str_pad(bin2hex(strrev($a)),8,0);'),array_pad(str_split($string,4),4,''))); Link to comment https://forums.phpfreaks.com/topic/164529-how-to-convert-text-to-hex-and-return-the-output-reversed/#findComment-867831 Share on other sites More sharing options...
Brandon_R Posted July 2, 2009 Author Share Posted July 2, 2009 Thank you sir I think i know why your title says PHP Guru But i have just a tiny problem. After the first 4 hexes it doesn't skip a line. It Just keeps gooing line this 6e616854 6f59206b 75000000 00000000 I think its because instead of using $string = "Hello World";, i changed it to $string = $_POST['ascii_inputs']; and wrote a form to make it user submittable. Is there any way i can get it to skip a line after the first 4 Hexes. Also it would be very nice if you could show me how to put text next to the hexes like. The First Line= 6c6c6548 The Second Line = 6f57206f The Third Line Equals= 00646c72 The Forth Line Equals = 0000000 Link to comment https://forums.phpfreaks.com/topic/164529-how-to-convert-text-to-hex-and-return-the-output-reversed/#findComment-867858 Share on other sites More sharing options...
rhodesa Posted July 2, 2009 Share Posted July 2, 2009 <pre> <?php $string = "Hello World and here is a longer string"; $n=0; foreach(str_split($string,16) as $chunk){ foreach(str_split($chunk,4) as $line){ printf("%-4s = %s\n",$line,str_pad(bin2hex(strrev($line)),8,0,STR_PAD_LEFT)); $n++; if(!($n%4)) print "\n"; } } print str_repeat(" = 00000000\n",4-($n%4)); ?> Link to comment https://forums.phpfreaks.com/topic/164529-how-to-convert-text-to-hex-and-return-the-output-reversed/#findComment-867878 Share on other sites More sharing options...
Brandon_R Posted July 2, 2009 Author Share Posted July 2, 2009 Thank You For All Your Help So Far. There's just 1 last thing i need with this script to be able to do. The ability to output the resulted hex on on arrary of addresses per say. Something alike this. [Ascii Name Here] - In This case It Will Be Hello World 0x00000004 0x6c6c6548 0x00000008 0x6f57206f 0x0000000C 0x00646c72 0x00000010 0x0000000 while still filling the remainder of whats left with zeros. Link to comment https://forums.phpfreaks.com/topic/164529-how-to-convert-text-to-hex-and-return-the-output-reversed/#findComment-867893 Share on other sites More sharing options...
rhodesa Posted July 2, 2009 Share Posted July 2, 2009 i don't understand Link to comment https://forums.phpfreaks.com/topic/164529-how-to-convert-text-to-hex-and-return-the-output-reversed/#findComment-867908 Share on other sites More sharing options...
Brandon_R Posted July 2, 2009 Author Share Posted July 2, 2009 I dont think im allowed to post links so i pmed you it. Link to comment https://forums.phpfreaks.com/topic/164529-how-to-convert-text-to-hex-and-return-the-output-reversed/#findComment-867937 Share on other sites More sharing options...
rhodesa Posted July 2, 2009 Share Posted July 2, 2009 So, you want the output to be like: 0x005A42AC 0x6C6C6548 0x005A42B0 0x6F57206F 0x005A42B4 0x00646C72 0x005A42B8 0x00000000 0x005A42BC 0x00000000 0x005A42C0 0x00000000 0x005A42C4 0x00000000 0x005A42C8 0x00000000 What is the first column? Link to comment https://forums.phpfreaks.com/topic/164529-how-to-convert-text-to-hex-and-return-the-output-reversed/#findComment-867947 Share on other sites More sharing options...
Brandon_R Posted July 2, 2009 Author Share Posted July 2, 2009 The first column is an array of addresses that the converted hex will be printed onto. Link to comment https://forums.phpfreaks.com/topic/164529-how-to-convert-text-to-hex-and-return-the-output-reversed/#findComment-867950 Share on other sites More sharing options...
rhodesa Posted July 2, 2009 Share Posted July 2, 2009 ok, where do these addresses come from? Link to comment https://forums.phpfreaks.com/topic/164529-how-to-convert-text-to-hex-and-return-the-output-reversed/#findComment-867956 Share on other sites More sharing options...
Brandon_R Posted July 2, 2009 Author Share Posted July 2, 2009 I choose them. It doesn't matter, it could be different if you like. Link to comment https://forums.phpfreaks.com/topic/164529-how-to-convert-text-to-hex-and-return-the-output-reversed/#findComment-867973 Share on other sites More sharing options...
Brandon_R Posted July 2, 2009 Author Share Posted July 2, 2009 All that matters is the hex gets outputted in reverse order to the left of them like so. If i type in hello World it should be outputted like this: 0x00010000 0x6c6c6548 0x00010004 0x6f57206f 0x00010008 0x00646c72 0x0001000C 0x00000000. You already showed me how to convert text to hex. TY Now i need to output the result of that conversion like stated above. Link to comment https://forums.phpfreaks.com/topic/164529-how-to-convert-text-to-hex-and-return-the-output-reversed/#findComment-868019 Share on other sites More sharing options...
Brandon_R Posted July 3, 2009 Author Share Posted July 3, 2009 Just checking to see if anyone has a solution for this. Link to comment https://forums.phpfreaks.com/topic/164529-how-to-convert-text-to-hex-and-return-the-output-reversed/#findComment-868207 Share on other sites More sharing options...
Brandon_R Posted July 3, 2009 Author Share Posted July 3, 2009 Still checking, read my provious posts. Link to comment https://forums.phpfreaks.com/topic/164529-how-to-convert-text-to-hex-and-return-the-output-reversed/#findComment-868588 Share on other sites More sharing options...
rhodesa Posted July 6, 2009 Share Posted July 6, 2009 <pre> <?php $key = 5915308; $key_incr = 4; $format = "0x%08s 0x%08s\n"; $string = "Hello World"; $n=0; foreach(str_split($string,16) as $chunk){ foreach(str_split($chunk,4) as $line){ printf($format,strtoupper(dechex($key)),strtoupper(bin2hex(strrev($line)))); $n++; $key += 4; } } //Fill in extra empty rows for($n = $n%4;$n && $n < 4;$n++){ printf($format,strtoupper(dechex($key)),"00000000"); $key += 4; } ?> Link to comment https://forums.phpfreaks.com/topic/164529-how-to-convert-text-to-hex-and-return-the-output-reversed/#findComment-869747 Share on other sites More sharing options...
Brandon_R Posted July 16, 2009 Author Share Posted July 16, 2009 OK guys just came back from vacation and im glad to see my post got answered by this wonderful user Im having a little problem returning the non hex version of the inputted value ie the value the user inputted on the top of the code. any help with that? Here is what im trying to do: on top of the outputted hex values is a line that shows what the hex means #[Original ascii here] 0x00000004 0x20202020 0x00000008 0x20202020 0x0000000c 0x20202020 0x00000010 0x20202020 I tried editing the format but it returned #[Original ascii here] 0x00000004 0x20202020 #[Original ascii here] 0x00000008 0x20202020 #[Original ascii here] 0x0000000c 0x20202020 #[Original ascii here] 0x00000010 0x20202020 Instead of #[Original ascii here] 0x00000004 0x20202020 0x00000008 0x20202020 0x0000000c 0x20202020 0x00000010 0x20202020 Please help me in fixing that Thank you all -Brandon_R Link to comment https://forums.phpfreaks.com/topic/164529-how-to-convert-text-to-hex-and-return-the-output-reversed/#findComment-876289 Share on other sites More sharing options...
Andy-H Posted July 16, 2009 Share Posted July 16, 2009 You found a tutorial on reverse engineering I take it... Link to comment https://forums.phpfreaks.com/topic/164529-how-to-convert-text-to-hex-and-return-the-output-reversed/#findComment-876290 Share on other sites More sharing options...
Brandon_R Posted July 16, 2009 Author Share Posted July 16, 2009 No i haven't sir, could you could take the time to point me to one please? Link to comment https://forums.phpfreaks.com/topic/164529-how-to-convert-text-to-hex-and-return-the-output-reversed/#findComment-876292 Share on other sites More sharing options...
Andy-H Posted July 16, 2009 Share Posted July 16, 2009 I sent the link in a PM. Link to comment https://forums.phpfreaks.com/topic/164529-how-to-convert-text-to-hex-and-return-the-output-reversed/#findComment-876294 Share on other sites More sharing options...
Brandon_R Posted July 16, 2009 Author Share Posted July 16, 2009 Thanks but still doesn't help me with the PHP aspect of it. Thanks For Trying Andy -Brandon_R Link to comment https://forums.phpfreaks.com/topic/164529-how-to-convert-text-to-hex-and-return-the-output-reversed/#findComment-876298 Share on other sites More sharing options...
Brandon_R Posted July 16, 2009 Author Share Posted July 16, 2009 Hello could someone change the code <pre> <?php $key = 5915308; $key_incr = 4; $format = "0x%08s 0x%08s\n"; $string = "Hello World"; $n=0; foreach(str_split($string,16) as $chunk){ foreach(str_split($chunk,4) as $line){ printf($format,strtoupper(dechex($key)),strtoupper(bin2hex(strrev($line)))); $n++; $key += 4; } } //Fill in extra empty rows for($n = $n%4;$n && $n < 4;$n++){ printf($format,strtoupper(dechex($key)),"00000000"); $key += 4; } ?> to use sprintf instead? Thank You Brandon_r Link to comment https://forums.phpfreaks.com/topic/164529-how-to-convert-text-to-hex-and-return-the-output-reversed/#findComment-876621 Share on other sites More sharing options...
rhodesa Posted July 16, 2009 Share Posted July 16, 2009 are you really asking that? <pre> <?php $key = 5915308; $key_incr = 4; $format = "0x%08s 0x%08s\n"; $string = "Hello World"; $output = "$string\n"; $n=0; foreach(str_split($string,16) as $chunk){ foreach(str_split($chunk,4) as $line){ $output .= sprintf($format,strtoupper(dechex($key)),strtoupper(bin2hex(strrev($line)))); $n++; $key += 4; } } //Fill in extra empty rows for($n = $n%4;$n && $n < 4;$n++){ $output .= sprintf($format,strtoupper(dechex($key)),"00000000"); $key += 4; } ?> Link to comment https://forums.phpfreaks.com/topic/164529-how-to-convert-text-to-hex-and-return-the-output-reversed/#findComment-876629 Share on other sites More sharing options...
Brandon_R Posted July 16, 2009 Author Share Posted July 16, 2009 Once again thank you i almost had it Has = instead of .= -Brandon_R Link to comment https://forums.phpfreaks.com/topic/164529-how-to-convert-text-to-hex-and-return-the-output-reversed/#findComment-876677 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.