forked from Naetw/CTF-pwn-tips
-
Notifications
You must be signed in to change notification settings - Fork 1
Python
Rahul Sridhar edited this page Oct 27, 2017
·
1 revision
Collection of useful python functions for CTFs
assert(chr(0x41) == 'A')
assert(ord('A') == 0x41)
import binascii
x = binascii.unhexlify('4142434445')
assert(x == 'ABCDE')
y = binascii.hexlify(x)
assert(y == '4142434445')
import base64
y = base64.b64encode('asdfasdf')
assert(y == 'YXNkZmFzZGY=')
x = base64.b64decode('YXNkZmFzZGY=')
assert(x == 'asdfasdf')
import struct
x = struct.pack('<I', 0x44434241)
assert(x == 'ABCD')
y = struct.unpack('<I', y)
assert(y == (0x44434241,))
The <I
stands for "little-endian 32-bit integer". Note that unpack
returns a tuple.
N.B.: If you're using pwntools just use p32
and u32
instead!