Skip to content

Instantly share code, notes, and snippets.

Avatar

Bastiaan Quast bquast

View GitHub Profile
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))
}
View gf
https://photos.app.goo.gl/DK4FrQPWradbxxsYA
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()
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)
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=[]
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
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
@bquast
bquast / Paillier.R
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()
@bquast
bquast / RSA.R
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()
@bquast
bquast / fib.c
Last active Jul 3, 2019
Fibonacci printing C program (while x < 255). Compile using: gcc fib.c -o fib
View fib.c
#include <stdio.h>
int main(void) {
int x, y, z;
while (1) {
x = 0;
y = 1;
do {
printf("%d\n", x);