+ Reply to Thread
Results 1 to 4 of 4

Thread: Text -> Binary and Binary -> Text PHP script

  1. #1
    Full Member dzone is on a distinguished road
    Join Date
    Dec 2003
    Posts
    75

    Text -> Binary and Binary -> Text PHP script

    Hello everybody!

    I've just wrote this code snippet... It's quite useless but funny. Just think about, you can encode your forum signatures to look like an 133t 4ax0r, send encoded mails or something like this And then string_split() && safestrip() are quite usefull in everyday life.

    Code:
    <?php
    // Text -> Binary and Binary -> Text tools, v0.1
    // Useless, but funny
    // &#40;C&#41; Yury V. Zaytsev &#40;zaytsev at mail dot nnov dot ru&#41;, 2003-2004
    
    // Parse the input
    $input = safestrip&#40;$_POST&#91;&quot;input&quot;&#93;&#41;;
    
    ?><html>
    <head><title>Text -> Binary and Binary -> Text tools, v0.1</title></head>
    <body>
    <h1>Text -> Binary and Binary -> Text tools, v0.1</h1>
    
    <form method=post action=<?php echo $PHP_SELF; ?>>
    
    <p><input type=submit name=submit value='Encode'>
    &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
    <input type=submit name=submit value='Decode'></p>
    
    <p>Input text&#58;</p>
    <textarea rows=10 cols=50 name=input><?php echo $input; ?></textarea>
    </form>
    
    <?php
    $output = &quot;&quot;;
    
    // If user asked us to decode the stuff...
    if &#40;$_POST&#91;&quot;submit&quot;&#93; == &quot;Decode&quot;&#41; &#123;
    
       // Consolidate text &amp; split in groups of 8 chars
       $text = str_replace&#40;&quot; &quot;, &quot;&quot;, trim&#40;$input&#41;&#41;;
       $arr = string_split&#40;$text, 8&#41;;
    
       // Take each 8 bit group and convert it to ASCII symbol
       for &#40;$i = 0; $i < count&#40;$arr&#41;; $i++&#41;
          $output .= chr&#40;bindec&#40;$arr&#91;$i&#93;&#41;&#41;;
    
    // User asked us to encode the stuff
    &#125; elseif &#40;$_POST&#91;&quot;submit&quot;&#93; == &quot;Encode&quot;&#41; &#123;
    
       // Trim the input &amp; convert each character first to the
       // ASCII code and then to it's binary representation
       $text = trim&#40;$input&#41;;
       for &#40;$i = 0; $i < strlen&#40;$text&#41;; $i++&#41;
          $output .= sprintf&#40;&quot;%08d&quot;, decbin&#40;ord&#40;$text&#91;$i&#93;&#41;&#41;&#41; . &quot; &quot;;
    &#125;
    
    ?><p>Script output&#58;</p>
    <textarea rows=10 cols=50 ><?php echo trim&#40;$output&#41;; ?></textarea>
    <p><hr></p>
    <p align=right>&amp;copy; Yury V. Zaytsev, 2003</p>
    </body>
    </html><?php
    
    // Split the given string into an array of substrings of the given length
    function string_split&#40;$string, $split_length = 8, $separator = '&#58;'&#41; &#123;
       return explode&#40;$separator, chunk_split&#40;$string, $split_length, $separator&#41;&#41;;
    &#125;
    
    // Strip the &quot;automagically&quot; added quotes only if this &quot;feature&quot; is ON
    function safestrip&#40;$str&#41; &#123;
       return get_magic_quotes_gpc&#40;&#41; ? stripslashes&#40;$str&#41; &#58; $str;
    &#125;
    ?>
    ------------------------------------
    [URL=http://www.dedicatedzone.com]Managed Dedicated Servers[\URL]

  2. #2
    Full Member dzone is on a distinguished road
    Join Date
    Dec 2003
    Posts
    75
    01000001 01101110 01100100 00100000 01001101 01100101 01110010 01110010 01111001 00100000 01011000 01001101 01100001 01110011 00100000 01110100 01101111 00100000 01100001 01101100 01101100 00100000 01101111 01100110 00100000 01111001 01101111 01110101 00100000 00111010 00101001
    ------------------------------------
    [URL=http://www.dedicatedzone.com]Managed Dedicated Servers[\URL]

  3. #3
    Full Member dzone is on a distinguished road
    Join Date
    Dec 2003
    Posts
    75

    Huh :)

    Do you need a translation ?

    And Merry XMas to all of you
    ------------------------------------
    [URL=http://www.dedicatedzone.com]Managed Dedicated Servers[\URL]

  4. #4
    Moderator airnine is on a distinguished road
    Join Date
    Jan 2004
    Posts
    78
    nice touch,

    Airnine
    -------------------------------
    Airnine is a developer @
    www.promomedium.com
    -------------------------------

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Posting Permissions

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