Post
Topic
Board Development & Technical Discussion
Re: How to convert a compressed public key into uncompressed one in Python?
by
SamYezi
on 30/08/2022, 18:20:46 UTC
The Python script you've already discovered, over here works correctly as far as I can tell.

Substituting your example keys into the "compressed_key" variable on line 12 and running the script three times produced the following results:

compressed_key = '025A2146590B80D1F0D97CC7104E702011AFFF21BFAF817F5C7002446369BA9DDC'
Code:
045a2146590b80d1f0d97cc7104e702011afff21bfaf817f5c7002446369ba9ddc9bd5dcd1b4a737244d6bb7b96e256391b8597d3a7972a6f8ca9096d4aea1f37e

compressed_key = '035728F4692D85D411DF3643CD69FE05C411A0D507C7D814008F56C8F260AD7ED9'
Code:
045728f4692d85d411df3643cd69fe05c411a0d507c7d814008f56c8f260ad7ed99e2df8d9cb1a575d55264692629ae22e518bc14ad02592941c13be6755c72973

compressed_key = '039E87EB177890FDD788B95843ED53AD4FB6E877E3F730EF1E73593964C2AB9D15'
Code:
049e87eb177890fdd788b95843ed53ad4fb6e877e3f730ef1e73593964c2ab9d15a3b647c8c4a0766420917b7b445cdcd6bfec2900175c5534c6113954f3ff00d9

Unfortunatelly in my case it outputs incorrect values (Pycharm Python 3.10.5)
Here's the rundown of the cases:
https://i.stack.imgur.com/VgZhr.png
https://i.stack.imgur.com/VgZhr.png

Test 1:
Code:
042351126323155009915566305515988222562668831973356296881287277305661165837788ee29766cfd677f845e830bea820e1ef951b86fdc335247a8aa697e6baf1ef78
Test 2:
Code:
046799846282981021315422058923075594964980219729412475060169781627609169100505f87b4bda8ed8b93cff4207e66c65b4909a48a3b54076aac6d6ba7626e15ba875
Test 3:
Code:
049081844685017147717691639198226214703337765349173402524026447080150572702997d7b2db226c460a5e7167c150fab386c8688dd4170d3d453a2c3efad529c73e75