def create_time_hash(time, tag, secret): key = base64.b64decode(secret) msg = time.to_bytes(8, 'big') + codecs.encode(tag) auth = hmac.new(key, msg, hashlib.sha1) code = base64.b64encode(auth.digest()) return codecs.decode(code)
def sc_lpn(): """ This method handles every message sent by the LORA sensors :return: """ print("Data received from ThingPark...") j = [] try: j = request.json except: print("Unable to read information or json from sensor...") print("JSON received:") print(j) tuino_list = ['78AF580300000485','78AF580300000506'] r_deveui = j['DevEUI_uplink']['DevEUI'] #Parse JSON from ThingPark payload = j['DevEUI_uplink']['payload_hex'] payload_int = int(j['DevEUI_uplink']['payload_hex'],16) bytes = bytearray.fromhex(payload) r_time = j['DevEUI_uplink']['Time'] r_timestamp = dt.datetime.strptime(r_time,"%Y-%m-%dT%H:%M:%S.%f+02:00") if sys.getsizeof(bytes)) == 1: if(bytes[0]=='t') ##send time headers_POST = "Content-type:application/x-www-form-urlencoded" time=int(time.time()) time_bytes = time.to_bytes(4, 'big') print('sending to LoRa'); params = {'DevEUI' = r_deveui, 'FPORT' = '1', 'Payload' = time_bytes }
def set_acc_dec_time(self, time): commando = b"\x10\x06\x00\x00\x02\x04" time = time.to_bytes(4, "big") commando = self.unit_id + commando + time crc = calc_crc16(commando) commando = commando + crc self.client.write(commando) result = self.client.read()
def _convert_to_bytes(self, objects, frame_millis): data_to_send = bytearray() for i in range(len(objects)): obj = objects[i] data_to_send.extend(obj.class_id.to_bytes(4, byteorder='little')) data_to_send.extend(obj.x.to_bytes(4, byteorder='little')) data_to_send.extend(obj.y.to_bytes(4, byteorder='little')) data_to_send.extend(obj.w.to_bytes(4, byteorder='little')) data_to_send.extend(obj.h.to_bytes(4, byteorder='little')) data_to_send.extend(obj.frame_id.to_bytes(4, byteorder='little')) frame_len = int(len(data_to_send)) frame_len = bytearray(frame_len.to_bytes(4, byteorder='little')) time = frame_millis time = time % self._max_u32_value time = bytearray(time.to_bytes(4, byteorder='little')) return frame_len + time + data_to_send
def process_image(self, image): frames = [] with Image.open(image) as img: picture_frames = [] palette = img.getpalette() try: while True: if not img.getpalette(): img.putpalette(palette) duration = img.info['duration'] new_frame = Image.new('RGBA', img.size) new_frame.paste(img, (0, 0), img.convert('RGBA')) picture_frames.append([new_frame, duration]) img.seek(img.tell() + 1) except EOFError: pass for pair in picture_frames: picture_frame = pair[0] time = pair[1] colors = [] pixels = [None] * self.size * self.size if time is None: time = 0 for pos in itertools.product(range(self.size), range(self.size)): y, x = pos r, g, b, a = picture_frame.getpixel((x, y)) if [r, g, b] not in colors: colors.append([r, g, b]) color_index = colors.index([r, g, b]) pixels[x + self.size * y] = color_index colorCount = len(colors) if colorCount >= 256: colorCount = 0 timeCode = [0x00, 0x00] if len(picture_frames) > 1: timeCode = time.to_bytes(2, byteorder='little') frame = [] frame += timeCode frame += [0x00] frame += colorCount.to_bytes(1, byteorder='big') for color in colors: frame += self.convert_color(color) frame += self.process_pixels(pixels, colors) frames.append(frame) result = [] for frame in frames: result.append(self.make_frame(frame)) return result
addressHash = crypto.hashChain(crypto.str2bytes(unhashedAddress))[0:4] address2 = crypto.str2bytes(unhashedAddress + addressHash) pywaves.setNode(node = 'http://52.30.47.67:6869', chain = 'testnet') myAddress = pywaves.Address(seed=seed_str) #print(myAddress.balance()) #myAddress.sendWaves(recipient = pywaves.Address('3NBVqYXrapgJP9atQccdBPAgJPwHDKkh6A8'), amount = 300000000) time = int(time.time() * 1000) #constructing Tx comp = { 't_type' : b'\4', 'k_pub' : k_pub, 'amount_flag' : b'\0', 'fee_flag' : b'\0', 'timestamp' : time.to_bytes(8, byteorder='big'), #'timestamp' : (1479287120875).to_bytes(8, byteorder='big') 'amount' : (100000000).to_bytes(8, byteorder='big'), 'fee' : (100000).to_bytes(8, byteorder='big'), 'recip_address' : b58decode('3NBVqYXrapgJP9atQccdBPAgJPwHDKkh6A8'), 'att' : (4).to_bytes(2, byteorder='big'), 'att_bytes' : b58decode('2VfUX') } tx = b'' for key, value in comp.items(): #print("{0}: {1}".format(key, b58encode(value))) tx += value #print(b58encode(tx)) randm64 = os.urandom(64) sign = curve.calculateSignature(randm64, k_pr, tx)
def setLastUsed(pagenr, time): byte12 = time.to_bytes(2, byteorder="big") byte3 = struct[pagenr][2].to_bytes(1, byteorder="big") byte123 = byte12[0].to_bytes(1, byteorder="big") + byte12[1].to_bytes( 1, byteorder="big") + byte3[0].to_bytes(1, byteorder="big") struct[pagenr] = byte123
#compute Address ver = bytes([1]) scheme = b'\x54' # \x57 for mainnet, \x54 for testnet k_pub_hash = SecureHash(k_pub)[:20] checksum = SecureHash(ver + scheme + k_pub_hash)[0:4] address = ver + scheme + k_pub_hash + checksum time = int(time.time() * 1000) #constructing Tx components = { 't_type': b'\4', 'k_pub': k_pub, 'amount_flag': b'\0', 'fee_flag': b'\0', 'timestamp': time.to_bytes(8, byteorder='big'), 'amount': (100000000).to_bytes(8, byteorder='big'), 'fee': (100000).to_bytes(8, byteorder='big'), 'recip_address': b58decode('3NBVqYXrapgJP9atQccdBPAgJPwHDKkh6A8'), 'att': (4).to_bytes(2, byteorder='big'), 'att_bytes': b58decode('2VfUX') } tx = b'' for key, value in components.items(): tx += value #sign tx randm64 = os.urandom(64) sign = curve.calculateSignature(randm64, k_pr, tx) #prepare data for broadcast