Skip to content

Instantly share code, notes, and snippets.

@pun1sher729
pun1sher729 / writeup.md
Last active May 18, 2022 19:24
Cryptohack - Diffusion through Permutation writeup
def shift_rows(s):
    s[0][1], s[1][1], s[2][1], s[3][1] = s[1][1], s[2][1], s[3][1], s[0][1]
    s[0][2], s[1][2], s[2][2], s[3][2] = s[2][2], s[3][2], s[0][2], s[1][2]
    s[0][3], s[1][3], s[2][3], s[3][3] = s[3][3], s[0][3], s[1][3], s[2][3]


def inv_shift_rows(s):
    s[0][1], s[1][1], s[2][1], s[3][1] = s[3][1], s[0][1], s[1][1], s[2][1]
    s[0][2], s[1][2], s[2][2], s[3][2] = s[2][2], s[3][2], s[0][2], s[1][2]
@pun1sher729
pun1sher729 / writeup.md
Last active May 18, 2022 19:25
Cryptohack - Structure of AES writeup
def bytes2matrix(text):
    """ Converts a 16-byte array into a 4x4 matrix.  """
    return [list(text[i:i+4]) for i in range(0, len(text), 4)]

def matrix2bytes(matrix):
    """ Converts a 4x4 matrix into a 16-byte array.  """
    out = []
    for r in matrix:
 for c in r:
@pun1sher729
pun1sher729 / writeup.md
Last active May 18, 2022 19:24
Cryptohack - Round Keys writeup
state = [
    [206, 243, 61, 34],
    [171, 11, 93, 31],
    [16, 200, 91, 108],
    [150, 3, 194, 51],
]

round_key = [
 [173, 129, 68, 82],
@pun1sher729
pun1sher729 / writeup.md
Last active May 18, 2022 19:25
Cryptohack - Confusion through Substitution writeup
s_box = (
    0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5, 0x30, 0x01, 0x67, 0x2B, 0xFE, 0xD7, 0xAB, 0x76,
    0xCA, 0x82, 0xC9, 0x7D, 0xFA, 0x59, 0x47, 0xF0, 0xAD, 0xD4, 0xA2, 0xAF, 0x9C, 0xA4, 0x72, 0xC0,
    0xB7, 0xFD, 0x93, 0x26, 0x36, 0x3F, 0xF7, 0xCC, 0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8, 0x31, 0x15,
    0x04, 0xC7, 0x23, 0xC3, 0x18, 0x96, 0x05, 0x9A, 0x07, 0x12, 0x80, 0xE2, 0xEB, 0x27, 0xB2, 0x75,
    0x09, 0x83, 0x2C, 0x1A, 0x1B, 0x6E, 0x5A, 0xA0, 0x52, 0x3B, 0xD6, 0xB3, 0x29, 0xE3, 0x2F, 0x84,
    0x53, 0xD1, 0x00, 0xED, 0x20, 0xFC, 0xB1, 0x5B, 0x6A, 0xCB, 0xBE, 0x39, 0x4A, 0x4C, 0x58, 0xCF,
    0xD0, 0xEF, 0xAA, 0xFB, 0x43, 0x4D, 0x33, 0x85, 0x45, 0xF9, 0x02, 0x7F, 0x50, 0x3C, 0x9F, 0xA8,
    0x51, 0xA3, 0x40, 0x8F, 0x92, 0x9D, 0x38, 0xF5, 0xBC, 0xB6, 0xDA, 0x21, 0x10, 0xFF, 0xF3, 0xD2,
@pun1sher729
pun1sher729 / writeup.md
Last active May 18, 2022 19:26
Cryptohack - Bringing It All Together writeup
N_ROUNDS = 10

key        = b'\xc3,\\\xa6\xb5\x80^\x0c\xdb\x8d\xa5z*\xb6\xfe\\'
ciphertext = b'\xd1O\x14j\xa4+O\xb6\xa1\xc4\x08B)\x8f\x12\xdd'

s_box = (
    0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5, 0x30, 0x01, 0x67, 0x2B, 0xFE, 0xD7, 0xAB, 0x76,
    0xCA, 0x82, 0xC9, 0x7D, 0xFA, 0x59, 0x47, 0xF0, 0xAD, 0xD4, 0xA2, 0xAF, 0x9C, 0xA4, 0x72, 0xC0,
    0xB7, 0xFD, 0x93, 0x26, 0x36, 0x3F, 0xF7, 0xCC, 0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8, 0x31, 0x15,
@pun1sher729
pun1sher729 / writeup.md
Last active May 18, 2022 19:26
Cryptohack - Passwords as Keys writeup
from Crypto.Cipher import AES
import hashlib
import requests
from binascii import hexlify

r = requests.get("http://aes.cryptohack.org/passwords_as_keys/encrypt_flag/")
ct = (r.text).split('"')[3]

with open("words.txt") as f:
@pun1sher729
pun1sher729 / writeup.md
Last active May 18, 2022 19:27
Cryptohack - ECB Oracle writeup

Working Method:

from binascii import hexlify
import requests
import json
from string import printable

def encrypt(pt):
    p = hexlify(pt).decode()
    url = "http://aes.cryptohack.org/ecb_oracle/encrypt/"+p
@pun1sher729
pun1sher729 / writeup.md
Last active May 18, 2022 19:27
Cryptohack - ECB CBC WTF writeup
import requests
import json
from pwn import xor

def get_ciphertext():
    url = "http://aes.cryptohack.org/ecbcbcwtf/encrypt_flag/"
    r = requests.get(url)
    ct = (json.loads(r.text))['ciphertext']
 return ct
@pun1sher729
pun1sher729 / writeup.md
Last active January 28, 2024 13:49
Cryptohack - Flipping Cookie writeup

082113_1459_CBCByteFlip3

From cbc decryption: P0 = iv xor block_decryption(C0)

P0 --> "admin=False" P' --> "admin=True" (what we want)

"admin=True" = iv' xor block_decryption(C0)

@pun1sher729
pun1sher729 / writeup.md
Last active May 18, 2022 19:28
Cryptohack - Symmetry writeup

This is esentially a chosen plaintext attack

import requests
import json
from binascii import *
import string

def encrypted_flag():
 url = "http://aes.cryptohack.org/symmetry/encrypt_flag/"