Please include the following text and links: This article is participating in Python Theme Month, see the links to the events for more details
Hi, I’m Lex the Lex who likes to bully Superman
Areas of expertise: Python development, network security, Windows domain control Exchange architecture
Today’s key: Goddess encryption album can not open, I use 20 lines of code, help her open
1. Here’s the thing
This morning, the company goddess sister said that she went to Sanya last year travel photos can not open
I had to ask out of curiosity.
Turns out, she compressed the photo and added a password.
But I don’t remember it, just a string of six digits.
The compression rate of photos is not high, but also encryption, is there any cute little photos
But as a positive (BA) straight (GUA) technician
I told her, “I’ll take care of it. Python will write a script to help you crack it.”
Second, first of all, review the goddess’s operation process
When I compressed the album, I added the password.
LIke This left
Three, need to open the album
When you open it, it prompts you to enter your password.
4. Python scripting
1. Basic ideas
First, if you want a Python command line to open the little Sister album, you first need to find the command line you are trying to open, that is, the command line used for decompression. Then we use python scripts to write nested loops to try and unzip the zip file and retrieve the real password.
2. Decompress commands
First, the compressed file is in ZIP format, and we use the versatile 7z command to unpack it.
Why not use unzip? (Because I tried, unzip can’t loop)
3. Analyze the parameters of decompression commands
PS C:\Users\lex> 7z7-zip 21.01 alpha (x64) : Copyright (C) 1999-2021 Igor Pavlov: 2021-03-09 Usage: 7z <command> [<switches>...] <archive_name> [<file_names>...] [@listfile] <Commands> a: do you want to do something with your Commands d: do you want to do something with your Commands Extract files from archive (without using directory names) T: Test integrity of archive # <Switches> -o{Directory} : set Output Directory -p{Password} : set Password # Set Password parametersCopy the code
4. Sort out the 7z decompression command
The commands are too simple, and seem a little out of keeping with my talents and ideas
7z -p 123456 t zip # t: try to open, similar to background run # -p: try password # finally is the file to extractCopy the code
Close the door! The python scripts
According to the little sister’s needs, the password is six pure numbers, that helped me save a lot of time
Try only 6 pure digits.
The script came out in three minutes
Five, find the goddess to…
Faced with the goddess at a loss, I ran the script, less than 5 seconds, the album was successfully opened.
Results the GIF left
The story ends
When I opened it, the goddess looked at me differently.