Advertisement
Guest User

raw

a guest
Jan 28th, 2016
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.40 KB | None | 0 0
  1. def phraseencrypt(what, phrase): # accepts to arguments a string to enceypt and some tex to tncrypt it with.
  2.     key = [] # create a list to store the phrase to encrypt with.
  3.     for char in phrase: #for loop to itirate through each charcter in the tet stored as prhrase (what to encrypt with)
  4.         key.append(ord(char)) # convert letter to ascii number and apend it to the list key. repeat for all letters
  5.     result = "" # variable ued to append the end result to
  6.     indexkey = 0 # used to keep track of which letter up to in the phrase encryption
  7.     for i in what: # for every letter in the text the user wants encrypting
  8.         i = ord(i) # convert letter to ascii number
  9.         if indexkey == len(phrase): # test to see that the indexkey (place in the llist) is not over the amount of letters that are in it.
  10.             indexkey = 0 # if previouse if statment is true then reset it to 0
  11.         for num in range(1, key[indexkey]+1):  # for every number inbtween 1 and the key. Since i store the index of the list in a varibale i can then call the letter that i am up to. +1 to fix bug/error
  12.             if i < 1: # if i is less than 1 then then reset to 127
  13.                 i = 127
  14.             i -= 1 # take away one from i (change shift of letter)
  15.         result+= chr(i) # convert ascii number back to letter
  16.         indexkey+=1 # append to string
  17.     return result # return the result
  18.  
  19.  
  20. def hashPassword(password):
  21.     global data
  22.     passwordlen = len(password)
  23.     run = 0
  24.     type = 0
  25.     try:
  26.         hashAmount = data['settings']['hashAmount'] * passwordlen
  27.     except:
  28.         hashAmount = 100
  29.     while run != hashAmount:
  30.         password = str(password).encode('utf-8')
  31.         if type == 0:
  32.             password = hashlib.md5(password).hexdigest() * passwordlen
  33.         elif type == 1:
  34.             password = hashlib.sha1(password).hexdigest() * passwordlen
  35.         elif type == 2:
  36.             password = hashlib.sha224(password).hexdigest() * passwordlen
  37.         elif type == 3:
  38.             password = hashlib.sha256(password).hexdigest() * passwordlen
  39.         elif type == 4:
  40.             password = hashlib.sha384(password).hexdigest() * passwordlen
  41.         elif type == 5:
  42.             password = hashlib.sha512(password).hexdigest() * passwordlen
  43.         elif type == 6:
  44.             type = 0
  45.             run += 1
  46.         type += 1
  47.     return phraseencrypt(str(password), str(password))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement