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
# 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() |
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 | |
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) |
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
# adapted from: https://asecuritysite.com/encryption/lwe4 | |
import sys | |
import numpy as np | |
import random | |
import math | |
nvals=20 | |
B=[] | |
e=[] |
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
# 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 |
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
# 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 |
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
# 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() |
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
# 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() |
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
## sigmoid function | |
sigmoid <- function(x, k=1, x0=0) | |
1 / (1+exp( -k*(x-x0) )) | |
## tanh^2 function | |
tanhsq <- function(x) | |
((exp(2*x)-1)^2)/((exp(2*x)+1)^2) | |
# define weights | |
Wa = matrix( c(0.45, 0.25), nrow=1 ); Ua = matrix(0.15); ba = matrix(0.20) |
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
# sigmoid function | |
sigmoid <- function(x) | |
1 / (1 + exp(-x) ) | |
# sigmoid derivative | |
sigmoid_output_to_derivative <- function(x) | |
x*(1-x) | |
# hidden layer size | |
hidden_dim = 4 |
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
# define some functions | |
## convert integer to binary | |
i2b <- function(integer, length=8) | |
as.numeric(intToBits(integer))[1:length] | |
## apply | |
int2bin <- function(integer, length=8) | |
t(sapply(integer, i2b, length=length)) |