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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:59:07+00:00 2026-05-23T05:59:07+00:00

I am about to use an algorithm to encode a variable length but very

  • 0

I am about to use an algorithm to encode a variable length but very long String field retrieved from an XML file, then that encoded data should be persisted in the database.

Later, when I recieve a second file I need to fetch the encoded data from database (previously stored) and then decode it and validate with the new data for duplicate.

I tried org.apache.commons.codec.binary.Base64 class
it has 2 methods:

  1. encodeBase64(Byte[] barray)
  2. decodeBase64(String str)

which works perfectly fine and solves my problem.
But it converts 55 char string to just 6 char String.

So I wonder if there is any case where these algorithm encodes 2 Strings which are very large and have only 1 char mismatch (for example) into same encoded byte arrays.

I donot know about the Base64 class much but if anyone can help me out it will be really helpful.

If you can suggest any other Algorithm which makes a large String short of fixed length and solves my purpose I will be happy to use it.

Thanks in advance.

  • 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-23T05:59:07+00:00Added an answer on May 23, 2026 at 5:59 am

    Not very efficient.

    Also, using sun.misc classes gives a non-portable application.

    Check out the following performance comparisons from MiGBase64:

    enter image description here


    So I wonder if there is any case where
    these algorithm encodes 2 Strings
    which are very large and have only 1
    char mismatch (for example) into same
    encoded byte arrays.

    Base64 isn’t a hashing algorithm, it’s an encoding and must therefore be bi-directional. Collisions can’t be allowed by necessity – otherwise decoding would be non-deterministic. Base64 is designed to represent arbitrary binary data in an ASCII string. Encoding a Unicode string as Base64 will often increase the number of code points required since the Unicode character set requires multiple bytes. The Base64 representation of a Unicode string will vary depending on the encoding (UTF-8, UTF-16) used. For example:

    Base64( UTF8( "test" ) ) => "dGVzdA=="
    Base64( UTF16( "test" ) ) => "/v8AdABlAHMAdA=="
    

    Solution 1

    Use lossless compression

    GZip( UTF8( "test" ) )
    

    Here you are converting the string to byte array and using lossless compression to reduce the number of bytes you have to store. You can vary the char encoding and compression algorithm to reduce the number of bytes depending on the Strings you will be storing (ie if it’s mostly ASCII then UTF-8 will probably be best.

    Pros: no collisions, ability to recover original string
    Cons: Bytes required to store value is variable; bytes required to store value is larger

    Solution 2

    Use a hashing algorithm

    SHA256( UTF8( "test" ) )
    

    Here you are converting the string to a fixed length set of bytes with a hashing function. Hashing is uni-directional and by its nature collisions can be possible. However, based on the profile and number of Strings that you expect to process you can select a hash function to minimise the likelihood of collisions

    Pros: Bytes required to store value is fixed; bytes required to store value is small
    Cons: Collisions possible, no ability to recover original string

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

Sidebar

Related Questions

I've been doing a research about the best algorithm to use in creating a
I'm unclear about legal status of utilizing an algorithm from a published academic paper.
I know about map/reduce alghoritm and its use. It's using functions that are called
I am about to use linqtosql in my first asp.net mvc application. I have
I'm about to use Google's Website Optimizer to do a/b testing on the home
I am wondering about the use of == when comparing two generators For example:
I'm about to use func_get_args for reading additional arguments of a function call. How
I have a question about the use of multidimensional std::intializer_list in C++. I have
I have a question about the use of data structures such as ArrayLists in
I'm a bit confused about the use of all the IEnumerable<T> extension methods, intellisense

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.