Thing you want to do When I was looking at my iPhone, I was wondering how long it would take to break the 4-digit passcode lock. A quick calculation shows that there should be 10000 combinations of 10 to the 4th power from "0000" to "9999". When I brute force this using Python, I measured how many seconds it took to detect the passcode.
"8400 rpm. 420 horsepower In the time you finish reading this sentence Accelerate to 100km / h. " This is a promotional phrase for the BMW M3 Coupe that was published in an automobile magazine about 10 years ago.
Is it faster or slower than that? Compete with the BMW M3 Coupe!
background ・ I am a Python beginner. ・ I learned the basics, but I don't know how to apply it, I don't use it at work, and my motivation is low.
** Thinking ** ・ The 4-digit PIN code is assumed to be a combination of 4 digits, which is often used for bank PINs and smartphone lock screens. -Assuming that you do not know the PIN code, it is randomly generated using a random function. -Try brute force from "0000" to "9999", and if there is a match, the message "iPhone unlocked" will be displayed.
code
pin_code_breaker.py
from random import randint
import time
pin_n = randint(0, 9999)
def iphone_unlock(pin_n):
for i in range(0, 9999):
print(format(i, '04'))
if i == pin_n:
print(f"PIN is {pin_n}, iPhone unlocked.")
break
else:
print('Process finished.')
start = time.time()
iphone_unlock(pin_n)
elapsed_time = time.time() - start
print(f"elapsed time: {elapsed_time}")
** Consideration ** -Since matching is tried by brute force from 0000, the younger the generated PIN code (closer to 0000), the shorter the processing time, and the larger it is (closer to 9999), the longer the processing time. ・ However, the process is completed within 3 seconds at the longest. ・ It turned out that the 4-digit password itself is defenseless.
Recommended Posts