Decode this binary : ) and how did you figure out?

Posted on 2004-11-30
Last Modified: 2008-03-10
See this image:


Note I might raise the points (however this is your own great brain exercise), but credit will be given to one who describes his approach in detail : )

Good luck.
Question by:InGearX
    LVL 8

    Accepted Solution

    The decoded binary says...

    "I spent $100 at ThinkGeek and all I got was this lousy limited edition t-shirt."

    This is based on 8 bit ascii.  I started from the end of the binary string and worked to the beginning converting as I went...  I'm sure there's a more optimal way but I was in a rush.  Enjoy!!  -Aaron

    string str = "01001001001000000111001101110000011001010110111001110100001000000010010000110001001100000011000000100000011000010111010000100000010101000110100001101001011011100110101101000111011001010110010101101011001000000110000101101110011001000010000001100001011011000110110000100000010010010010000001100111011011110111010000100000011101110110000101110011001000000111010001101000011010010111001100100000011011000110111101110101011100110111100100100000011011000110100101101101011010010111010001100101011001000010000001100101011001000110100101110100011010010110111101101110001000000111010000101101011100110110100001101001011100100111010000101110";

    string strMessage="";
    int count=0;
    string str_byte="";
    for(int i=str.Length-1; i>=0; i--)
          str_byte = str[i]+str_byte;
                int  b = System.Convert.ToInt32( str_byte, 2 );
                char c = (char)b;
                strMessage = c + strMessage;
                count = 0;
    LVL 1

    Assisted Solution

    Here comes a small real-mode standalone program for Intel x86-based DOS/Windows operating systems;
    it comes down to 82 bytes, which might be slightly less than the solution presented earlier.
    Of course it could be made even smaller by e.g. clever choice of system services, choice of opcodes and processing order,
    but for a simple app that can decode any 'image file' that contains these ones and zeroes, I think it is pretty alright.
    It handles redirection, so you can have it process either some file or your (terminated) keyboard input.
    I tried to write it so that any old assembler would accept it. The code assumes DS=CS.

    The idea is to decode eight characters represented by either ASCII '0's or '1's (all other input characters are skipped) into binary,
    then to output the accumulated character (cooked) and keep repeating this until the input is exhausted.
    The code utilises two DOS-level system services: read from file and write from file. This will allow to use command-line redirection.
    The code is not as dense as it could be, for sake of readability and porting ease.

    Tested on: DOS 6.22,Win95,Win98,Win4/SP6,Win2K/SP4,WinXP/SP1

    Run using (program file 'DECODE.COM', input file 'image'):  DECODE <image

    And the decoded text of course is
    'I spent $100 at ThinkGeek and all I got was this lousy limited edition t-shirt.'
    which is conveniently 79 bytes long to fit on a single line.

    DOS      EQU      21h
    COUNT      EQU      si
    READ      EQU      3fh
    WRITE      EQU      40h
    ZERO      EQU      '0'
    ONE      EQU      '1'

    start:      jmp decode

    Input            DB 0            ;for stdin
    Output      DB 0            ;for stdout

          mov [Output],0      ;the accumulated byte
          mov COUNT,8      ;bit counter
          mov ah,READ      
          mov bx,0      ;stdin
          mov cx,1
          lea dx,Input      ;into ds:dx tiny model, ds=cs
          int DOS            ;read next input character
          cmp ax,0            ;none?
          jz quit

          ;accept only '0' and '1'
          cmp [Input],ZERO
          jz got0
          cmp [Input],ONE
          jz got1
          jmp next
          shl [Output],1      ;punch the zero
          jmp isdone
           shl [Output],1            
           or [Output],1      ;punch the one

           dec COUNT
          jnz next      ;loop until eight bits have been collected

          mov ah,WRITE
          mov bx,1      ;stdout
          mov cx,1
          lea dx,Output            
          int DOS            ;show the accumulated character

          jmp decode      ;keep on truckin'



    PS. A curious fact about the 'image': when stored into a file with the exact layout presented in the question and
    using DOS-type line termination (CR+LF) for each line except the last, the file length is 666 bytes. Should this mean anything? ;-)


    LVL 23

    Expert Comment

    How do you decode it in visual basic just outta curiousty ?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    Title # Comments Views Activity
    while loop over for loop 7 67
    data scientists and AI 17 53
    sumHeights2  challenge 7 51
    countHi challenge 25 61
    How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
    If you haven’t already, I encourage you to read the first article ( in my series to gain a basic foundation of R and R Studio.  You will also find the …
    The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now