def main(argv): script, flag, filename = sys.argv if flag == '-e': coder.encode(filename, "_Encoded4.pi", coder.getPiWithFourHex(), 4) elif flag == '-d': coder.decode(filename, "_Decoded4.pi", coder.getPiWithFourHex(), 4)
def main(argv): script, flag, filename = sys.argv if flag == '-e': coder.encode(filename, filename + "_Encoded.pi", coder.getPiWithTwoHex(), 2) elif flag == '-d': coder.decode(filename, "_Decoded.pi", coder.getPiWithTwoHex(), 2)
def main(argv): script, flag, filename = sys.argv if flag == '-e': coder.encode(filename, filename+"_Encoded.pi", coder.getPiWithTwoHex(), 2) elif flag == '-d': coder.decode(filename, "_Decoded.pi", coder.getPiWithTwoHex(), 2)
def encode_text(): validation() file_name = file_entry.get() key = key_entry.get() text = text_box.get('1.0', END).strip() if not text: showerror(title='Ошибка', message='Введите текст') return encode(file_name, key, text) showinfo(title='Выполнено', message='Кодирование завершено')
def sendClientInfo(serial): """get mac, user name, serial and send encrypted data to server, and recieve result to use""" mac = str(uuid.getnode()) usr = getpass.getuser() data = mac + '/' + usr + '/' + serial data = coder.encode('monigota', data) newData = sendToServer(data) return newData
def sendClientInfo( serial ): """get mac, user name, serial and send encrypted data to server, and recieve result to use""" mac = str( uuid.getnode() ) usr = getpass.getuser() data = mac+'/'+usr+'/'+serial data = coder.encode( 'monigota', data ) newData = sendToServer( data ) return newData
def run(): # Create a TCP/IP socket to listen on server = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) # Prevent from "address already in use" upon server restart server.setsockopt( socket.SOL_SOCKET, socket.SO_REUSEADDR, 1 ) # Bind the socket to port 8081 on all interfaces server_address = ( 'localhost', 8081 ) print 'starting up on %s port %s' % server_address server.bind( server_address ) # Listen for connections server.listen( 5 ) while 1: # Wait for one incomming connection connection, client_address = server.accept() print 'connection from', connection.getpeername() # Let's receive something data = connection.recv( 4096 ) if not data: break #send it back nicely formatted data = coder.decode('monigota', data ) dbase = clm.ClientsManager() dataSplit = data.split( '/' ) mac = dataSplit[0] usr = dataSplit[1] serial = dataSplit[2] result = dbase.clientInstall( serial ) if result == True: print 'Received ', mac,usr,serial finalData = serial + '+' + mac + '+' + usr + 'monigota' finalData = coder.encode( 'gotamoni', finalData ) else: finalData = result connection.send( finalData ) print 'Response sent!' # close the connection from our side connection.shutdown( socket.SHUT_RD | socket.SHUT_WR ) connection.close() print "Connection closed." # And stop listening server.close()
def __init__(self,filename,output_filename ="motiondata"): self.TXT_VERSION = 1 print "-> reading input file .." f = open(filename,'r') lines = f.readlines() if self.TXT_VERSION: outputfile = open(output_filename+".dat","w") binfile = open(output_filename+".bin","wb") numsteps = 0 targetspeed = 0 beginspeed = 0 currentspeed = 0.0 prev_result = 0 eased_in_array = [] eased_out_array = [] resulting_speed_array = [] print "-> easing in .." for l in lines: if l[0] == "(": if "BEGIN_LINE" in l: beginspeed = int(l.split(",")[1]) targetspeed = int(l.split(",")[2]) numsteps = int(l.split(",")[3].replace(")\n","")) speed_incr = float(targetspeed-beginspeed)/float(numsteps) currentspeed = beginspeed else: if currentspeed < targetspeed: currentspeed += speed_incr eased_in_array.append(int(round(currentspeed))) print "-> easing out .." poscounter = 0L for p in reversed(lines): if p[0] == "(": if "END_LINE" in p: beginspeed = int(p.split(",")[1]) numsteps = int(p.split(",")[2].replace(")\n","")) index = len(eased_in_array) - numsteps - 1 - poscounter targetspeed = eased_in_array[index] speed_decr = float(targetspeed-beginspeed)/float(numsteps) currentspeed = beginspeed else: if currentspeed < targetspeed: currentspeed += speed_decr eased_out_array.append(int(round(currentspeed))) poscounter += 1 print "-> calculating speed profile .." counter = 0L error_counter = 0 for speed in reversed(eased_out_array): ease_in_value = eased_in_array[counter] ease_out_value = speed resulting_speed = min(499,ease_in_value,ease_out_value) delta = abs(prev_result - resulting_speed) if delta > 1: error_counter += 1 print "WARNING STEPPER JAM ERROR NO.",error_counter ,"DELTA : ",delta,"SPEED ",resulting_speed ,"LINE : ",counter,"IN-OUT",ease_in_value,"-",ease_out_value prev_result = resulting_speed resulting_speed_array.append(str(resulting_speed)) counter += 1 print "-> encoding binary .." linecounter = 0L for l in lines: if l[0] == "(": continue else: elems = l.split(",") left_engine = int(elems[0]) right_engine = int(elems[1]) sol1 = int(elems[2]) sol2 = int(elems[3]) sol3 = int(elems[4]) p1 = int(elems[5]) p2 = int(elems[6]) p3 = int(elems[7]) even = int(elems[8]) speed = int(resulting_speed_array[linecounter]) SAMPLE = struct.pack('=LLLL',coder.encode(left_engine,right_engine,p1,p2,p3,even,speed),sol1,sol2,sol3) binfile.write(SAMPLE) if self.TXT_VERSION: outputfile.write(l.replace("#",resulting_speed_array[linecounter])) linecounter += 1 if self.TXT_VERSION: outputfile.close() binfile.close()
#!/usr/bin/python import coder msg = "abcdefghz09'/?" print ">\n" + coder.encode(msg) + "<\n" print ">\n" + coder.decode(coder.encode(msg)) + "<\n"
def test_decode_inverts_encode(self, s): assert decode(encode(s)) == s
#!/usr/bin/env python import coder import sys msg = sys.argv[1] print coder.encode(msg),
filter_parser = subparsers.add_parser('filter') filter_parser.add_argument('-N', type=int, default=10) filter_parser.add_argument('-M', type=int, default=100) filter_parser.add_argument('-c', type=float, default=0.15) filter_parser.add_argument('--delay', type=int) channel_parser = subparsers.add_parser('channel') channel_parser.add_argument('--zero-delay', dest='zero_delay', type=int) channel_parser.add_argument('--one-delay', dest='one_delay', type=int) channel_parser.add_argument('--msg') channel_parser.add_argument('--path') channel_parser.add_argument('--warm', type=int, default=10) args = parser.parse_args() result = vars(args) if args.conf_type == 'filter': a = probability.calc(args.N, args.M, args.c) result['coeff'] = a else: if args.msg: msg = args.msg else: with open(args.path, 'r') as f: msg = f.read() result['msg'] = coder.encode(msg) with open(args.conf, 'w') as f: json.dump(result, f)