Russian Dolls
-
- Posts: 2
- Joined: Mon Jul 30, 2012 5:01 am
- Location: usa
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
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
-
- Posts: 4
- Joined: Tue Jul 12, 2011 4:31 pm
- Location: Floating Around
Simple on *nix!
It will just start outputting a bunch of gunzip errors when it is done
Code: Select all
mv doll.bin doll
while true; do mv doll doll.gz; gunzip doll.gz;done
Last edited by strongdrink on Wed Aug 21, 2013 11:50 am, edited 2 times in total.
If you give it a good bash the answer will simply fall out
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
bash solution with a counter
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]
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
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
-
- Posts: 4
- Joined: Wed Jun 04, 2014 6:27 pm
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).
- 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).
Python solution with help of file signature
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
-
- Posts: 21
- Joined: Sun Jan 04, 2015 3:34 pm
Did it on MATLAB. Very simple.
Just ran a for-loop on the following code:
The code run automatically stops when it reaches a doll.gz file which is not valid.
Just ran a for-loop on the following code:
Code: Select all
! ren doll doll.gz
gunzip('doll.gz')
! del doll.gz
-
- Posts: 1
- Joined: Tue May 17, 2016 9:22 pm
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
Boring part first: I wrote a bash one-liner
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!
Code: Select all
while [ /bin/true ] ; do mv doll doll.gz; gunzip doll; done
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