예제 #1
0
def encrypt(username):
	print "-------------------------------------------"
	target_name = raw_input("Enter name of target : ")
	sql_command = "SELECT public_exp,modulus FROM main WHERE username LIKE '%s';" %target_name
	cursor.execute(sql_command)
	results = cursor.fetchall()


	exp = int(results[0][0])
	modulus = int(results[0][1])

	infilename = raw_input("Enter file to be encrypted : ")
	f = open(infilename, "r")
	text = ""

	for line in f.readlines():
		text = text + line

	c = Toolkit.encrypt(text,exp,modulus)

	outfilename = raw_input("Enter name of the file to store the encrypted message : ")
	f = open(outfilename, "w", 0)
	f.write(c)
	print "-------------------------------------------"
	print "Done! Your Encrypted file is ready."
	print "-------------------------------------------"

	enter_into_log(username,target_name,infilename,outfilename)

	start_session(username)
예제 #2
0
def decrypt(username):
	print "-------------------------------------------"
	sql_command = "SELECT private_exp,modulus FROM main WHERE username LIKE '%s'" %username
	cursor.execute(sql_command)
	result = cursor.fetchall()

	exp = int(result[0][0])
	modulus = int(result[0][1])


	infilename = raw_input("Enter name of file to be decrypted : ")
	f = open(infilename, "r")

	text = ""
	for line in f.readlines() :
		line = line.strip()
		text = text + line + "\n"

	m = Toolkit.decrypt(text,exp,modulus)

	if not(len(m) >0) :
		print "-------------------------------------------"
		print "Authentication Failure, This file is not for you"
		print "-------------------------------------------"
		start_session(username)

	else :
		outfilename = raw_input("Enter name of file to store decrypted message : ")
		f = open(outfilename, "w", 0)
		f.write(m)
		print "-------------------------------------------"
		print "Done! Your Decrypted file is ready."

	print "-------------------------------------------"
	start_session(username)
예제 #3
0
def signAll():
    for username,password in users.items():
        for i in range(5):
            status = sign(username,password)
            if status:
                print >>log,username + 'sign successfully'
                break
        else:
            print >>log, 'Error sign with '+username + '||' + str(datetime.datetime.now())
            Toolkit.notificationByMail('Error sign with '+username)
            return False

    print >>log, 'Successfully sign.' + '||' + str(datetime.datetime.now())
    Toolkit.notificationByMail('Successfully sign.')

    return True
예제 #4
0
    def post(self):
        print("Request in: \n")
        prettyJSON(self.args)
        if self.args["status"] == "empty":
            self.write(self.args)
        elif self.args["type"] == "blockMesh":
            opt = dict()
            opt["DIVI"] = [self.args["division"][0],
                           self.args["division"][1],
                           self.args["division"][2]]
            opt["NSEC"] = self.args["nsec"]
            opt["SQRRATIO"] = self.args["coeur"]
            opt["RQUAD"] = [self.args["centre"]]+self.args["sections"]
            opt["IMPELLERCUT"] = self.args["cuts"]

            bottom = self.args["bottom"]
            lvlrot = [bottom[0]]
            shaft = [1 if bottom[1] == "on" else 0]
            hlay = [bottom[2]]
            for level in self.args["vertical"]:
                lvlrot.append(level[0])
                shaft.append(1 if level[1] == "on" else 0)
                hlay.append(level[2])

            opt["LVLROT"] = lvlrot
            opt["HLAY"] = hlay
            opt["SHAFT"] = shaft

            self.args["data"] = sm.superMarine(opt)
            print("Answer:\n")
            prettyJSON(self.args)
            self.write(self.args)
        elif self.args["type"] == "python":
            opt = dict()
            opt["r"] = self.args["division"][0]
            opt["theta"] = self.args["division"][1]
            opt["z"] = self.args["division"][2]
            opt["nsec"] = self.args["nsec"]
            opt["sqratio"] = self.args["coeur"]
            opt["rquad"] = [self.args["centre"]]+self.args["sections"]
            opt["impellercut"] = self.args["cuts"]

            bottom = self.args["bottom"]
            lvlrot = [bottom[0]]
            shaft = [1 if bottom[1] == "on" else 0]
            hlay = [bottom[2]]
            for level in self.args["vertical"]:
                lvlrot.append(level[0])
                shaft.append(1 if level[1] == "on" else 0)
                hlay.append(level[2])

            opt["lvlrot"] = lvlrot
            opt["hlay"] = hlay
            opt["shaft"] = shaft

            self.args["data"] = tk.genSupM(opt)
            print("Answer:\n")
            prettyJSON(self.args)
            self.write(self.args)
