Im not sure how to take filename out of sha256 checksum in Python 3

Tyrell Anderson

I'm still a Python noob but figured that instead of checking a checksum manually, I would make a quick program so it would take less time whenever I had to do it(also as practice) so I wrote this(excuse the extra useless lines and bad naming in my code, I was trying to pinpoint what I was doing wrong.)

import subprocess

FileLocation = input("Enter File Location: ")

Garbage1 = str(input("Enter First Checksum: "))

Garbage2 = str(subprocess.call(['sha256sum', FileLocation]))

Garbage3 = Garbage2.split(None, 1)

if Garbage1 == Garbage3[0]:
    print("all good")
else:
    print("Still Not Working!!!")

When I run this code it keeps on leaving the filepath at the end of the second checksum because of the Linux command, but I tried getting rid of it various ways with .split() but when I ran the code, it was still there, I also tried to add the file path to the end of the first checksum as a test, but that also won't add the filepath to the end of it. I do know for a fact that the checksums match

Any idea whats wrong any help would be appreciated.

tdelaney

From the docs, subprocess.call does: Run command with arguments. Wait for command to complete or timeout, then return the returncode attribute. You can verify this in the python shell by entering help(subprocess.call) or looking at https://docs.python.org and searching for the subprocess module.

Your code converts the integer return code to a string, not the checksum. There are other calls in subprocess that capture the process stdout, which is where sha256sum sends its checksum. Stdout is a bytes object that needs to be decoded to a string.

import subprocess

FileLocation = input("Enter File Location: ")

Garbage1 = str(input("Enter First Checksum: "))

Garbage2 = subprocess.check_output(['sha256sum', FileLocation]).decode()

Garbage3 = Garbage2.split(None, 1)

if Garbage1 == Garbage3[0]:
    print("all good")
else:
    print("Still Not Working!!!")

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to give hexadecimal input to SHA256 in python 3?

Compute sha256 checksum of a zip file using python

How is the .sha256 file on the download page for Inkscape used as a checksum?

How to calculate sha256 file checksum in Go

checking sha256 checksum

How to use sha256 hash in Python

How do I make the same SHA256 encoded string in Javascript that I do in Python 3?

ubuntu iso sha256 checksum

How to convert a sha256 object to integer and pack it to bytearray in python?

How Do I Convert a Picture into a Sha256 Hash Python

How to hash SHA256 byte 00 with Python?

How do I sha256 raw bits in python?

How found sha256 of package python for import in my project?

How to check SHA-256 checksum on files?

How to calculate SHA-256 checksum of S3 file content

How long would it take for a sha256 digest loop to reach the original hash or start cycling?

How to hash output of sha256 with sha256 in rust

Sha256 checksum on terminal displaying strange characters

Create checksum sha256 of all files and directories?

Linux SHA256 checksum generates incorrectly encoded output

How to checksum files from filename on Linux

Im very unfamiliar with python 2.7. Im not sure how to convert a specific piece of code from 2.7 to 3+

Implementation of SHA256 in python3, final hash is too short

Python3 Sha256: TypeError: object supporting the buffer API required

How to Sign ClickOnce with Sha256 Cert for .NET 4.0 like Visual Studio Update 3

How to use common crypto and/or calculate sha256 in swift 2 & 3

how to take out the mean from python matrix

Why does verifying SHA256 checksum with `sha256sum` fail on Debian and work on Ubuntu?

How to correctly generate SHA-256 checksum for a string in scala?

TOP Ranking

HotTag

Archive