simple-hash_2.py 658 B

1234567891011121314151617181920212223242526272829
  1. def hash_pwd (string, salt=None):
  2. msg = []
  3. if salt == None:
  4. salt = gen_salt(20)
  5. for i, c in enumerate(string):
  6. char_s = ord(salt[len(string) - i])
  7. char_string = ord(c)
  8. msg.append(chr((char_s + char_string) % 127))
  9. res = ''.join(msg)
  10. return (res + salt, salt)
  11. if __name__ == '__main__':
  12. print('Password')
  13. message = input('> ')
  14. hashed_password, salt = hash_pwd(message)
  15. print(f'Encryption: {hashed_password}')
  16. print('Enter password again')
  17. second_password = input('> ')
  18. if (hash_pwd(second_password, salt)[0] == hashed_password):
  19. print('Passwords match! Great!')
  20. else:
  21. print('Passwords don\'t match.')