예제 #5
0
def verify_signature(username) :
	infilename = raw_input("Enter name of the file : ")
	signature_filename = raw_input("Enter name of the signature file : ")

	name = raw_input("Enter name of creator : ")

	sql_command = "SELECT public_exp, modulus FROM main WHERE username like '%s'" %name
	cursor.execute(sql_command)
	result = cursor.fetchall()

	exp = int(result[0][0])
	modulus = int(result[0][1])

	file_text = ""
	f = open(infilename, "r")
	for line in f.readlines():
		file_text = file_text + line

	file_fingerprint = Toolkit.get_fingerprint(file_text)
	
	f = open(signature_filename, "r")
	signature_file_text = ""
	for line in f.readlines():
		signature_file_text = signature_file_text + line

	try :
		decrypted_signature = Toolkit.decrypt(signature_file_text, exp, modulus)

	except Exception :
		print "-------------------------------------------"
		print "Verification Failed"
		print "-------------------------------------------"
		start_session(username)

	if decrypted_signature == file_fingerprint :
		print "-------------------------------------------"
		print "Verification Successful!"
		print "-------------------------------------------"

	start_session(username)
예제 #6
0
def sign(username):
	print "-------------------------------------------"
	sql_command = "SELECT private_exp, modulus FROM main WHERE username like '%s'" %username
	cursor.execute(sql_command)
	result = cursor.fetchall()
	exp = int(result[0][0])
	modulus = int(result[0][1])

	infilename = raw_input("Enter name of file to be signed : ")
	f = open(infilename, "r")

	file_text = ""

	for line in f.readlines():
		file_text = file_text + line

	fingerprint = Toolkit.get_fingerprint(file_text)
	c = Toolkit.encrypt(fingerprint,exp,modulus)

	outfilename = raw_input("Enter name of file to store the signature : ")
	f = open(outfilename, "w", 0)
	f.write(c)
	start_session(username)
