def add_account(self): name = input("Account name : ") host = input("Host : ") port = int(input("Port : ")) login = input("Login : "******"[+] Account add.")
def get_account(self, num): account = self.db.get_data_by_id(num) id = account[0] name = account[1] host = account[2] port = int(account[3]) login = account[4] pwd = b64decode(account[5].encode()) iv = pwd[:16] pwd = pwd[16:] ctx = serpent_cbc(self.mdp, iv) pwd = ctx.decrypt(pwd) pwdlen = unpack('H', pwd[:2])[0] pwd = pwd[2:2+pwdlen].decode() return {"id":id, "name":name, "host":host, "port":port, "login":login, "pwd":pwd}
ctx = _serpent(key) print ('key = ' + key.hex()) plaintext = b"\xDE"*16 buff = ctx.encrypt(plaintext) print("Encrypted buffer:") print(buff.hex()) ctx = _serpent(key) print("Decrypted buffer:") print(ctx.decrypt(buff).hex()) print("--------------------------------") print("####### СBC ENCRYPT/DECRYPT #1 #########") key = b"\x31\x32\x33\x34\x35\x36\x37\x38"+b"\0"*8 #if len = 8 we should add 8 zero bytes to the key (SERPENT key sizes: 128,192,256 bit) iv = b"\0" * 16 print('key = ' + key.hex()) print('iv = ' + iv.hex()) ctx = serpent_cbc(key, iv) #abcdefghijklmnopqrstuvwxyz0123456789 plaintext = b"\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39" buff = ctx.encrypt(plaintext) print("Encrypted buffer:") print(buff.hex()) ctx = serpent_cbc(key, iv) buff = ctx.decrypt(buff) print("Decrypted buffer:") print(buff.hex()) print("--------------------------------") print("####### СBC ENCRYPT/DECRYPT #2 #########") key = b"\x31\x32\x33\x34\x35\x36\x37\x38\x31\x32\x33\x34\x35\x36\x37\x38" # if len = 8 we should add 8 zero bytes to the key (SERPENT key sizes: 128,192,256 bit) iv = b"\x12"*16
print >> sys.stderr, 'received "%s"' % data if data: command = data[:8] info = data[8:] print >> sys.stderr, 'command ', command if command == "exit": print >> sys.stderr, 'goodbye' connection.close() sys.exit() if command[:7] == "gen_key": print >> sys.stderr, 'generating key' key = genKey() elif command[:7] == "get_key": print >> sys.stderr, 'sending key' connection.sendall(key) elif command[:7] == "rec_key": rsa_key = info elif command == "get_file": print >> sys.stderr, 'sending data' info = getText(info[1:]) serp = serpent.serpent_cbc(key, iv) connection.sendall(serp.encrypt(info)) break else: rsa_key += data else: break finally: connection.close()