Last active
July 19, 2017 16:44
-
-
Save MrQubo/3c95567d80d2c244db38b4789f093765 to your computer and use it in GitHub Desktop.
python3
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
import string | |
# num = msg * C | |
# We know num, so we have to check every possible C, | |
# but there's a hint "P.S.2. It's just two bytes.", | |
# so we only check two-byte numbers | |
num = 1087943696176439095600323762148055792209594928798662843208446383247024 # given number | |
# converts integer to array of its bytes | |
def to_byte_array(n): | |
# Byte order could be big-endian or little-endian, | |
# I assumed big, if it's incorrect, we would get string in reverse order | |
return n.to_bytes((n.bit_length() + 7) // 8, byteorder='big') | |
def try_num(n): | |
a = to_byte_array(n) | |
a = [chr(x) for x in a] # convert array of bytes to array of ascii characters | |
if(not all(c in string.printable for c in a)): # check if all characters are printable | |
return | |
msg = ''.join(a) # convert array of characters to string | |
print(msg) | |
for C in range(1,256**2): # we check only two-byte numbers (except 0) | |
if(num % C == 0): # check if num is the multiple of C | |
try_num(num // C) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment