def auth(sid, data): # decrypting data keys = db.getKeys() data['status'] = func.decrypt(keys['privKey'], unhexlify(data['status'])) data['time'] = func.decrypt(keys['privKey'], unhexlify(data['time'])) # update status db.updateStatus(data['devId'], data['status']) # encrypting data deviceInfo = db.getDeviceInfo(str(data['devId'])) data['status'] = hexlify( func.encrypt(str(deviceInfo['pubKey']), data['status'])) data['time'] = hexlify( func.encrypt(str(deviceInfo['pubKey']), data['time'])) sio.emit(str(data['devId']), data)
def login_button_function(self): user_mes = { 'ID': self.login.accountInput.text(), 'PASSWORD': func.encrypt(self.login.passwordInput.text()) } self.user = func.signin(user_mes) if self.user is not None: self.login.setVisible(False) self.display() else: print('登录失败!')
def signup_function(self): self.user = self.signup.getInfo() res = func.check_user_info(self.user) if res['res'] == 'fail': self.errorBox(res['reason']) return self.user['max_book'] = int(self.user['max_book']) self.user['password'] = func.encrypt(self.user['password']) ans = func.signup(self.user) self.user['class'] = 'stu' self.user.pop('password') if ans: self.signup.setVisible(False) print('成功') self.display() else: self.errorBox('注册失败')
def submitFunction(self): if not self.maxNumInput.text().isalnum(): print('最大数量输入错误') return if self.passwordInput.text() != self.passwordInput.initText: if self.passwordInput.text() != self.repPasswordInput.text(): msgBox = QMessageBox(QMessageBox.Warning, "错误!", '两次输入密码不一致!', QMessageBox.NoButton, self) msgBox.addButton("确认", QMessageBox.AcceptRole) msgBox.exec_() return self.stu_info['password'] = func.encrypt(self.passwordInput.text()) self.stu_info['sname'] = self.nameInput.text() self.stu_info['dept'] = self.deptInput.text() self.stu_info['majority'] = self.majorInput.text() self.stu_info['max_book'] = int(self.maxNumInput.text()) self.close() self.after_close.emit(self.stu_info)
def saveFunction(self): if self.passwordInput.text() != self.repPasswordInput.text(): print('密码不一致') return if not self.maxNumInput.text().isalnum(): print('最大数量输入错误') return if self.passwordInput.text() != '******': self.stu_mes['password'] = func.encrypt(self.passwordInput.text()) self.stu_mes['sname'] = self.nameInput.text() self.stu_mes['dept'] = self.deptInput.text() self.stu_mes['majority'] = self.majorInput.text() self.stu_mes['max_book'] = int(self.maxNumInput.text()) if not func.update_student(self.stu_mes): print('更新失败') return self.save.setEnabled(False) self.nameInput.setEnabled(False) self.passwordInput.setEnabled(False) self.repPasswordInput.setEnabled(False) self.deptInput.setEnabled(False) self.majorInput.setEnabled(False) self.maxNumInput.setEnabled(False) self.setMyStyle()
import socket import pyperclip import func import time HOST = '127.0.0.1' # Endereco IP do Servidor PORT = 5000 # Porta que o Servidor esta tcpCliente = socket.socket(socket.AF_INET, socket.SOCK_STREAM) dest = (HOST, PORT) tcpCliente.connect(dest) key = 4 print 'Para sair digite exit\n' msgEncriptada = '' #msg = '' # Lendo Primeira Mensagem de Arquivo msg = func.leArquivo2() while msg != 'exit': #msgEncriptada = func.encrypt(msg,key) # para cifra de ceasar # copy the encrypted/decrypted string to the clipboard #pyperclip.copy(msgEncriptada) msgEncriptada = func.encrypt(msg, int(key)) # para cifra de substituicao print 'Encriptada pelo cliente: ', msgEncriptada if msg != 'exit': tcpCliente.send(msgEncriptada) time.sleep(0.2) print key tcpCliente.send(str(key)) msg = raw_input() tcpCliente.close()
def main(): # curr_path = os.path.abspath('main.py')[:-7] # login = getpass.getuser() # hostname = GetComputerName() # winpath = os.environ['WINDIR'] # sysfilespath = os.environ['WINDIR'] + "\\System32\\" # width = GetSystemMetrics(0) # size, device = get_drive_details(curr_path) # keyboard_type = get_keyboard_details() # info = "Login {}, Hostname {}, Winpath {}, Sysfilespath {}, Monitorwidth {}, Drivesize {}, Drivedevices {}, Keyboardtype {}".format(login, hostname, winpath, sysfilespath, width, size, device, keyboard_type) # hash_info = SHA256.new(data=info.encode()) # f = open('{}mykey.pem'.format(curr_path), 'rb') # pubkey = RSA.import_key(f.read()) # signature = get_reg('Signature') # try: # pkcs1_15.new(pubkey).verify(hash_info, signature) # except ValueError: # print("Signature wasn't verified") # exit() # print("Success") func.createPassFile() func.decrypt(r'D:\passfile') while True: print("1 - SignIn") print("2 - SignIn as ADMIN") print("3 - Info") print("4 - Exit") answ = 0 answ = int(input()) if answ == 1: flag = 1 login = str(input("Type your login: "******"Your account is blocked") flag = -1 break else: flag = 1 break if flag == 0: print("No such username") print("Enter 0 to exit") login = input("Type your login: "******"0": break else: break if flag <= 0: break attempts = 1 while True: if attempts > 3: break elif 4 > attempts > 0: password = input("Type your password: "******"Incorrect password") print("You have {} more attempts".format( 3 - attempts)) attempts += 1 continue elif attempts == 0: break if attempts < 4: print("1 - Change password") print("2 - Exit") answ2 = 0 answ2 = int(input()) if answ2 == 1: password = input("Type your current password: "******"Type new password: "******"0": break if u[4]: if func.verifyPassword(password): password2 = input( "Retype your new password: "******"Password has changed") break else: print( "Password wasn't confirmed" ) break else: print("Enter 0 to exit") continue else: password2 = input( "Retype your new password: "******"Password has changed") break else: print("Password wasn't confirmed") break else: print("Incorrect password") break elif answ2 == 2: break else: print("You haven`t chosen any option") break else: break break if answ == 2: flag = 1 login = input("Type your login: "******"ADMIN": print("Only for admin") print("Enter 0 to exit") login = input("Type your login: "******"0": flag = 0 break else: break if flag == 0: break attempts = 1 while True: if 4 > attempts: password = input("Type your password: "******"Incorrect password") print("You have {} more attempts".format(3 - attempts)) attempts += 1 continue else: flag = 0 break if flag == 0: break while True: print("1 - Change password") print("2 - List of users") print("3 - New user") print("4 - Block user") print("5 - Limit/unlimit user`s password") print("6 - Exit") answ3 = int(input()) if answ3 == 1: password = input("Type your current password: "******"Type your new password: "******"Retype your new password: "******"Password has changed") break else: print("Password wasn't confirmed") break else: break else: password2 = input("Retype your new password: "******"Password has changed") break else: print("Password wasn't confirmed") break if answ3 == 1: password = input("Type your current password: "******"Enter id: ") username = input("Enter username: "******"Enter 1 if blocked, 0 if not: ") islimited = input( "Enter 1 if password is limited, 0 if not: ") usr = [id, username, '', isblocked, islimited] func.adminfunc.addUser(usr) continue elif answ3 == 4: username = input("Enter username: "******"If you want to set the limit, enter 1, enter 0 if not: " ) username = input("Enter username: "******"Chose one option") break elif answ == 3: print("Zakhariash Kseniia") print("Upper and lowercase letters and numbers") continue elif answ == 4: break else: print("Chose one option") break func.encrypt(r'D:\passfile')
def test_encrypt(self): self.assertEqual(func.encrypt('Unit_test', 4), 'Yrmxcxiwx')
def on_connect(): print('connection established') deviceInfo = db.getDeviceInfo(sys.argv[1]) status = func.encrypt(deviceInfo['pubKey'], str(sys.argv[3])) t = func.encrypt(deviceInfo['pubKey'], str(time.time())) sio.emit('auth', {'fleetId': sys.argv[1], 'devId': str(sys.argv[2]), 'status': hexlify(status), 'time': hexlify(t)})
from func import encrypt, decrypt if __name__ == '__main__': message = str(input("Message:")) [code, cards] = encrypt(message) print("Coded message: ", code) decode = decrypt(code, cards) print("Your original message:", decode)
import socket import pyperclip import func import time HOST = '127.0.0.1' # Endereco IP do Servidor PORT = 5000 # Porta que o Servidor esta tcpCliente = socket.socket(socket.AF_INET, socket.SOCK_STREAM) dest = (HOST, PORT) tcpCliente.connect(dest) key = 4 print 'Para sair digite exit\n' msgEncriptada = '' #msg = '' # Lendo Primeira Mensagem de Arquivo msg = func.leArquivo2() while msg != 'exit': #msgEncriptada = func.encrypt(msg,key) # para cifra de ceasar # copy the encrypted/decrypted string to the clipboard #pyperclip.copy(msgEncriptada) msgEncriptada = func.encrypt(msg,int(key)) # para cifra de substituicao print 'Encriptada pelo cliente: ',msgEncriptada if msg != 'exit': tcpCliente.send (msgEncriptada) time.sleep(0.2) print key tcpCliente.send (str(key)) msg = raw_input() tcpCliente.close()