Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8324021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:54:20+00:00 2026-06-08T23:54:20+00:00

Working on an assignment for a self-study course that I’m taking in cryptography (I’m

  • 0

Working on an assignment for a self-study course that I’m taking in cryptography (I’m receiving no credit for this class). I need to compute hash values on a large file where the hash is done block by block. The thing that I am stumped on at the moment is how to break up the file into these blocks? I’m using python, which I’m very new to.

f = open('myfile', 'rb')
BLOCK_SIZE = 1024
m = Crypto.Hash.SHA256.new()
thisHash = ""
blocks = os.path.getsize('myfile') / BLOCK_SIZE #ignore partial last block for now

for i in Range(blocks):
    b = f.read(BLOCK_SIZE)
    thisHash = m.update(b.encode())
    f.seek(block_size, os.SEEK_CUR) 

Am I approaching this correctly? The code seems to run up until the m.update(b.encode()) line executes. I don’t know if I am way off base or what to do to make this work. Any advice is appreciated. Thanks!

(note: as you might notice, this code doesn’t really produce anything at the moment – I’m just getting some of the scaffolding set up)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T23:54:23+00:00Added an answer on June 8, 2026 at 11:54 pm

    You’ll have to do a few things to make this example work correctly. Here are some points:

    • Crypto.Hash.SHA256.SHA256Hash.update() (you invoke it as m.update()) has no return value. To pull a human-readable hash out of the object, .update() it a bunch of times and then call .hexdigest()
    • You don’t need to encode binary data before feeding it to the .update() function. Just pass the string containing the data block.
    • File pointers are advanced by file.read(). You don’t need a separate .seek() operation.
    • .read() will return an empty string if you’ve hit EOF already. This is totally fine. Feel free just to pull in that partial block.
    • Variable names are case-sensitive. block_size is not the same variable as BLOCK_SIZE.

    Making these few minor adjustments, and assuming you have all the right imports, you’ll be on the right track.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on my assignment of PHP course. The problem that I don't understand
I've been working on this assignment, where I need to read in records and
I am working on this assignment. I need to create a temporary stack without
I'm working on an assignment for a class, and need a bit of direction.
Im working on this assignment using Open SSL and C++. I need to establish
I am working on an assignment that uses a base class bankAccount and two
I'm working on an assignment in my beginner Javascript class that involves an element
I am working on an assignment where I need to do calculations with large
I am working on an assignment that deals with reading data from a text
I'm working on an assignment has a class hierarchy like blow: abstract EventClass someEventClass1

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.