PROJECT 06_압축파일 암호 푸는 프로그램

김리나·2023년 1월 28일
0

번호를 생성하고 암호화된 압축파일에 대입해서 암호를 푸는 프로그램 만들기

  • 압축을 풀기 위해 문자열 순서대로 배열

import itertools
passwd_string = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

for len in range(1, 4):
    to_attempt = itertools.product(passwd_string, repeat = len)
    for attempt in to_attempt:
        passwd = ''.join(attempt)
        print(passwd)
  • 압축 푸는 코드

import itertools
import zipfile

passwd_string = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
#압축된 파일 경로
zFile = zipfile.ZipFile(r'6. 압축파일 암호 푸는 프로그램\암호1234.zip')

for len in range(1,6):
    to_attempt = itertools.product(passwd_string, repeat = len)
    for attempt in to_attempt:
        passwd = ''.join(attempt)
        print(passwd)
        try:
            zFile.extractall(pwd=passwd.encode())
            print (f"비밀번호는 {passwd} 입니다.")
            break
        except:
            pass
  • 비밀번호 찾으면 프로그램 종료

import itertools
import zipfile

def un_zip(passwd_string, min_len, max_len, zFile):
    for len in range(min_len, max_len+1):
        to_attempt = itertools.product(passwd_string, repeat = len)
        for attempt in to_attempt:
            passwd =''.join(attempt)
            print(passwd)
            try:
                zFile.extractall(pwd = passwd.encode())
                print(f"비밀번호는 {passwd} 입니다.")
                return 1
            except:
                pass

passwd_string = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

zFile = zipfile.ZipFile(r'6. 압축파일 암호 푸는 프로그램\암호1234.zip')

min_len = 4
max_len = 5

unzip_result = un_zip(passwd_string, min_len, max_len, zFile)

if unzip_result ==1:
    print("암호찾기에 성공하였습니다.")
else:
    print("암호찾기에 실패하였습니다.")

0개의 댓글