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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:10:56+00:00 2026-05-25T17:10:56+00:00

I need to convert this PHP function into Python but I don’t even know,

  • 0

I need to convert this PHP function into Python but I don’t even know, what is space padded binary string.

pack('A*', $string);

Python has struct.pack what should be probably used but I end here. Can somebody help and explain me the behaviour?

Thanks!


UPDATE:

This is the whole code I need to implement in Python. Until now I never heard about pack() so I am trying to understand what it exactly does so I can do it in Python:

function getSIGN($PID, $ID, $DESC, $PRICE, $URL, $EMAIL, $PWD) {
    $bHash = pack('A*', $PID . $ID . $DESC . $PRICE . $URL . $EMAIL);
    $bPWD = pack('A*', $PWD);
    $SIGN = strtoupper(hash_hmac('sha256', $bHash, $bPWD, false));
    return $SIGN;
}
  • 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-05-25T17:10:57+00:00Added an answer on May 25, 2026 at 5:10 pm

    I think that is a noop.

    $string = 'asdf';
    print pack('A10', $string) . "|<-\n";
    

    would give you

    asdf      |<-
    

    Since the * means “take as many as possible,” there is never any reason to pad.

    IMHO you can just throw away the whole line.


    Re. your Update:

    The pack function still serves no purpose, except for maybe implicitely converting all non-string arguments to strings.

    Here is how you would do it in Python. I took the liberty to change the order of the parameters, so I can use parameter packing (which is not at all like string packing ;).

    import hmac, hashlib
    
    def get_sign(key, *data):
         msg = ''.join(str(item) for item in data)
         h = hmac.new(key, msg, hashlib.sha256)
         return h.hexdigest().upper()
    

    PHP:

    $ print getSIGN(1234, 456, "foo", '123.45', 'http://example.com', 'foo@example.com', 'blah');  
    7FA608240FA2DC04F15DB2CDB58C83F4ED6C28C5C5B4063C5A7605F9D69F170B
    

    Python:

    In [12]: get_sign('blah', 1234, 456, "foo", '123.45',
                      'http://example.com',  'foo@example.com')
    Out[12]: '7FA608240FA2DC04F15DB2CDB58C83F4ED6C28C5C5B4063C5A7605F9D69F170B'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That sounds pretty odd but i have this cod and i need to convert
I need to convert a Word document into HTML file(s) in Java. The function
I need to convert latitude/longitude coordinates into Easting/Northing coordinates in the Alberta 10 TM
I need to convert HTML documents into valid XML, preferably XHTML. What's the best
I need to convert a value which is in a DateTime variable into a
I need to convert a bunch of files to utf-8 in Python, and I
I need to convert an arbitrary amount of milliseconds into Days, Hours, Minutes Second.
I am making a function (PHP). In this function it basically uses the dbms
I've determined that I need to convert a Windows FILETIME type to something PHP
I have seen many PHP function on how to generate a <ul><li> tag but

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.