forked from Georeactor/encrypted-geofence
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (29 loc) · 960 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const fs = require('fs');
const bn = require('jsbn');
const phe = require('homomorphicjs');
module.exports = function (box, g, n, lat, lng, callback) {
console.log(g);
console.log(n);
var public_key = new phe.PublicKey(new bn(g), new bn(n));
console.log(public_key);
var xmin = Math.round(box[0] * 1000);
var ymin = Math.round(box[1] * 1000);
var xmax = Math.round(box[2] * 1000);
var ymax = Math.round(box[3] * 1000);
console.log('coords');
xmin = public_key.raw_encrypt(xmin);
ymin = public_key.raw_encrypt(ymin);
xmax = public_key.raw_encrypt(xmax);
ymax = public_key.raw_encrupt(ymax);
console.log('encrypted box');
var lat = new bn(lat);
var latoffset1 = lat.subtract(ymin);
var latoffset2 = lat.subtract(ymax);
var lng = new bn(lng);
var lngoffset1 = lat.subtract(xmin);
var lngoffset2 = lat.subtract(xmax);
callback(null, {
lat: [latoffset1, latoffset2],
lng: [lngoffset1, lngoffset2]
});
};