def main(): if rank == 0: m = int(input("count of subarray:")) n = int(input("count of elements:")) if n != p: print("count of elements should be equals to count of processes") return 0 array = [[random.randint(-1000000, 1000000) for _ in range(n)] for _ in range(m)] responses = [multiple(array[:][0])] for i in range(1, n): vector = [] for j in range(m): vector.append(array[j][i]) send(data=vector, dest=i) responses.append(receive(source=i)) print(sum(responses)) else: parent_rank = 0 vector = receive(source=parent_rank) send(data=multiple(vector), dest=parent_rank)
def main(): if rank == 0: n = int(input("n: ")) if n <= p: print("count of elements should be more than count of processes") return 0 array = [random.randint(-100000000, 100000000) for _ in range(n)] # S count of elements for per process = N count of elements / P count of processes # and round to the nearest integer s = round(n / p) # processes minimum mins = [min(array[:s])] for pi in range(1, p): start = pi * s end = start + s send(data=array[start:end], dest=pi) mins.append(receive(source=pi)) print("processes mins:", mins) print("final:", min(mins)) else: parent_process = 0 array = receive(source=parent_process) min_num = min(array) send(data=min_num, dest=parent_process)
def server_handle(server): server.bind(ADDR) server.listen() print(f'[SERVER UPDATE] Server is running and listening on port {PORT}') conn, addr = server.accept() print(f'[SERVER CONNECTION UPDATE] Connected to {addr}') print('[SERVER INFO] Waiting for initiation message') initiated = False while not initiated: initiated = initiate(conn) print( f'[SERVER CONNECTION UPDATE] Received initiation message from {addr}') connected = True while connected: message = receive(conn) if not message is None: if message == DISCONNECT_MESSAGE: connected = False else: global game response = game.get_info() send(conn, response) print(message) print(f'[SERVER CONNECTION UPDATE] {addr} disconnected') conn.close()
def accept_incoming_connections(self): info(logger, "Waiting for incoming connections") while True: c, addr = self.s.accept() info(logger, "Incoming connection from", addr) request = int(recv(c)) info(logger, "Request Code", request, "was received") # 1 - request new uuid if request == 1: info(logger, "Code", request, "means that a new uuid was requested by the client") while True: new_uuid = uuid.uuid4() if not database.check_for_uuid(new_uuid): break info(logger, "Generated new uuid -", new_uuid) send(c, new_uuid) password = recv(c) info(logger, "Received password") c.close() info(logger, )
def main(): data = None if rank == p - 1: data = 125 send(data, rank - 1) else: data = receive(rank + 1) if rank != 0: send(data, rank - 1) print(rank, data)
def main(): if p % 2 != 0: print("n должно быть четным") return if rank % 2 == 0: data = random.randint(1, 10) send(data, rank + 1) else: data = receive(rank - 1) display(rank, data, "sending to rank 0") send(data, 0) if rank == 0: data = 0 for i in range(1, p, 2): data += receive(i) display(rank, data, "final result")
def client_handle(client): client.connect(ADDR) print('[CLIENT CONNECTION UPDATE] Connected to the server') initiated = False send(client, INITIATION_MESSAGE) connected = True message = INITIATION_MESSAGE while connected: if message == DISCONNECT_MESSAGE: connected = False else: global game game.update(message) response = datetime.now() send(client, response) print(message) message = receive(client) print('[CLIENT CONNECTION UPDATE] Disconnecting from the server') client.close()
def send_user_his_message(message): if check(message.chat.username): msg = bot.send_message(message.chat.id, send(message), reply_markup=markups.my_message_markup) bot.register_next_step_handler(msg, process_my_message) else: bot.send_message( message.chat.id, "У вас ещё не созданного сообщения. Для того, чтобы его создать введите " "\"Добавить сообщение\".")
def handle_text(message): if message.text in LIST_OF_COMMANDS: from functions import send send(message, LIST_OF_COMMANDS[message.text], bot) elif message.text == 'Тарелки': from telebot import types markup = types.ReplyKeyboardMarkup(True, True) itembtn1 = types.KeyboardButton('Плоские тарелки') itembtn2 = types.KeyboardButton('Глубокие тарелки') markup.add(itembtn1, itembtn2) bot.send_message(message.chat.id, "Выберите интересующий тип", reply_markup=markup) elif message.text == 'Вернуться в каталог': get_text_messageCatalog(message) elif message.text == 'Сделать заказ': from telebot import types markup = types.ReplyKeyboardMarkup(True, True, True) itembtn1 = types.KeyboardButton("Хочу чтобы со мной связались", request_contact=True) itembtn2 = types.KeyboardButton("Я сам напишу") markup.add(itembtn1, itembtn2) bot.send_message(message.chat.id, "Выбери способ заказа", reply_markup=markup) elif message.text == 'Я сам напишу': from telebot import types button1 = types.InlineKeyboardButton(text="Меню", callback_data="menu") markup = types.InlineKeyboardMarkup() markup.add(button1) bot.send_message( message.chat.id, 'Твое письмо уже ждут по адресу @annjuniper' + "\n" + "Можешь в добавок просто переслать изделие которое понравилось", reply_markup=markup) else: bot.send_message( message.chat.id, 'Я тебя не понимаю :(' + "\n" + "Воспользуйся командой /help")
def __init__(self): application.frame = self self.last_review = [0.0, None, None] super(MainFrame, self).__init__(None, title = application.name) self._review = 0 # The current position of the review cursor. self.commands = [] # Command history. self._command_pos = 0 # The current position in the command history. p = wx.Panel(self) self.CreateStatusBar() self.SetStatusText('Not connected.') s = wx.BoxSizer(wx.VERTICAL) self.output = MyTextCtrl(p, style = wx.TE_READONLY | wx.TE_MULTILINE) s.Add(self.output, 1, wx.GROW) s1 = wx.BoxSizer(wx.HORIZONTAL) self.prompt = wx.StaticText(p, label = '&Entry') s1.Add(self.prompt, 0, wx.GROW) self.entry = wx.TextCtrl(p, style = wx.TE_RICH2) self.entry.SetFocus() s1.Add(self.entry, 1, wx.GROW) s.Add(s1, 0, wx.GROW) p.SetSizerAndFit(s) keys.add_accelerator(self.entry, 'RETURN', self.do_send) keys.add_accelerator(self.entry, 'ESCAPE', lambda event: self.do_clear(save = True)) keys.add_accelerator(self.entry, 'UP', lambda event: self.do_command_history(self._command_pos - 1)) # Commands are entered using append. keys.add_accelerator(self.entry, 'DOWN', lambda event: self.do_command_history(self._command_pos + 1)) keys.add_accelerator(self.entry, 'CTRL+HOME', lambda event: self.do_command_history(-1)) keys.add_accelerator(self.entry, 'CTRL+END', lambda event: self.do_command_history(0)) keys.add_accelerator(self.entry, 'SHIFT+RETURN', lambda event: self.do_send(event, clear = False)) keys.add_accelerator(self.entry, 'CTRL+RETURN', lambda event: functions.send(self.commands[0]) if self.commands else functions.bell()) for x in xrange(10): keys.add_accelerator(self, 'ALT+%s' % x, lambda event, i = x: self.do_review(-10 if not i else (i * -1), move = False)) keys.add_accelerator(self, 'ALT+%s' % x, lambda event, i = x: self.output.SpeakLineText(10 if not i else i)) keys.add_accelerator(self, 'CTRL+SHIFT+Y', lambda event: self.do_review(0)) keys.add_accelerator(self, 'CTRL+SHIFT+P', lambda event: self.do_review(-1)) keys.add_accelerator(self, 'CTRL+SHIFT+U', lambda event: self.do_review(max(self._review - 1, 0))) keys.add_accelerator(self, 'CTRL+SHIFT+I', lambda event: self.do_review(self._review)) keys.add_accelerator(self, 'CTRL+SHIFT+O', lambda event: self.do_review(self._review + 1)) functions.output('Welcome to %s (V%s).\nType %scommands() for help with builtin functions.' % (application.name, application.version, application.config.get('application', 'command_char'))) mb = wx.MenuBar() self.file_menu = wx.Menu() self.Bind(wx.EVT_MENU, self.do_load, self.file_menu.Append(wx.ID_ANY, '&Load Script...', 'Load a script.')) self.Bind(wx.EVT_MENU, lambda event: application.config.get_gui().Show(True), self.file_menu.Append(wx.ID_PREFERENCES, '&Preferences...', 'Change program configuration.')) self.Bind(wx.EVT_MENU, lambda event: functions.quit(), self.file_menu.Append(wx.ID_EXIT, '&Quit', 'Quit the program.')) mb.Append(self.file_menu, '&File') self.connect_menu = wx.Menu() self.Bind(wx.EVT_MENU, lambda event: do_connect(), self.connect_menu.Append(wx.ID_ANY, '&Connect...', 'Create a new connection.')) self.Bind(wx.EVT_MENU, lambda event: functions.disconnect(), self.connect_menu.Append(wx.ID_ANY, '&Disconnect', 'Disconnect from the MUD.')) mb.Append(self.connect_menu, '&Connect') self.SetMenuBar(mb) self.Bind(wx.EVT_CLOSE, self.on_close)
def main(): if rank == 0: try: data = int(input("Введите число: ")) send(data * 2, rank + 1) data = receive(p - 1) print(data) except: send(0, rank + 1) data = receive(p - 1) print("Произошла ошибка", data) else: data = receive(rank - 1) if rank == p - 1: send(data * 2, 0) else: send(data * 2, rank + 1)
# A encrypt msg and decrypt it msg = rsa.random.randint(2, 99999) C = rsa.encrypt(msg, e, n) decrypted_msg = rsa.decrypt(C, d, n) print("\n\n local test for encryption and decryption\n\nmsg is: " + str(msg) + "\nEncrypted msg is: " + str(C) + "\nDecrypted msg is: " + str(decrypted_msg)) print("\n\n--------------------------------------- local check for signing and verification --------------------------" "-------------\n\n") # A send signed msg to B msg = rsa.random.randint(2, 99999) print("msg is: " + str(msg)) signed_msg = rsa.send(msg, n1, e1, d, n) print("encrypted msg is:" + signed_msg[0] + "\nsignature is: " + signed_msg[1]) # B received signed_msg and knows e and n [check, k] = rsa.receive(signed_msg[0], signed_msg[1], n1, d1, e, n) if check: print("Signature is valid\nencrypted msg is: " + str(k)) else: print("invalid signature") print("\n\n--------------------------------------- user-server check for signing and verification" " ---------------------------------------\n\n") # exchange with server pub_k_request = f"http://asymcryptwebservice.appspot.com/rsa/serverKey?keySize=515"
def dir_call_back(src_entry): directory = (src_entry.get()) send(directory) messagebox.showinfo(message="Upload completed")
import sys import functions args = sys.argv entry_len = len(args) command = args[1] if command == "init": try: if entry_len == 2: print("Hello! This is the PySub - Receive version!\nConsult the README.md file to know how to config the enviroment and receive the submitions.") elif args[2] == "to-config": functions.to_config() elif args[2] == "from-config": functions.from_config() except Exception as error: print(f"Something went wrong... {error}") if command == "send": try: functions.send() except Exception as error: print(f"Something went wrong... {error}") if command == "received": try: functions.get_received() except Exception as error: print(f"Something went wrong... {error}")