{{ message }}

Instantly share code, notes, and snippets.

Bastiaan Quast bquast

Created Feb 10, 2021
View simple-self-attention.R
 # logsumexp logsumexp <- function (x) { y = max(x) y + log(sum(exp(x - y))) } # softmax softmax <- function (x) { exp(x - logsumexp(x)) }
Created Jan 22, 2020
View gf
Created Nov 11, 2019
View tensor.R
 # contructor function tensor <- function(x) { # check that it's numeric if (!is.numeric(x)) stop("X must be numeric") # create the array and change the class y <- structure(array(x), class = "tensor") # add attributes attributes(y)\$creators <- list()
Last active Jul 29, 2019
View Ring-Learning-With-Errors.py
 import numpy as np import sys def gen_poly(n,q): global xN_1 l = 0 #Gamma Distribution Location (Mean "center" of dist.) poly = np.floor(np.random.normal(l,size=(n))) while (len(poly) != n): poly = np.floor(np.random.normal(l,size=(n))) poly = np.floor(p.polydiv(poly,xN_1)[1]%q)
Last active Jul 29, 2019
View Homomorphic-Encryption-Learning-With-Errors-Buchanan.py
 # adapted from: https://asecuritysite.com/encryption/lwe4 import sys import numpy as np import random import math nvals=20 B=[] e=[]
Created Jul 25, 2019
View Paillier.m
 # define some functions # modular exponentiation # source: https://gist.github.com/ttezel/4635562 function result = modexp (x, y, n) %anything raised to 0th power = 1 so return 1 if (y == 0) result = 1; return; end
Created Jul 19, 2019
View Paillier-BuchananExample.py
 # Author: Bill Buchanan # source: https://asecuritysite.com/encryption/pal_ex from random import randint import sys def gcd(a,b): """Compute the greatest common divisor of a and b""" while b > 0: a, b = b, a % b
Last active Aug 16, 2019
Paillier Cryptosystem for E-voting (using RSA) in R
View Paillier.R
 # Paillier cryptosystem in R # Bastiaan Quast # install and load the GNU Multiple Percision Arithmetic R package install.packages('gmp') library(gmp) # define parameters # p and q are private to the Inspector Inspector = list()
Created Jul 18, 2019
Basic example of the RSA algorithm in R
View RSA.R
 # RSA example # # Bastiaan Quast # International Telecommunication Union # bastiaan.quast@itu.int # Two people - Alice and Bob - want to communicate privately # A third person Eve wants to read the private communication Alice = list() Bob = list()
Last active Jul 3, 2019
Fibonacci printing C program (while x < 255). Compile using: gcc fib.c -o fib
View fib.c
 #include int main(void) { int x, y, z; while (1) { x = 0; y = 1; do { printf("%d\n", x);