Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import *
- import inflect
- import socket
- import time
- def get(s):
- return s.recv(1024).decode()
- def text2int(textnum, numwords={}):
- if not numwords:
- units = [
- "zero", "one", "two", "three", "four", "five", "six", "seven", "eight",
- "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen",
- "sixteen", "seventeen", "eighteen", "nineteen",
- ]
- tens = ["", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"]
- scales = ["hundred", "thousand", "million", "billion", "trillion"]
- numwords["and"] = (1, 0)
- for idx, word in enumerate(units): numwords[word] = (1, idx)
- for idx, word in enumerate(tens): numwords[word] = (1, idx * 10)
- for idx, word in enumerate(scales): numwords[word] = (10 ** (idx * 3 or 2), 0)
- current = result = 0
- for word in textnum.split():
- if word not in numwords:
- raise Exception("Illegal word: " + word)
- scale, increment = numwords[word]
- current = current * scale + increment
- if scale > 100:
- result += current
- current = 0
- return result + current
- p = inflect.engine()
- flag=''
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- s.connect(("18.216.59.235",7747))
- print(get(s))
- print(get(s))
- s.send('\n'.encode())
- flag+=s.recv(1024).decode()
- print("flag is: "+flag)
- while 1:
- data = s.recv(1024).decode()
- print("data is: " + data)
- try:
- data = int(data)
- except Exception:
- try:
- math_eval=str(eval(data))
- math_eval+='\n'
- print("sending: "+math_eval)
- s.send(math_eval.encode())
- print('sent')
- continue
- except Exception:
- try:
- data= data.replace(',','')
- data=data.replace('-',' ')
- num = str(text2int(data))
- num+='\n'
- print("sending: "+ num)
- s.send(num.encode())
- print('sent')
- continue
- except Exception:
- print('Cannot continue from here!')
- break
- words=(p.number_to_words(data))
- print("sending: "+words)
- words+='\n'
- s.send(words.encode())
- print('sent')
- s.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement