Skip to content

Instantly share code, notes, and snippets.

View th0rex's full-sized avatar

Timo von Hartz th0rex

View GitHub Profile
@th0rex
th0rex / gf_mul.py
Last active April 19, 2018 09:10
#!/usr/bin/python3
import functools
# 1+0x+x^2+0x^3+0x^4+x^5
p = [1, 0, 1, 0, 0, 1]
def format_polynom(xs):
return " + ".join(reversed([("x^{}".format(i) if i > 0 else "1") for i, x in enumerate(xs) if x == 1]))
// clang++ -std=c++17 baby_giant_step.cpp -o baby_giant_step -march=native -O3
// ./baby_giant_step
#include <cmath>
#include <cstdint>
#include <cstdlib>
#include <unordered_map>
#include <utility> // std::swap
struct result {
def eea(r0, r1):
if r0 <= r1:
r0, r1 = r1, r0
r = [r0, r1, 0]
s = [1, 0, 0]
t = [0, 1, 0]
i = 2
#ifndef ALTERNATIVELINKEDLIST_H
#define ALTERNATIVELINKEDLIST_H
#include "Item.h"
#include "List.h"
/*
* Deklariert hier die AlternativeLinkedList ohne Dummy-Element.
*
* Diese Liste soll keine FreeList verwenden, denn die move-Methoden
@th0rex
th0rex / elgamal.py
Last active September 3, 2018 09:39
#!/usr/bin/env python
# -*- vim: set sts=4 sw=4 fdm=marker: -*-
# Please put in your name and id number here
# Name:
# Matrikelnummer:
from collections import defaultdict
from functools import reduce
@th0rex
th0rex / mindiff.hs
Last active May 27, 2018 16:14
some haskell exercises
#! /usr/bin/runhaskell
import Control.Monad
import Data.List
mapSucc :: (a -> a -> b) -> [a] -> [b]
mapSucc _ [] = []
mapSucc f [x] = error "can't call mapSucc with a list of only one element"
mapSucc f [x, y] = [f x y]
mapSucc f (x:y:xs) = f x y : mapSucc f (y:xs)
#[async(boxed, send)]
fn program_main(state: State) -> Result<(), Never> {
// Hack to make sure sessions is only created on the polling thread.
await!(futures::future::ok::<(), Never>(()))?;
let mut sessions: Vec<Session> = vec![];
#[async]
for cmd in state.command_rx {
use UICommand::*;
fn parity(xs: &[u8]) -> u64 {
let mut ret = 0u64;
for (i, _) in xs.iter().enumerate() {
let mut acc = 0;
for j in i..i + 8 {
let x = xs[j % xs.len()];
acc ^= (x >> (7 - ((i + 1) % 8))) & 0b1;
}
ret |= (acc as u64) << (xs.len() - (i+1));
# [y][x]
rot_table = [
[0, 1, 62, 28, 27],
[36, 44, 6, 55, 20],
[3, 10, 43, 25, 39],
[41, 45, 15, 21, 8],
[18, 2, 61, 56, 14],
]
@th0rex
th0rex / vm.sh
Last active October 11, 2018 12:35
#!/usr/bin/bash
# Start:
# sudo ./vm.sh
# Connect:
# sudo spicy --uri="spice+unix:///tmp/vm_spice.socket"
NET_OPTIONS="-net none" && [[ $1 == "--enable-net" ]] && NET_OPTIONS="-netdev user,id=default,net=10.0.2.0/24,dhcpstart=10.0.2.9 -device virtio-net-pci,netdev=default,mac=00:16:3e:00:01:01 -net nic -net user,smb=/vm/"
qemu-system-x86_64 \