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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:51:30+00:00 2026-05-18T21:51:30+00:00

would this be a correct way extract the algorithm specific values from a pgp

  • 0

would this be a correct way extract the algorithm specific values from a pgp key? i have a weird problem where all but the last values for DSA and ElGamal can be extracted properly, which then messes up the rest of my program

def algorithm(data, pka):
    #data is a large binary string with the algorithm specific values, 
    #along with the rest of the data

    # MPI is defined as: 2 byte showing how many bits the value is + the value
    if pka in [pub[1], pub[2], pub[3]]:  # the 3 different RSA values/types
        '''MPI of RSA public modulus n'''
        # I havent actually used this part of the code yet
        length = int(data[:16], 2)       # get the length of the value in bits 
        n = int(data[16:16 + length], 2) # get the value
        data = data[16 + length:]        # remove the MPI from the data

            '''MPI of RSA public modulus e'''
        length = int(data[:16], 2)
        e = int(data[16:16 + length], 2)
        data = data[16 + length:]

            temp = [n, e]
    elif pka == 'DSA':
        '''MPI of DSA prime p'''
        length = int(data[:16], 2)
        p = int(data[16:16 + length], 2)
        data = data[16 + length:]

        '''MPI of DSA group order q (q is a prime divisor of p-1)'''
        length = int(data[:16], 2)
        q = int(data[16:16 + length], 2)
        data = data[16 + length:]

        '''MPI of DSA group generator g'''
        length = int(data[:16], 2)
        g = int(data[16:16 + length], 2)
        data = data[16 + length:]

        '''MPI of DSA public-key value y (= g**x mod p where x is secret)'''
        length = int(data[:16], 2)
        y = int(data[16:16 + length], 2)
        data = data[16 + length:]

            temp = [p, q, g, y]
    elif pka == 'Elgamal (Encrypt-Only)':
        '''MPI of Elgamal prime p'''
        length = int(data[:16], 2)
        p = int(data[16:16 + length], 2)
        data = data[16 + length:]

        '''MPI of Elgamal group generator g'''
        length = int(data[:16], 2)
        g = int(data[16:16 + length], 2)
        data = data[16 + length:]

        '''MPI of Elgamal public key value y (= g**x mod p where x
            is secret)'''
        length = int(data[:16], 2)
        y = int(data[16:16 + length], 2)
        data = data[16 + length:]

            temp = [p, g, y]

    return data, temp

for example: i have a key i got from somewhere online with data (dumped from pgpdump.net) being:

Old: Public Subkey Packet(tag 14)(525 bytes) 
  Ver 4 - new Public key creation time - Sat Oct 24 20:28:43 UTC 1998 
  Pub alg - ElGamal Encrypt-Only(pub 16) 
  ElGamal p(2048 bits) - ... 
  ElGamal g(2 bits) - ... 
  ElGamal y(2044 bits) - ...

i would get everything except y, which messes up the rest of my program. the length i get for y is 2079, which makes no sense, since everything else is correct, but when i look at the binary data, the program is not reading it wrong, so i dont get where my programming is going wrong.

any ideas?

  • 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-18T21:51:31+00:00Added an answer on May 18, 2026 at 9:51 pm

    I’m not familiar with Python, but it seems that data = data[16 + length:] skips 16 + length: bits in data, but in OpenPGP multiprecision integers body is padded to byte boundary, i.e. you should write something like data = data[16 + (((length + 7)/8)*8):]

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

Sidebar

Related Questions

Would this be the correct way of declaring that an XML element Cluster contains
How would you correct way to handle an exception in this situation? Initially I
Say I have a table with an auto-incrementing surrogate key. Would this be a
would this be the correct way to display the number or records in a
Is this code correct? I'm trying to submit it and also I would like
Would this be a proper way to dispose of a BackGroundWorker? I'm not sure
In a single paged application, would this be the best way to bind and
I have read that you can do it, but would this really improve performance
I have a requirement to extract a distinct subset of rows from a DataTable,
I have a webservice running on tomcat (and working). I would like to extract

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.