T
T
TORONTOADLER2022-04-13 18:47:19
Python
TORONTOADLER, 2022-04-13 18:47:19

Hashing a variable with a file in md5 (hashlib)?

how do I hash the data of a variable, it's just that in all the manuals they show how to hash a word, or something like that.
I want to hash a readFile variable, but the name becomes the hash

import hashlib
chunk_size = 9000

readFile = input("введите полный путь к файлу чтения: ")


with open(readFile, 'rb') as f:

    i = 0

    while True:

        data = f.read(chunk_size)

        if data:
            with open(f'chunk_{i}', 'wb') as f2:
                f2.write(data)
        else:
            break

        i += 1


# файл с кол-во чанков

cFile = input("файл для записи кол-во чанков: ")
c = bytes(i)

with open(cFile, 'wb') as f3:
    f3.write(c)


print("файл успешно прочитан")
hash_object = hashlib.md5(b"readFile")
print(hash_object.hexdigest())

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Nesterov, 2022-04-13
@AlexNest

You should learn python before hashing something.

readFile = input("введите полный путь к файлу чтения: ")
...
hash_object = hashlib.md5(b"readFile")

In my opinion, the fact that the view construct "любой_текст"is only a string and nothing else (and certainly not a variable name) is explained in the first lessons.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question