def calchash(): global X global bit global key global key_hashed global Y #Send a request to the sender try: r = requests.get('http://0.0.0.0:8080/priv', proxies=proxyDict) except: r = requests.get('http://0.0.0.0:8080/priv') #Recieve the public exponent X = int((r.json())['public']) print('The recieved public exponent is ', X, '\n') #Choose the message option bit = int(input('Enter 0 or 1 to choose message\n')) #Calculate the public factor to be sent if (bit == 0): Y = pow(g, y, prime) else: Y = X * pow(g, y, prime) print("Public factor to send = " + str(Y), '\n') #Generate the key key = str(pow(X, y, prime)).encode("utf-8") #Obtain the hash of the generated key key_hashed = encrypt.getHash(key) print('Hash of Key calculated\n')
def enc(): global Y data = ast.literal_eval((request.data).decode('utf-8')) #Obtain the public factor Y = int(data['Public']) print('Recieved public factor is ', Y, '\n') #Calculate and create the hash of the two keys key0 = str(pow(Y, x, prime)).encode("utf-8") key1 = str(pow(int(Y / X), x, prime)).encode("utf-8") key_hashed_0 = encrypt.getHash(key0) print('Hash of Key 1 calculated') key_hashed_1 = encrypt.getHash(key1) print('Hash of Key 2 calculated\n') #Encrypt both the messages and return to the reciever cipher_0 = encrypt.cipher(key_hashed_0, m0) print('Cipher of message 1 calculated') cipher_1 = encrypt.cipher(key_hashed_1, m1) print('Cipher of message 2 calculated\n') print('Waiting for receiver\n') return jsonify({ 'cipher_0': cipher_0.decode("utf-8"), 'cipher_1': cipher_1.decode("utf-8") })
def get_ld_bind_hash(self): """hash bind""" return getHash(self.Get('ld_bind_pw'), self.Get('ld_encrypt'))
def get_ld_admin_hash(self): """root hash""" return getHash(self.Get('ld_admin_pw'), self.Get('ld_encrypt'))
def get_ld_temp_hash(self): """hash пароля временного root""" return getHash(self.Get('ld_temp_pw'), self.Get('ld_encrypt'))