EG Information
Training Missions
Knowledge Bank
|
|
Enigma Group's Code Bank
Binary-Ascii-HEX-Plain text converterBy: Link- - Date Submitted: 2008-09-26 10:22:23 <?php /** * Code created by Link- * * Email your questions-comments to: Link.random@gmail.com * * * * Simple and easy... Although HEX conversion is not created yet * It will be included in the next version. * * Version 1.01 **/ ?> <html> <head> <meta http-equiv="Content-Language" content="en-us"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>Binary-ASCII-Hex-Octal Converter</title> </head> <body> <table border="1" width="53%" id="table1"> <tr> <td colspan="3"><font face="Verdana" size="2">● Enter the code you want to convert and click calculate:</font></td> </tr> <tr> <td width="202"><font face="Verdana" size="1">Output delimiter:</font></td> <td width="357"><form action="bahoc.php?action=convert" method="post"> <font size="1" face="Verdana"> <input type="text" name="delimiter_box" size="34" style="border: 1px solid #000000; font-family:Verdana; font-size:8pt"></font></td> <td><font face="Verdana" size="1">[ex: , | ' ]</font></td> </tr> <tr> <td width="202"> <select size="1" name="code_type" style="font-family: Verdana; font-size: 8pt; border: 1px solid #000000"> <option value="CT1">Binary</option> <option value="CT2">ASCII</option> <option value="CT3">Plain Text</option> <option value="CT4">Hex</option> </select></td> <td width="357"> <textarea rows="6" name="original_code" cols="42" style="border: 1px solid #000000"></textarea></td> <td> <input type="submit" value="Calculate" name="B1" style="color: #FFFFFF; font-family: Verdana; font-size: 8pt; border: 1px solid #000000; background-color: #282828"></td></form> </tr> <tr> <td colspan="3"><hr size="1"></td> </tr> <tr> <td width="202"><font face="Verdana" size="2">Converted code:</font></td> <td colspan="2"> <?php //Binary conversions hex-octal-ascii-text //Binary Validation rule function validate_binary($input) { $input = str_split($input); for ($i=0;$i<count($input);$i++) { if ($input[$i] != "1" && $input[$i] != "0" && $input[$i] != chr(32)) { return False; break; } else { continue; } } return True; } //END //Convert binary to hex-ascii-text function binary_to_all($input, $delimiter) { if (validate_binary($input)) { //Remove spaces and other unwanted chars $input = trim($input); //explode the string into array, delimiter is a space $orig_exp = explode(" ",$input); //recombine the string without spaces for ($i=0; $i<count($orig_exp); $i++) { $input2 .= $orig_exp[$i]; } //Split the binary code to a set of 8 bits to convert $orig_exp2 = str_split($input2, 8); for ($i=0; $i<count($orig_exp2); $i++) { $hex_string .= $delimiter . base_convert($orig_exp2[$i],2,16); $ascii_string .= $delimiter . base_convert($orig_exp2[$i],2,10); if ($orig_exp2[$i] == "00000000") { $text_string .= $delimiter . chr(32); } else { $text_string .= $delimiter . chr(base_convert($orig_exp2[$i],2,10)); } } echo "HEX :: " . $hex_string . "<br>"; echo "ASCII :: " . $ascii_string . "<br>"; echo "Plain-Text :: " . $text_string . "<br>"; } else { echo "This is an invalid binary number!"; } } //END //Valid ASCII code doesn't contain letters, chars, etc.. function validate_ascii($input) { $input = str_split($input); for ($i=0; $i<count ($input); $i++) { } } } //END //Convert ASCII to hex-binary-text function ascii_to_all($input, $delimiter) { if (validate_ascii ($input)) { //Remove spaces and other unwanted chars //Explode into arrays //Do the conversion for ($i=0; $i<count ($orig_exp); $i++) { $hex_string .= $delimiter . base_convert($orig_exp[$i],10,16); //Make sure that the binary is made of 8 chars not 7! $binary_string .= $delimiter . base_convert($orig_exp[$i],10,2); } $text_string .= $delimiter . chr($orig_exp[$i]); } echo "HEX :: " . $hex_string . "<br>"; echo "Binary :: " . $binary_string . "<br>"; echo "Plain-Text :: " . $text_string . "<br>"; } else { echo "This string contains invalid characters!"; } } //END //Convert Plain-Text to ascii-binary-hex function text_to_all($input, $delimiter) { //Explode into arrays $orig_exp = str_split($input); //Do the conversion for ($i=0; $i<count ($orig_exp); $i++) { $ascii_string .= $delimiter . ord($orig_exp[$i]); //Again make sure every binary code is 8 chars if ($orig_exp[$i] == " ") { $binary_string .= $delimiter . "00000000"; } } } echo "HEX :: " . $hex_string . "<br>"; echo "Binary :: " . $binary_string . "<br>"; echo "ASCII :: " . $ascii_string . "<br>"; } //END //Convert HEX to ASCII-Binary-Plain text //First we validate the hex code function validate_hex($input) { $input = str_split($input); for ($i=0; $i<count ($input); $i++) { if (!is_int($input[$i]) && $input[$i] != "A" && $input[$i] != "B" && $input[$i] != "C" && $input[$i] != "D" && $input[$i] != "E" && $input[$i] != "F") { } } } //END //Now we do the conversion function hex_to_all($input, $delimiter) { } //END //Switch to functions according to main code type. if ($_GET["action"] == "convert") { $conversion_type = $_POST["code_type"]; $conversion_code = $_POST["original_code"]; $delimiter = $_POST["delimiter_box"]; binary_to_all($conversion_code, $delimiter); ascii_to_all($conversion_code, $delimiter); text_to_all($conversion_code, $delimiter); hex_to_all($conversion_code, $delimiter); } } //END ?></td> </tr> </table> </body> </html>
|
| Return to
php category list |
|
|
Who's Online
484 Guests, 101 Users ckryptix, Ios, viper0i0, Diznablo, rabbidmind, asapong, Nasrudin, CollapsingWalls, mehtaparag, bitstrike, jnony, C, Nicid1, Nusquam-Redono-Sapientia, bazcrown, saifulfaizan, The End, Ultraminor, psychomarine, st3alth, themastersinner, pgmrlink, login, lionaneesh, ishkur88, mahraja, Mac, chekifr, gandalf88, Vap0r, t0ast, tantrum6226, BnE, Distorted, Psiber_Syn, Ausome1, invas10n, oldgoat, freedaysbecumei, BinaryShinigami, Rex_Mundi, Red_beard, Strobeflux, s0m3nak3dguy, Descent, teehee, machupicchu, Genetix, Anandarl, NotMyOwn, thegamerdude, Godzila, popo12341234, RedEvolution, velocity_b, myne17, teto111, aVoid, Central-Gsm, 1101, JackalReborn, InjectioN, h4lted, c0re, DisPater, markt4death, splatta, Jackowacko, saint556, Pyron2312, Azerion, howsens, white.hat.gone.bad, vazzilly, pwunkz, Inverted, QuarterCask, Infernoe11, deskata, cr4ck3rj4ck, Blizer, jasonmax, j0sh, gwenwavor, N4g4c3N, spizeyboy, Network X, Uino59, Jae Cee, ianFDK, saykov, medhaavee, zofy, demonkiller410, Stumble, SaMTHG, kishore, Raze, helasraizam, Venom1019, Jakabo |
| |
|
|
|
|
|