77 lines
1.9 KiB
Python
Executable File
77 lines
1.9 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
# Each character can be represented as a byte value using its
|
|
# ASCII encoding. Each byte contains 8 bits, and an int contains
|
|
# 32 bits, so we can "pack" 4 bytes into a single int. Here's an
|
|
# example: if the hex string is "01ab", then those can be
|
|
# represented as the bytes {0x30, 0x31, 0x61, 0x62}. When those
|
|
# bytes are represented as binary, they are:
|
|
#
|
|
# 0x30: 00110000
|
|
# 0x31: 00110001
|
|
# 0x61: 01100001
|
|
# 0x62: 01100010
|
|
#
|
|
# If we put those 4 binary numbers end to end, we end up with 32
|
|
# bits that can be interpreted as an int.
|
|
#
|
|
# 00110000001100010110000101100010 -> 808542562
|
|
#
|
|
# Since 4 chars can be represented as 1 int, the 32 character password can
|
|
# be represented as an array of 8 ints.
|
|
#
|
|
# - Minion #7816
|
|
|
|
# public int[] passwordToIntArray(String hex) {
|
|
# int[] x = new int[8];
|
|
# byte[] hexBytes = hex.getBytes();
|
|
# for (int i=0; i<8; i++) {
|
|
# x[i] = hexBytes[i*4] << 24
|
|
# | hexBytes[i*4+1] << 16
|
|
# | hexBytes[i*4+2] << 8
|
|
# | hexBytes[i*4+3];
|
|
# }
|
|
# return x;
|
|
# }
|
|
|
|
# public boolean checkPassword(String password) {
|
|
# if (password.length() != 32) {
|
|
# return false;
|
|
# }
|
|
# int[] x = passwordToIntArray(password);
|
|
# return x[0] == 1096770097
|
|
# && x[1] == 1952395366
|
|
# && x[2] == 1600270708
|
|
# && x[3] == 1601398833
|
|
# && x[4] == 1716808014
|
|
# && x[5] == 1734305378
|
|
# && x[6] == 825374004
|
|
# && x[7] == 912340068;
|
|
# }
|
|
|
|
CHUNKS: list[str] = [
|
|
"1096770097",
|
|
"1952395366",
|
|
"1600270708",
|
|
"1601398833",
|
|
"1716808014",
|
|
"1734305378",
|
|
"0825374004",
|
|
"0912340068",
|
|
]
|
|
|
|
|
|
def main():
|
|
print('picoCTF{', end='')
|
|
for x in CHUNKS:
|
|
i = int(x)
|
|
print(chr((i >> 24) & 0xFF), end='')
|
|
print(chr((i >> 16) & 0xFF), end='')
|
|
print(chr((i >> 8) & 0xFF), end='')
|
|
print(chr((i >> 0) & 0xFF), end='')
|
|
print('}')
|
|
|
|
if __name__ == '__main__':
|
|
main()
|
|
|