Skip to content

Instantly share code, notes, and snippets.

@HenrikBengtsson
Created November 7, 2016 01:43
Show Gist options
  • Save HenrikBengtsson/2b7b6a5d0bcda725dd5c5895c7f12513 to your computer and use it in GitHub Desktop.
Save HenrikBengtsson/2b7b6a5d0bcda725dd5c5895c7f12513 to your computer and use it in GitHub Desktop.
Example of homomorphic encryption and operators in R
## Example adopted and clarified from
## http://www.louisaslett.com/HomomorphicEncryption/
library("HomomorphicEncryption")
p <- pars("FandV")
k <- keygen(p)
## Unencrypted data
x <- c(42, 34)
y <- c(7, 5)
## Calculation on unencrypted data
z <- x + y
z
## Encrypted data
cx <- enc(k$pk, x)
cy <- enc(k$pk, y)
## You can safely send the encrypted data (cx, cy)
## to anyone in the world and ask them to perform
## the calculation for you.
cz <- cx + cy
## They will not be able to see the data nor the
## results because it's all encrypted throughout!
cz
## The person sends you back the encrypted results
## and you are the only one who can decrypt it.
z <- dec(k$sk, cz)
z
@bquast
Copy link

bquast commented Oct 6, 2022

is only it were possible to install this library

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment