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 8221413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:54:55+00:00 2026-06-07T13:54:55+00:00

I’m trying to convert some Ruby code into Python. I’m having troubles with this

  • 0

I’m trying to convert some Ruby code into Python. I’m having troubles with this line:

Digest::MD5.digest(message).unpack('L*')

I think I should use the struct module and the hashlib one, but if I do:

struct.unpack('L', hashlib.md5(message).digest())

I get this error:

struct.error: unpack requires a bytes object of length 4

What should I do?
Thank you,

rubik

P.S. The output should be a list of 4 x 32 bit ints:

irb(main):039:0> Digest::MD5.digest('Hash').unpack('L*')
=> [631892218, 1967199614, 3683860954, 4130231798]
  • 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-07T13:55:02+00:00Added an answer on June 7, 2026 at 1:55 pm

    There is no support for arbitrary length unpacks (the * operator). You’ll have to specify a repeater manually.

    Luckily the struct module does let you specify a fixed length, and the hashlib module tells you how many bytes to expect. By putting an integer number before the L you specify the number of times to apply the pattern. And a specific hash in the hashlib library has a .digest_size attribute that tells you how many bytes long a specific hash is.

    To combine these:

    structspec = '%iL' % (hashlib.hash('md5').digest_size / 4)
    struct.unpack(structspec, hashlib.md5(message).digest())
    

    If you don’t even want to hardcode the 4 there, you can ask struct.calcsize for the size of an L unsigned long as well:

    structspec = '%iL' % (hashlib.hash('md5').digest_size / struct.calcsize('L'))
    struct.unpack(structspec, hashlib.md5(message).digest())
    

    In fact, on 64 bit platforms like my Mac, L is 8 bytes, so the latter calculation matters enormously if you are deploying across different architectures.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have some data like this: 1 2 3 4 5 9 2 6
I am trying to understand how to use SyndicationItem to display feed which is

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.