Skip to content

Instantly share code, notes, and snippets.

View dfyz's full-sized avatar

Ivan Komarov dfyz

View GitHub Profile
#!/usr/bin/python3
from pwn import *
def p64(n):
return struct.pack("<Q", n)
def gen_xorbyte(byteoffset, value, bitwidth, selfstart, jumpthen):
code = b""
for i in range(bitwidth):
if value & (1 << i):
@dfyz
dfyz / sice_supervisor.py
Created February 5, 2023 20:59
An attempt to solve Sice Supervisor from DiceCTF 2023, which almost succeeded
from pwn import *
PROMPT = b'> '
DONE = b'Done!\n'
if __name__ == '__main__':
with process('./sice_supervisor') as tube:
#with remote('mc.ax', 30283) as tube:
diff --git a/sample.py b/sample.py
index 6ff0ea2..00daada 100644
--- a/sample.py
+++ b/sample.py
@@ -7,10 +7,11 @@ from contextlib import nullcontext
import torch
import tiktoken
from model import GPTConfig, GPT
+import time
import galois
from itertools import chain
import numpy as np
class SymbolicByte:
def __init__(self, bit_vars):
self.bit_vars = [
self._xor_vars(vs) for vs in bit_vars
]
@dfyz
dfyz / exe.c
Last active September 26, 2022 02:35
Mach-O vs. ELF export benchmark
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <dlfcn.h>
#include <err.h>
#define NSYMS 1000000
@dfyz
dfyz / cvt.c
Last active September 11, 2022 23:14
Comparing x86 and aarch64 instructions for conterting double to int32_t
#include <stdio.h>
#include <stdint.h>
#include <math.h>
int32_t d2i(double);
int main(int argc, char* argv[]) {
for (int sign = -1; sign <= 1; sign += 2) {
for (int p = 0; p <= 7; ++p) {
double d = (double)sign * pow(133.7, (double)p);
@dfyz
dfyz / cvt_aarch64_cheat
Last active September 11, 2022 23:13
We have FJCVTZS at home
.global _d2i
.align 4
_d2i:
fcvtzs x0, d0
ret
#!/usr/bin/env python3
from Crypto.Util.number import *
import sys
from flag import flag
def diff(a, b):
assert a.bit_length() == b.bit_length()
w, l = 0, a.bit_length()
for _ in range(l):

When $a \ne 0$, there are two solutions to $(ax^2 + bx + c = 0)$ and they are $$ x = {-b \pm \sqrt{b^2-4ac} \over 2a} $$

Example AMD output:

$ lscpu | grep 'Model name'
Model name:                      AMD Ryzen Threadripper 3970X 32-Core Processor
$ gcc -DFAST puzzle.S -o puzzle && ./puzzle
1000000000 iterations, 2758479060 cycles, 2.76 cycles/iteration
1651816810 106000000000
$ gcc -DSLOW puzzle.S -o puzzle && ./puzzle
1000000000 iterations, 6551777517 cycles, 6.55 cycles/iteration