-
Notifications
You must be signed in to change notification settings - Fork 0
/
placesOperations.py
33 lines (22 loc) · 978 Bytes
/
placesOperations.py
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
import math
from constants import PLACE_TYPE_SIZE
from cryptoOperations import sha512HashFromIdPassphrase
# Sort by ID depending on the passphrase
def sortPlaces(places, passphrase):
for place in places:
place["sortId"] = sha512HashFromIdPassphrase(place["id"], passphrase)
places = sorted(places, key=lambda d: d['sortId'])
for place in places:
del place["sortId"]
return places
# Takes an array of coordinates, and calculate tha maximun capacity
# OUTPUT: number of bytes
def calculateBytesCapacity(places):
bitsSize = 0
for place in places:
bitsSize += PLACE_TYPE_SIZE[place["type"]]
maxCipherTextSize = math.floor(bitsSize / 8)
reduncyRatio = 4/5
numBlocks = 15
maxPlainTextSize = maxCipherTextSize * reduncyRatio - 64 + numBlocks
return math.floor(maxPlainTextSize * 0.8) # A margin is requiered, just in case a point cannot be used to exfiltrate information