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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:50:25+00:00 2026-06-06T21:50:25+00:00

I would like to encrypt a 10 Character (alpha-numeric only) string into a 16

  • 0

I would like to encrypt a 10 Character (alpha-numeric only) string into a 16 or 32 character alpha-numeric string.

The string I am encrypting is an asset tag. So in itself it carries no information, but I would like to hide all valid possible strings within a larger group of possible strings. I was hoping that encrypting the string would be a good way to do this.

Is it possible to do this with the Python PyCrypto library?

Here is an example I found regarding using PyCrypto.

  • 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-06T21:50:26+00:00Added an answer on June 6, 2026 at 9:50 pm

    You’re better off with simple hashing (which is like one way encryption). To do this just use the md5 function to make a digest and then base64 or base16 encode it. Please note that base64 strings can include +, = or /.

    import md5
    import base64
    
    def obfuscate(s):
        return base64.b64encode( md5.new(s).digest())
    
    def obfuscate2(s):
        return base64.b16encode( md5.new(s).digest())
    
    # returns alphanumeric string but strings can also include slash, plus or equal i.e. /+=
    print obfuscate('Tag 1')
    print obfuscate('Tag 2')
    print obfuscate('Tag 3')
    
    # return hex string
    print obfuscate2('Tag 1')
    

    As has been commented md5 is rapidly losing its security, so if you want to have something more reliable for the future, use the SHA-2 example below.

    import hashlib
    
    def obfuscate(s):
        m = hashlib.sha256()
        m.update(s)
        return m.hexdigest()
    
    print obfuscate('Tag 1')
    print obfuscate('Tag 2')
    print obfuscate('Tag 3')
    

    One more function – this time generate about 96-bit* digest using SHA-2 and truncating the output so that we can restrict it to 16 alphanum chars. This give slightly more chance of collision but should be good enough for most practical purposes.

    import hashlib
    import base64
    
    def obfuscate(s):
        m = hashlib.sha256()
        m.update(s)
        hash = base64.b64encode(m.digest(), altchars="ZZ")  # make one way base64 encode, to fit characters into alphanum space only
        return hash[:16]    # cut of hash at 16 chars - gives about 96 bits which should 
        # 96 bits means 1 in billion chance of collision if you have 1 billion tags (or much lower chance with fewer tags)
        # http://en.wikipedia.org/wiki/Birthday_attack
    
    print obfuscate('Tag 1')
    print obfuscate('Tag 2')
    print obfuscate('Tag 3')
    

    *The actual digest is only 95.2 bits as we use 62 character alphabet for encoding.

    >>> math.log(62**16,2)
    95.26714096618998
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to encrypt a string ( user's email ) and always obtain
I would like to encrypt strings which could potentially only be about three or
I have a dictionary object which i would like to encrypt, then put it
I would like to encrypt strings of 1500-2500 characters using an Asymmetric Key. It
I would like to know if I could encrypt two or more strings in
I would like to use OpenSSL's cms library to encrypt a file with a
I would like to be able to encrypt files on disk and/or data in
I would like to protect my database of secret information with a master key
I'd like to AES-128 encrypt a string in Delphi with a password. I'd like
Which symmetrical encryption algorithm to use to encrypt e-mail address(short message)? I would like

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.