import crypt
import os
import shutil
'''curDir = os.getcwd()
print(curDir)
os.mkdir('NixFiles')'''
'''shutil.move("/Users/Ayounes/Desktop/Python_dev/dictionary.txt",
"/Users/Ayounes/Desktop/Python_dev/")
shutil.move("/Users/Ayounes/Desktop/Python_dev/passwords.txt", "/Users/Ayounes/Desktop/Python_dev/")'''
def testPass(cryptPass):
salt = cryptPass[0:2]
dictFile = open('dictionary.txt', 'r')
for word in dictFile.read().split():
#print(word)
cryptWord = crypt.crypt(word, salt)
#print(cryptWord)
if(cryptWord == cryptPass):
print('Found password: %s' % word)
print('Index located at position: %d' % word.index(" "))
return
print('Password was not found.\n')
return
def main():
passFile = open('passwords.txt','r')
cryptPass1 = passFile.readline()
testPass(cryptPass1)
if __name__ == '__main__':
main()
Моя программа получает хеш из файла passwords.txt. Затем он продолжает принимать солт-параметры (первые 2 символа хэша) и хэширует слова в файле dictionary.txt по одному, построчно, сравнивая этот хэш с исходным в файле passwords.txt.
После совпадения можно распечатать, какой пароль был дешифрованным совпадением для исходного хеша.
'grilledcheese22' является четвертым словом в позиции 3 в файле dictionary.txt, и он продолжает выводить индекс в позиции: 0
Как вывести правильную позицию в файле .txt?
Оригинальный хэш: 22CWIxwLb7tWM
Расшифрованный хеш внутри dictionary.txt: 'grilledcheese22'