import hashlib, sys, re class PassKeep: #,  , ! __password = "" __length = 10 #    10 . url = "" def getMd5(self, string): #   md5  . string = str(string) md5 = hashlib.md5() md5.update(string) return md5.hexdigest() def __init__(self): #,   .   .      . self.__password = self.getMd5(self.__password) self.time = self.getMd5(time.time()) def setUrl(self, url): # url. self.url = self.getMd5(url) return self.url def setPasswd(self, passwd): # . self.__password = self.getMd5(passwd) return self.__password def decrypt(self): # ,   . password = self.__password #   url, url = self.url #    . result = self.getMd5(password + url) #  md5    . passwd_candidate = result[:self.__length] #     10 . #    !   , # ,    ,   n(10)    . #     -   ,     -   ! if (len(re.findall(r'([0-9]+)', passwd_candidate)[0]) + 3 < len(passwd_candidate)): #    return passwd_candidate else: #  ,   . result = "" count = 0 sum = 1 for symbol in passwd_candidate: #     . if (sum < 4): #       ,    . try: #     int,   str (). int_symbol = int(symbol) if (count%2 != 0): #      . print int_symbol result += chr(122 - int_symbol) #   ,          ,     ! sum += 1 count += 1 else: # ,    . result += symbol count += 1 except: #  str       . result += symbol count += 1 else: result += symbol count += 1 return result p = PassKeep() # . passwd = raw_input("Enter passwd \n") #       ! p.setPasswd(passwd) url = raw_input("Enter url, like www.example.com \n") p.setUrl(url) print p.decrypt() #      sys.exit(0) # . python passkeep.py
Source: https://habr.com/ru/post/128707/
All Articles