This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def base64_unit(input_bytes): | |
base64_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" | |
padding = {1: 2, 2: 1, 0: 0}[len(input_bytes) % 3] | |
while len(input_bytes) < 3: | |
input_bytes += b'\x00' | |
num = int.from_bytes(input_bytes, byteorder='big') | |
o = [] | |
count = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import select | |
import os | |
import fcntl | |
import threading | |
buffer_size = 1024 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import os | |
import array | |
def send_fd(sock, fd): | |
"""Send a file descriptor to another process via a Unix domain socket.""" | |
fds = array.array("i", [fd]) | |
sock.sendmsg([b"x"], [(socket.SOL_SOCKET, socket.SCM_RIGHTS, fds)]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import select | |
def test(): | |
c = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
c.connect(("", 8877)) | |
c.send(b"hello world") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### SIDH | |
### https://nbviewer.org/url/defeo.lu/docet/assets/jupyter/2018-03-22-PostScryptum.ipynb | |
p = 431 | |
F.<i> = GF(p^2, modulus=x^2+1) | |
E = EllipticCurve(F, [1, 0]) | |
E.order() == (p+1)^2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import hashlib | |
p = 2**256-2**32-977 | |
g = 2 | |
sk = random.randint(1, p-1) | |
pk = pow(g, sk, p) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sage.stats.distributions.discrete_gaussian_lattice import DiscreteGaussianDistributionLatticeSampler | |
def test_lwe(n, p, sigma, size=100): | |
F = GF(p) | |
a = random_vector(F, n) | |
HALF_P = int(p/2) | |
s = random_vector(F,n) | |
p41 = int(p/4) | |
p43 = int(p*3/4) | |
D = DiscreteGaussianDistributionLatticeSampler(F^1, sigma) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
P = next_prime(2^256) | |
N = 64 | |
k = 16 | |
BOUND = 32 | |
HALF_P = int(P/2+0.5) | |
R.<x> = PolynomialRing(GF(P), 'x') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scipy.cluster.vq import vq, kmeans | |
from scipy.spatial.distance import cdist | |
import numpy as np | |
class PQ(object): | |
def __init__(self, M, k): | |
self.M = M | |
self.k = k | |
def fit(self, vectors, iter=None): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scipy.cluster.vq import vq, kmeans | |
import numpy as np | |
class PQ(object): | |
def __init__(self, M, k): | |
self.M = M | |
self.k = k | |
def fit(self, vectors, iter=None): | |
assert vectors.ndim == 2, "vectors must be 2 dim array" |
NewerOlder