-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathclient.py
More file actions
35 lines (26 loc) · 807 Bytes
/
client.py
File metadata and controls
35 lines (26 loc) · 807 Bytes
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
import requests
import binascii
import math
from gmpy2 import mpz, iroot
def send(name, sig):
url = "http://localhost:4242/api"
data = {
'sig': binascii.hexlify(sig),
'name': name,
}
return requests.get(url, params=data)
def to_bytes(n):
""" Return a bytes representation of a int """
return n.to_bytes((n.bit_length() // 8) + 1, byteorder='big')
def from_bytes(b):
""" Makes a int from a bytestring """
return int.from_bytes(b, byteorder='big')
def get_bit(n, b):
""" Returns the b-th rightmost bit of n """
return ((1 << b) & n) >> b
def set_bit(n, b, x):
""" Returns n with the b-th rightmost bit set to x """
if x == 0: return ~(1 << b) & n
if x == 1: return (1 << b) | n
def cube_root(n):
return int(iroot(mpz(n), 3)[0])