 What's up guys John Hammond here moving into the Python challenge and we're looking at level 21. Let's just get right into it This is the prompt here We're working inside the zip archive that we just got finally figured out from level 20 And there's read me dot text in it and this package dot pack. So the prompt here is Okay, this is really level 21 after you solve it. You'll be in level 22 So for the level we used to play this game when we were kids when I had no idea what to do I looked backwards Okay, I don't really know what that means, but let's just go ahead and make a directory for ourselves Level 21 and let's actually yeah, let's go ahead and move the read me dot text in there and the package in there Just so we have a place to work that is not level 20 So, okay now we're level 21 and I want to know what this package dot pack thing is looks like that's actually We're gonna be working with you. So is he live compressed data? Okay? Kind of like an archive compressed data like a zip file like a raw like a tar file just compressed data So how do we uncompress that? We want to do this in Python so Zlib decompress Check out the documentation Okay, it looks like there's just a built-in module for it. I think that is built-in right Import Zlib. Yep. Okay, cool So we've got a built-in module to work with them. It looks like it has functions to compress compress object So we'll see our C value and decompress. Okay decompress takes a string So not like a file object or a file handle, but we need to read from that object to begin with Okay Let's try that Let's just create a new file for ourselves Let's call this We're in 21 here. I'll call it ape.py. So I have a script and put our shebang line in as usual All right, so we'll import Zlib since that's what we're working with here And let's go ahead and open up our package dot pack Objects and call that H and let's just say I Usually call it C, but I guess data whatever doesn't matter H.read and then H.close. Okay. Whoa. Don't want to buy sublime text Okay, so that should we can just print out data in this case and let's get a terminal side by side here So I can mark the script executable run it and we get a bunch of garbage because this is That Zlib data. Let's try and decompress that. Let's do that Zlib dot Decompress and the string is just gonna be data since we already read that from our H object or file handle Try this guy. Oh, I gave an argument and didn't need to didn't really matter So just a bunch of crap still let's just call that something so we can run file on it to see what it is And it's still Zlib compressed data. Did it Did it even do anything with it? All right. Let's take L package dot pack is This much minutes this this this many bytes something is this many bytes. Okay, so we got something decompress We lost like 80 of it Well, now let's do that with The something file that we just started to work with 8.pi more garbage redirect that to again file again still Zlib compressed data and Okay, now we're losing bytes every time we work through so What is this? It's just is this like a recursive encoded recursive like it repeatedly compressed and stuff Okay, just over and over and over again. We're gonna have to decompress this so Let's start like just a while loop while true so we do this over and over and over again Let's say data is equal to Zlib dot decompress What we're working with and right now, I guess let's just print it out. I guess because I don't know what else we're gonna really do with it Hey, oh nonsense nonsense nonsense and it's hanging. I just hit the spacebar Because I didn't want to enter all these nonsense. So so we get an error As you live decompress data error 3 will decompressing data incorrect header check. What why not? What is this not Zlib data anymore? Is that what is that good stuff? I'm gonna put this in just a try and accept statement. So once it errors out we can Print the data there And let's break so we don't loop forever because we are inside of a while loop right now Run that Apes scripts That's where it's hanging. So let's let's get rid of something and again So now we just clean here run Ape. Oh shit. No We run from the original file package dot pack. Good thing. I did that. I guess Now run a nonsense Let's redirect that to a file Let's put that in something I guess so what is something? Oh, it's B zip to compress data Okay, so we changed from Zlib to B zip to again another compression Like archive system thing just compressed data. Let's kind of I do Python bun zip or BZ unzip. Okay, so there's another module BZ to Do we have it? Yep, okay, it should be in some way to fall. I'm pretty sure it's built in. Yep, and It has a decompress decompress function I'll get one shot decompression provided through these functions here and again It looks like it just decompresses data decompress data in one shot Okay, that works we could just use that Import BZ to We don't need this try and accept anymore. Oh Wait a second. How are we gonna know? When to use which because we're just looping like a crazy Like a steamroller here. We're just going to get in and get in again How are we gonna know which to use the Z lip decompression or the BZ to decompression? We can probably just see what the data is It's gonna be data, so I can be like raw text So we can't we can't like run strings on something or strings on the original package dot pack Then find something that like would help us identify but we can probably just use Like the files we enter like the magic number at the very start here, so I guess Zlib will start with an X I'm looking at the ASCII on the right side. We can just see the hex here 78 is a bite or 9c is a bite we could do that, but if it starts with X it looks like it's Just fine Control C break out a hex edit and what is something sorry so BZ to The BZip compression will start with like a BZ capital BZ, so Can we try that if The data dots starts with an X then we will use Zlib if it doesn't and it starts with Like a BZ it was capital, right? Yeah It will use the BZ to decompress Data cool, and then in case it's anything else like it not a Zlib or BZ to we can just print out What it is and hopefully it'll be a flag or something for us or like a the password for the next level All right, let's go out of something and let's see if this will work Whoa nothing great. Jeez. This is the nonsense again That's really long Is it the whole thing? Oh shit, we didn't break my bad my bad Now it should be short. Okay, cool. Yeah, it's not just a bunch of data Consistently, I think it would eventually stop it if we're still gonna be a compressed file So that's it right now, but what is This thing let's put this into something again File something whoa 8086 relocatable Microsoft I Have no idea what that is. Let's Google that. Oh Good Lord for transhofer It was six Relocatable code predates virtual memory This can't be right Locatable object mode checks up. Okay. It's not like more compressed data. I don't this doesn't make any sense Okay, but everything else like looked so promising Uh What is the prompts? We used to play this game when we were kids, okay That's got to be like a reference to the recursive thing like a matryoshka doll or something What I had no idea what to do. I look back. Oh my gosh I had no idea what to do. Okay. I don't know what to do with this thing. So maybe What is this? Rev yeah, okay, you can't rev a binary file. You can't reverse it, but Let's hex edit something and get to like the very end and that's gonna take way too long. This file is too big Let's go xxd something And at the very end. Ah Yep Sure ends with the But it's like it looks like it ends with a new line here because of the print statement in Python when we redirected it But it's that same 7 8 and 9c. It's that same X character that we noted was a Zlib thing It's just backwards because that's the stupid riddle hint here when I know what it was to do. I look backwards. So it is It is backwards. Let's reverse it else let's just Keep working with that data because maybe they do this later with the BZ2 function. Let's just keep that data Let's not decompress it, but let's just reverse it Start to and reverse negative one as our incrementer and that way the next iteration of this while loop Once it runs through again, it'll use that data to either decompress or with Zlib or BZ2. So hopefully that should work and then I guess now we've got enough tests so if We if it doesn't return we can just print the data and we'll break if it's not either a reversed Zlib or BZ2 or regular Zlib, whatever. Let's try it now. Oh LF why is that not working? Oh LF Need to give it a condition, right? So if the data Ends with an X. We saw that with Our XXD. Yeah, there's an X at the very end. So if it ends with X, it's just the same as Zlib before but reversed. So let's just reverse it Okay, I hit that pie. Oh Hey, what is that? Skull Roya Takul This has to be backwards too. You can rev that Look at your logs What does that mean? I don't have any logs. I just wrote a Python script. That's all I did Do you mean like? Does it mean like the decompression that I'm doing? Is it? Okay, maybe like it needs to know when I use Zlib Will that help me figure anything out? Whether or not it was a Zlib or BZ2 or Reverse thing reverse good and Print data whatever a lot of stuff How many times is each of them? That doesn't help me Do anything that doesn't spell anything out. Did these like occur? Like a special number of times. I mean there's only three Things there's only three like potential things that could be BZB to Zlib or reversed Let's sort this and then okay pass it to unique tech C's we can get a count for whatever what happens so many times Reverse happens nine times. That's the thing. That's the secret 300 BZ to 432 Zlib, but not trying to spell anything out At least not oh Maybe it's not trying to spell anything out like vertically, but it's trying to do like horizontally or something like what if it is Giving a little message like one by one since there are so many of these So many of you to the BZB or the Zlib Let's put like a Minus sign and a plus sign or something and then this reverse that only happens a little it must be like a new line character So we don't need anything we just print out to begin with and then let's use the comma Following these print statements, so it doesn't print a new line, but it'll print a space So it will continue on the same line as if we were to keep moving forward that should work Whoa, whoa. What is that? I? Have no idea. Oh god. That's so hard to see That's still I didn't zoom out. Sorry. Oh, it's trying to spell something. I think That's kind of Oh, let's just remove this and just use like Like an X or something here Copper oh That's awesome. Oh, that's super cool remove the data at the end here. It just prints out copper Okay, dude, dude, copper's probably got to be it. That's got to be like the Key to the next level copper. Yes. Oh Sweet guys. All right. We did it. That's it. That was level 21 Stuck inside a little zip archive that had more nested BZIP archives and Zlib archives compressed data And then just doing that in Python running through that recursive decompression little matroishka doll thing and They threw a curve ball with that like reverse syntax that was messed up, but Okay, cool. That's it Thank you guys so much for watching. Hope you enjoyed these Hope you I hope you're enjoying the Python challenge series a lot of people have been asking for these for a long long time So I hope they're enjoyable to watch I hope you're learning a thing or two about Python and Enjoying kind of this problem-solving riddles and stuff that we're moving through so hey if you like the video Please do like like the video click the button Maybe subscribe if you're feeling up for it and really if you do want to support me That's the best way to do it send some send some love my way, but thanks for watching guys Hope you're enjoying these and I'll see you in the next video level 22 Python challenge