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

  • Home
  • SEARCH
  • 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 7847413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:53:11+00:00 2026-06-02T17:53:11+00:00

Quick question. I’m trying to find or write an encoder in Python to shorten

  • 0

Quick question. I’m trying to find or write an encoder in Python to shorten a string of numbers by using upper and lower case letters. The numeric strings look something like this:

20120425161608678259146181504021022591461815040210220120425161608667

The length is always the same.

My initial thought was to write some simple encoder to utilize upper and lower case letters and numbers to shorten this string into something that looks more like this:

a26Dkd38JK

That was completely arbitrary, just trying to be as clear as possible.
I’m certain that there is a really slick way to do this, probably already built in. Maybe this is an embarrassing question to even be asking.

Also, I need to be able to take the shortened string and convert it back to the longer numeric value.
Should I write something and post the code, or is this a one line built in function of Python that I should already know about?

Thanks!

  • 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-02T17:53:15+00:00Added an answer on June 2, 2026 at 5:53 pm

    This is a pretty good compression:

    import base64
    
    def num_to_alpha(num):
        num = hex(num)[2:].rstrip("L")
    
        if len(num) % 2:
            num = "0" + num
    
        return base64.b64encode(num.decode('hex'))
    

    It first turns the integer into a bytestring and then base64 encodes it. Here’s the decoder:

    def alpha_to_num(alpha):
        num_bytes = base64.b64decode(alpha)
        return int(num_bytes.encode('hex'), 16)
    

    Example:

    >>> num_to_alpha(20120425161608678259146181504021022591461815040210220120425161608667)
    'vw4LUVm4Ea3fMnoTkHzNOlP6Z7eUAkHNdZjN2w=='
    >>> alpha_to_num('vw4LUVm4Ea3fMnoTkHzNOlP6Z7eUAkHNdZjN2w==')
    20120425161608678259146181504021022591461815040210220120425161608667
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

quick question about using ORMLite. I am trying to make sure that my implementation
Quick question, indexof() find the first occur position of the string character? what about
Quick question, I'm trying to pass a value to a variable and then run
Quick question: I'm using jquery ajax to call a page that returns some json
quick question. I am trying to get C++ nailed down, and today I spent
Quick question, having a look around it seems this is the case, but it
Quick question that I can't seem to find an answer for. If I am
quick question. I'd like to remove the sup tag from the following string, and
quick question: why wont this while-loop wait for input? (ing is a string) while(ing
Quick question - I'm trying to decide the best way to store some site

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.