Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SHA256-Checker
#1
I made a SHA256 checker.

How to use SHA256-Checker? Step 1: Download the file you want to check and sha256sum.txt from the Internet then put them inside dist folder.
Step 2: Open hash.exe. Step 3: Type the file name. (Example:pycharm-community-2020.2.exe). Then the program will generate hash from the check file and compare the hash inside sha256sum.txt. If two of them are matched.The program will display "Hash correct". Otherwise the program will display "Hash incorrect".

Notice: If the website only provided you a SHA256SUM value then you need to create a text file called sha256sum.txt After that paste the hash value inside the text file. The SHA256SUM hash format should look like this. hashvaule *filename.extension or hashvaule filename.extension

For example: 65afa1b90f3ecc45946793c4c43a47a46dff2e1da0737ce602f5ee12bd946f1e *pycharm-community-2020.2.exe

93863e17ac24eeaa347dfb91dddac654f214c189e0379d7c28664a306e0301e7 debian-10.5.0-amd64-netinst.iso 14ca00bafcaf124ef2cab9da2f51d75044232ba9630a067d8664fabcb5e26ec2 debian-10.5.0-amd64-xfce-CD-1.iso 7fe10f143b7f697ecabe3d4b2f94d523ad74ffb1743e5c86586a3f57ea904f35 debian-edu-10.5.0-amd64-netinst.iso 461af35784ef816401297902c531a03614429003bdea0ea26fb19f57e0aaa4c6 debian-mac-10.5.0-amd64-netinst.iso

If you think the download source is untrusted.Never download any files or hash files from them.

If you have any question feel free to ask me. Thank you!

[Image: Screenshot1.jpg]

[Image: Screenshot2.jpg]

import os
import hashlib

hash1=""
hash2=""

if os.path.isfile('./sha256sum.txt'):
    print("sha256sum.txt exists")
    file1 = open("sha256sum.txt", "r")
else:
    print("sha256sum.txt does not exists,please make sure your file name is correct")
    input("Press enter to exit")
    exit(0)

#Display list of files inside directory
print("Display list of files:")
for x in os.listdir('.'):
    print(x)

filename = input("Please enter the file name: ")
print("Extracting hash from %s ..." % filename)

sha256_hash = hashlib.sha256()
with open(filename,"rb") as f:
    # Read and update hash string value in blocks of 4K
    for byte_block in iter(lambda: f.read(4096), b""):
        sha256_hash.update(byte_block)

hash1=sha256_hash.hexdigest()

l=file1.readlines()
for word in l:
    if filename in word: # find match line by file name
        print(word) #debug
        clearline1 = word.replace(filename, '') # clear file name
        clearline2 = clearline1.replace('*', '')  # clear *
        clearline3 = clearline2.strip() # clear whitespace and new lines
        hash2=clearline3

if hash1 == hash2:
    print("Hash1 is %s"%hash1)
    print("Hash2 is %s" % hash2)
    print("Hash correct")
    input("Press enter to exit")

else:
    print("Hash1 is %s" % hash1)
    print("Hash2 is %s" % hash2)
    print("Hash incorrect")
    input("Press enter to exit")
Reply
#2
you can make your life easier,
use one of these packages: https://pypi.org/search/?q=sha
Reply
#3
(Aug-21-2020, 02:03 PM)Larz60+ Wrote: you can make your life easier,
use one of these packages: https://pypi.org/search/?q=sha

Please notice that this is not just a bunch of source code.It is a SHA256 file checker that can check download file's integrity.This program not only extract hash from the file. It also compares the hash with sha256sum.txt to ensure the download file's integrity.

[Image: Screenshot1.jpg]

Step 1: Download the file you want to check and sha256sum.txt from the Internet then put them inside dist folder. Step 2: Open hash.exe. Step 3: Type the file name. (Example:pycharm-community-2020.2.exe). Then the program will generate hash from the check file and compare the hash inside sha256sum.txt. If two of them are matched.The program will display "Hash correct". Otherwise the program will display "Hash incorrect".
Basically one line of command will do all jobs.

https://github.com/gingshow/SHA256-Checker

If you guys want to use this program you can download the tool from my Github.Thank you!
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020