General

ASCII

Integers to corresponding ASCII characters.

Solution

ascii.py
def ascii():
    a = [99, 114, 121, 112, 116, 111, 123, 65, 83, 67, 73, 73, 95, 112, 114, 49, 110, 116, 52, 98, 108, 51, 125]
    r = ""
    for elem in a:
        r = r + chr(elem)
    return r

print(ascii())

Hex

Hex to bytes.

Solution

hex.py
def hex():
    s = "63727970746f7b596f755f77696c6c5f62655f776f726b696e675f776974685f6865785f737472696e67735f615f6c6f747d"
    return bytes.fromhex(s)

print(hex())

Base64

From hex to bytes to base64.

Solution

b64.py
import base64

def b64():
    hex_string = "72bca9b68fc16ac7beeb8f849dca1d8a783e8acf9679bf9269f7bf"
    bytes_ = bytes.fromhex(hex_string)
    return base64.b64encode(bytes_)
print(b64())

Bytes and Big Integers

Given a long, convert to bytes.

bytes_and_big_integers.py
from Crypto.Util.number import long_to_bytes # pip install pycryptodome

def bytes_and_big_integers():
    long_ = 11515195063862318899931685488813747395775516287289682636499965282714637259206269
    return long_to_bytes(long_)

print(bytes_and_big_integers())

XOR Starter

XOR gymnastics.

xor_starter.py
import pwn # pip install pwntools

def xor_starter(b):
    r = ""
    for c in b:
        c_to_int = c ^ 13
        int_to_str = chr(c_to_int)
        r = r + int_to_str
    return r

def xor_starter_alt(b):
    return pwn.xor(b, 13)

bytes_ = b"label"
print(xor_starter(bytes_))
print(xor_starter_alt(bytes_))

Last updated