def main(): parser = create_parser() args = parser.parse_args(sys.argv[1:]) if args.message is not None: message.encode_message(args.message, args.password, args.decode) elif args.file is not None: file.encode_file(args.file, args.out, args.password, args.decode) else: raise ParameterException( "Need message or file parameter, add -h to show help")
def main(): parser = create_parser() args = parser.parse_args(sys.argv[1:]) enigma = Enigma(args.seed) if args.message is not None: message.encode_message(enigma, args.message) elif args.file is not None: file.encode_file(enigma, args.file, args.out) else: raise ParameterException( "Need message or file parameter, add -h to show help")
def main(): parser = create_parser() args = parser.parse_args(sys.argv[1:]) rsa = RSA(p=args.p, q=args.q, seed=args.seed) print("P:", rsa.p) print("Q:", rsa.q) print("N:", rsa.n) print("E:", rsa.e) print("D:", rsa.d) if args.message is not None: message.encode_message(args.message, rsa, args.decode) elif args.file is not None: file.encode_file(args.file, args.out, rsa, args.decode) else: raise ParameterException( "Need message or file parameter, add -h to show help")
def __send_udp_broadcast_sync(sender_name, sender_ip, message_type): if message_type not in message_types.UDP_OPTIONS: raise ValueError('Only message_type DISCOVER or GOODBYE is accepted.') message_to_send = message.encode_message( sender_name, sender_ip, message_type, ) with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s: s.bind(('', 0)) s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) s.sendto(message_to_send, ('<broadcast>', common.PORT))
def __send_tcp_message_sync(sender_name, sender_ip, message_type, receiver_ip, message_payload): if message_type in message_types.UDP_OPTIONS: raise ValueError('message_type DISCOVER or GOODBYE is not accepted.') message_to_send = message.encode_message(sender_name, sender_ip, message_type, message_payload) success = False with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: try: s.settimeout(common.TIMEOUT) s.connect((receiver_ip, common.PORT)) s.sendall(message_to_send) success = True except: pass return success
def update(self): offs = 0 for c in self.out_commands: offs = message.encode_message(self.buffer, offs, c) self.out_commands = [] self.connection.send(self.buffer[:offs]) offs = 0 while True: tup = message.decode_message(self.connection.received_data, offs) offs, msg = tup[0], tup[1:] if msg[0] == message.MESSAGE_NONE: break else: self.in_commands.append(msg) if offs: self.connection.received_data = self.connection.received_data[offs:]
def update(self): if not self.isopen(): raise NotConnected() sl = [self.sock] readable, writable, error = select.select(sl, sl, sl, 0) if readable: r = self.sock.recv(2048) if not len(r): error.append(sl) else: self.inputdata.extend(r) if writable and self.out_messages: outputdata = bytearray(1024 * 4096) offs = 0 for m in self.out_messages: print ('Client sent', m) offs = message.encode_message(outputdata, offs, m) self.out_messages = [] if offs: n = self.sock.send(outputdata[:offs]) if n < 1: error.append(sl) #if error: # self.sock.close() # self.sock = None offs = 0 while True: tup = message.decode_message(self.inputdata, offs) offs, msg = tup[0], tup[1:] if msg[0] != message.MESSAGE_NONE: self.in_messages.append(msg) else: break; if offs: self.inputdata = self.inputdata[offs:]