Russian Dolls

Discussion of challenges you have already solved
timothy48342
Posts: 2
Joined: Mon Jul 30, 2012 5:01 am
Location: usa

Post by timothy48342 »

I had sat on the "file mystery" challenge for a few days. It was also a compressed file, but I never would have guessed it. Then when I looked at the first few bytes of this, I saw it was the same and that made me think to do an internet search for the hex of the bytes themselves and found out they both were compressed.

That was the hardest part. Up till then I had tried opening it as a graphic and all sorts of stuff like that. I had tried various guesses with the other one, too.(Even used a ROTXX program I had written on that one. No such luck.)

Anyway past figuring out that it's compressed, and that 7-Zip can open it up without trouble, I started to peal back the layers manually until that got tedious.

So I made a batch file. 7-zip's command line version was easy to use and the docs were in the help file, so I lucked out with that.

do.bat:
@copy *.zip ..
@erase *.zip
@rename *. *.zip
@7z x *.zip

Than after running that about 20 times made another bat file
dox10.bat
@call do.bat
@call do.bat
@call do.bat
@call do.bat
...etc
Then after that got tedious, made a dox100.bat

I think this thing was about 500 levels deep or more.

So, I learned 2 things. When you don't know what kind of file you have, type the first few bytes into a search engine. And scrips are so much better than typing and clicking.
(Also learned that "IF EXISTS filename" does not work in a .bat file on my installation of winXP. I wonder if they have done away with that or disabled it some versions. *shrug*)

Fun, fun.
On to the next.
--timothy48342
strongdrink
Posts: 4
Joined: Tue Jul 12, 2011 4:31 pm
Location: Floating Around

Post by strongdrink »

Simple on *nix!

Code: Select all

mv doll.bin doll
while true; do mv doll doll.gz; gunzip doll.gz;done
It will just start outputting a bunch of gunzip errors when it is done :)
Last edited by strongdrink on Wed Aug 21, 2013 11:50 am, edited 2 times in total.
User avatar
CodeX
Posts: 350
Joined: Fri Oct 17, 2008 5:28 pm

Post by CodeX »

If you give it a good bash the answer will simply fall out :D

Code: Select all

wget -qO a.z http://www.hacker.org/challenge/misc/doll.bin
while true
do
    (gzip -d a.z 2>/dev/null && mv a a.z) || break
done
cat a.z
rm a.z
viaken
Posts: 1
Joined: Wed Feb 15, 2012 3:37 pm

bash solution with a counter

Post by viaken »

Here's how I did mine. Infinite loops make me itch, so I try to avoid "while true", even knowing I can break.

Also, looks like it was nested 999 times.

Code: Select all

wget -qO doll.gz http://www.hacker.org/challenge/misc/doll.bin
export i=0
while gunzip doll.gz
  do let i++ ; mv doll doll.gz
done
echo "Took $i iterations"
cat doll
[/code]
User avatar
Hippo
Posts: 339
Joined: Sat Feb 01, 2014 12:05 am
Location: Praha 5

Post by Hippo »

My 5 cents:

Code: Select all

:loop
dell bak
copy [Content] bak
ren [Content] doll.zip
7z e doll.zip
del doll.zip
goto :loop
snoopy1alpha
Posts: 4
Joined: Wed Jun 04, 2014 6:27 pm

Post by snoopy1alpha »

It is always interesting to see other peoples solutions. I always wonder why I am solving my problems in Java, if other languages can do the job in fewer lines of code. However, the neat thing about the Java solution is that Java supports gzip without additional tools. In combination with ByteArray(Input|Output)Streams, we have a very efficient way to work in memory, without writing the interim data back to the HDD. I will not post my code, but I want to share my solution strategy:
- read the gzip file into a byte array
- check the magic number for gzip
- deflate the data (new array, same reference) and check again
- repeat this until the magic number check fails
- the last byte array is written as file back to the HDD (and contains the solution text).
totick
Posts: 1
Joined: Mon Oct 13, 2014 5:38 pm

Python solution with help of file signature

Post by totick »

Code: Select all

import gzip

f = open(r"c:\doll.bin", "rb")
doll = f.read()
i = 1
r = gzip.decompress(doll)
while r.startswith(b"\x1f\x8b\x08"): # b"\x1f\x8b\x08"  = Hex Signature for gzip file
    r = gzip.decompress(r)
    i += 1

print(r) # result
print(i) # iteration count
List of file signatures http://garykessler.net/library/file_sigs.html
Valar_Dragon
Posts: 21
Joined: Sun Jan 04, 2015 3:34 pm

Post by Valar_Dragon »

I just used 7zip File Manager (The GUI) and an auto clicker and would just go through 200+ files deep, rename the file so 7zip didn't get an error due to the string taking too much memory, and repeated. It took less than 5 minutes to do this way.
stask
Posts: 3
Joined: Sun May 29, 2016 6:12 am

Post by stask »

Did it on MATLAB. Very simple.
Just ran a for-loop on the following code:

Code: Select all

 ! ren doll doll.gz
 gunzip('doll.gz')
 ! del doll.gz
The code run automatically stops when it reaches a doll.gz file which is not valid.
evan_yeyeye
Posts: 1
Joined: Tue May 17, 2016 9:22 pm

Post by evan_yeyeye »

I wrote an extremely simple shell script.

Code: Select all

#!/bin/bash

while (true)
do	
	mv doll doll.gz
	gunzip doll.gz
done
evan_yeyeye
Mad Mike
Posts: 11
Joined: Tue Jun 21, 2011 4:38 pm

Post by Mad Mike »

Boring part first: I wrote a bash one-liner

Code: Select all

while [ /bin/true ] ; do mv doll doll.gz; gunzip doll; done
and waited for errors to occur. But I really love how the first posts are like "took me over five minutes" and nowadays it's mere seconds (I'd guess ten?) until one hits the bottom.

Also tried to do it manually (Windows machine…) but when I got to the bottom the filename was too long to read or unpack the file. Such shame!
chown -R us ./base
Post Reply