예제 #7
0
def add_recipents():
	print "-------------------------------------------"
	ch = raw_input("Add Recipent? [y/n] : ")
	if ch == "y" :
		username = raw_input("Enter recipent name : ")
		password = raw_input("Enter recipent password : "******"INSERT INTO main VALUES(\"" + username + "\", \"" + password + "\", \"" + str(e) + "\", \"" + str(d) + "\", \"" + str(n) + "\");"
			cursor.execute(sql_command)
			db.commit()
			print "-------------------------------------------"
			print "Success!"
			print "-------------------------------------------"

	else :
		pass
	print "-------------------------------------------"
def init_lcd():
    # 产生一个让LCD复位的低电平脉冲
    GPIO.output(LCD_RST, GPIO.LOW)
    Toolkit.delay_1us()
    GPIO.output(LCD_RST, GPIO.HIGH)

    # 关闭LCD
    GPIO.output(LCD_CE, GPIO.LOW)
    Toolkit.delay_1us()

    # 使能LCD
    GPIO.output(LCD_CE, GPIO.HIGH)
    Toolkit.delay_1us()

    write_byte(0x21, 0)  # 使用扩展命令设置LCD模式
    write_byte(0xa0, 0)  # 设置偏置电压
    write_byte(0x07, 0)  # 温度校正
    write_byte(0x17, 0)  # 1:48
    write_byte(0x20, 0)  # 使用基本命令
    clear()  # 清屏
    write_byte(0x0c, 0)  # 设定显示模式,正常显示

    # 关闭LCD
    GPIO.output(LCD_CE, GPIO.LOW)
예제 #9
0
import Toolkit
import tables
"""kaggle | drivedata | crowdanalytix | innocentive | codalab | crowdai | datahack - sql
numpy.loadtxt
numpy.genfromtxt
pandas.read_csv
pandas.read_pickle
"""


pd = Toolkit.initiate_pandas()
np = Toolkit.initiate_numpy()

""" creating dataframes"""
data = np.random.random(size=(5, 5))
print(data)

df = pd.DataFrame(data=data, columns=["A", "B", "C", "D", "E"])  # use this
print(df)

dtype = [('A', int), ("B", (str, 20))]
data = np.array([(1, "Sam"), (2, "Alex"), (3, "James")], dtype=dtype)
print(data)  # [(1, 'Sam') (2, 'Alex') (3, 'James')]
df = pd.DataFrame(data)
print(df)

data = {"A": [1, 2, 3], "B": ["Sam", "Alex", "James"]}  # and use this
df = pd.DataFrame(data)
print(df)

data = [{"A": 1, "B": "Sam"}, {"A": 2, "B": "Alex"},{"A": 3, "B": "James"}]  # too messy
예제 #10
0
import Toolkit
# https://pandas.pydata.org/pandas-docs/stable/user_guide/merging.html#
pd = Toolkit.initiate_pandas()

# outer join
df_a = pd.DataFrame({"A": ["x", "y", "z"], "B": [1, 2, 3]})
df_b = pd.DataFrame({"A": ["u", "v", "x"], "C": [5.0, 4.0, 3.0]})

print(df_a, "\n", df_b)
print(pd.merge(df_a, df_b, how="inner", on='A'))
"""
   A  B    C
0  x  1  3.0
"""
print(pd.merge(df_a, df_b, how="outer", on='A'))
"""
   A    B    C
0  x  1.0  3.0
1  y  2.0  NaN
2  z  3.0  NaN
3  u  NaN  5.0
4  v  NaN  4.0
"""
# duplicate keys

df_c = pd.DataFrame({"A": ["x", "x", "z"], "B": [1, 2, 3]})
df_d = pd.DataFrame({"A": ["u", "x", "x"], "C": [5.0, 4.0, 3.0]})

print(df_c)
print(df_d)
print(pd.merge(df_c, df_d, on='A'))
예제 #11
0
import Toolkit
import matplotlib

np = Toolkit.initiate_numpy()
pd = Toolkit.initiate_pandas(max_cols=20)
import matplotlib.pyplot as plt

df = pd.read_csv("files/csv/train.csv", low_memory=False,
                 parse_dates=["Date"])  # allow load all in to determine dtype
print(df.head(5))
# doublecheck dtypes with df.info()
print(df.info())
# dates is still just dtype object:  2   Date           1017209 non-null  object
# fix with parse_dates=["Date"]

# https://pandas.pydata.org/pandas-docs/stable/reference/groupby.html
dfg = df.groupby("Store")
# print(dfg.mean())
# put store back into the dataframe with reset_index()
print(dfg.mean().reset_index())
store_avg = dfg.mean()
store_avg = store_avg.reset_index()
# https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.plot.html
plt.style.use('dark_background')
store_avg.plot.scatter("Store", "Sales", s=3,
                       title="avg sale/store")  # s = point size
# plt.show()
plt.clf()  # clear current figure
# Multiple groups
# group in multiple categories
store_day = df.groupby(
예제 #12
0
def getToolkit(params):
    useQuad = params["formatQuadrature"]
    return t.getPrinter(useQuad)
예제 #13
0
def getToolkit(params):
    useQuad = params["formatQuadrature"]
    return t.getPrinter(useQuad)