더북(TheBook)

여기서는 모든 숫자 조합이 순차 컴퓨팅으로 처리된다. CPU가 한 번에 작업 하나만 처리한 후 다음 작업으로 넘어가며, 모든 작업을 순차적으로 처리하기 때문이다. 이 작업과 순차적으로 실행하는 위의 그림의 알고리즘을 다음과 같이 코드로 옮겼다.

# Chapter 2/password_cracking_sequential.py
import time
import math
import hashlib
import typing as T

def get_combinations(*, length: int, min_number: int = 0) -> T.List[str]:
    combinations = []
    max_number = int(math.pow(10, length) - 1)

    for i in range(min_number, max_number + 1):
        str_num = str(i)
        zeros = "0" * (length - len(str_num))
        combinations.append("".join((zeros, str_num))) 
    return combinations


신간 소식 구독하기
뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.