Skip to content

Instantly share code, notes, and snippets.

@dfyz
dfyz / exe.c
Last active Sep 26, 2022
Mach-O vs. ELF export benchmark
View exe.c
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <dlfcn.h>
#include <err.h>
#define NSYMS 1000000
@dfyz
dfyz / cvt_aarch64_cheat
Last active Sep 11, 2022
We have FJCVTZS at home
View cvt_aarch64_cheat
.global _d2i
.align 4
_d2i:
fcvtzs x0, d0
ret
@dfyz
dfyz / cvt.c
Last active Sep 11, 2022
Comparing x86 and aarch64 instructions for conterting double to int32_t
View cvt.c
#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);
View fiercest.py
#!/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):
View latex_test.md

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} $$

View output.md

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
View mmap_benchmark.cpp
#include <exe/tp/thread_pool.hpp>
#include <exe/fibers/core/api.hpp>
#include <wheels/support/assert.hpp>
#include <chrono>
#include <iostream>
using namespace exe;
View memsafed.py
from pwn import *
def connect():
if args.REMOTE:
return remote('pwn1.ctf.zer0pts.com', 9002)
return process('./chall')
with connect() as tube:
View memory_models.cpp
#include <atomic>
#include <cstdint>
#include <chrono>
#include <iostream>
#include <thread>
bool IsPrime(uint64_t x) {
for (uint64_t y = 2; y * y <= x; ++y) {
if (x % y == 0) {
return false;
View qs_patch.patch
diff --git a/factorizer_qs.py b/factorizer_qs.py
index 1368283..e326743 100644
--- a/factorizer_qs.py
+++ b/factorizer_qs.py
@@ -70,7 +70,7 @@ class QuadraticSieve(Factorizer):
x = int(x)
candidate = (x+chunk_start)*(x+chunk_start) - N
factorization = _is_smooth(candidate)
- if factorization is not None: candidates_out[candidate] = factorization
+ if factorization is not None: candidates_out[x+chunk_start] = factorization.to_dict()