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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:35:10+00:00 2026-06-09T00:35:10+00:00

I have a string of numbers that i would like to make shorter for

  • 0

I have a string of numbers that i would like to make shorter for use in a URL. This string always consists of numbers only. For example: 9587661771112

In theory, encrypting a numeric string into an alphanumeric(0-9a-zA-Z) string should always return a shorter result, which is what i want.

I’ve created an algorithm that does the following:

Encrypt ( string1 = numeric input string, string2 = alphanumeric return string)

  • Takes the next two characters from string1 and converts them into a number, e.g 95 for the above example
  • Checks if the number is less than 52(the combined length of a-z and A-Z)
    • if so, adds (“abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ”)[Number] to
      string2 and jump forward by 2 characters
    • else, add (“0123456789)[First digit of Number) to string2 and jump forward by 1 character

In the next step the number would be 58 and so on.

With some tweaking the shortest result i could get was: 9587661771112 > j9UQpjva

My problem is that with this technique, the result can vary dramaticaly. I also feel that this is not a clean solution to my problem.

So I need an encryption algorithm that converts a string of numbers into a shorter string of uppercase letters, lowercase letters and numbers. It has to be decryptable and have a more or less consistent result.

Any idea how to achieve this?


Solution:

string Chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

string Base10To62(long N)
{
    string R = "";
    while (N != 0)
    {
        R += Chars[(int)(N % 62)];
        N /= 62;
    }
    return R;
}

long Base62To10(string N)
{
    long R = 0;
    int L = N.Length;
    for (int i = 0; i < L; i++)
    {
        R += Chars.IndexOf(N[i]) * (long)Math.Pow(62, i);
    }
    return R;
}

works like a charm 🙂

  • 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-09T00:35:12+00:00Added an answer on June 9, 2026 at 12:35 am

    Solution:

    string Chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    
        private static string Base10To62(string S) 
        {
            string R = "";
            var N = long.Parse(S);
            do { R += Chars[(int)(N % 0x3E)]; } while ((N /= 0x3E) != 0);
            return R;
        }
    
        private static string Base62To10(string S) 
        {
            long R = 0;
            int L = S.Length;
            for (int i = 0; i < L; i++) R += Chars.IndexOf(S[i]) * (long)(System.Math.Pow(0x3E, i));
            return R.ToString();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a plist that looks like this: <dict> <key>Aaron</key> <dict> <key>number</key> <string>1234</string> <key>country</key>
I have a list of numbers that i would like to send out onto
I have a short line of code that I would like to make uppercase.
Hi I have a string of numbers separated by commas, 100,200,300,400,500 that I'm splitting
I have a list that has some chapter numbers in string. When I sort
I have a field in my SSRS report, that contains a string of numbers
I have several input fields that should have only numbers as valid input, so
I have a string passed into a function, I would like to compare the
I have a C++ script which involves string representations of would-be hexadecimal numbers. In
I have a written C++ server app that I would like to be able

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.