Last active
January 13, 2022 21:19
-
-
Save nick3499/fd4053897585ed51aee76f9c442023c7 to your computer and use it in GitHub Desktop.
keygenme-py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/python3 | |
'''Print picoCTF flag for “keygenme-py” challenge.''' | |
import hashlib | |
user = b'GOUGH' | |
nums = [4, 5, 3, 6, 2, 7, 1, 8] | |
flag_1 = 'picoCTF{1n_7h3_|<3y_of_' | |
flag_2 = '' | |
flag_3 = '}' | |
for num in nums: | |
flag_2 += hashlib.sha256(user).hexdigest()[num] | |
print(flag_1 + flag_2 + flag_3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hashlib
Encode Username
sha256(b'GOUGH')
returns asha256 _hashlib.HASH object
hexdigest()
returns a string object of double length, containing only hexadecimal digits. This may be used to exchange the value safely in email or other non-binary environments.So, it simply became a matter of indexing characters based on the order of indices found in the
check_key()
method inkeygenme-py.py
(4, 5, 3, 6, 2, 7, 1, 8). For example, in the lineif key[i] != hashlib.sha256(username_trial).hexdigest()[4]:
the index value of4
can be found in the hex digest, so the first character becomesf
.References
hashlib