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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:16:00+00:00 2026-05-14T21:16:00+00:00

I would like to implement a simple substitution cipher to mask private ids in

  • 0

I would like to implement a simple substitution cipher to mask private ids in URLs.

I know how my IDs will look like (combination of uppercase ASCII letters, digits and underscore), and they will be rather long, as they are composed keys. I would like to use a longer alphabet to shorten the resulting codes (I’d like to use upper- and lowercase ASCII letters, digits and nothing else). So my incoming alphabet would be

[A-Z0-9_] (37 chars)

and my outgoing alphabet would be

[A-Za-z0-9] (62 chars)

so a compression of almost 50% reasonable amount of compression would be available.

Let’s say my URLs look like this:

/my/page/GFZHFFFZFZTFZTF_24_F34

and I want them to look like this instead:

/my/page/Ft32zfegZFV5

Obviously both arrays would be shuffled to bring some random order in.

This does not have to be secure. If someone figures it out: fine, but I don’t want the scheme to be obvious.

My desired solution would be to convert the string to an integer representation of radix 37, convert the radix to 62 and use the second alphabet to write out that number. is there any sample code available that does something similar? Integer.parseInt() has some similar logic, but it is hard-coded to use standard digit behavior.

Any ideas?

I am using Java to implement this but code or pseudo-code in any other language is of course also helpful.

  • 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-14T21:16:00+00:00Added an answer on May 14, 2026 at 9:16 pm

    Inexplicably Character.MAX_RADIX is only 36, but you can always write your own base conversion routine. The following implementation isn’t high-performance, but it should be a good starting point:

    import java.math.BigInteger;
    public class BaseConvert {
        static BigInteger fromString(String s, int base, String symbols) {
            BigInteger num = BigInteger.ZERO;
            BigInteger biBase = BigInteger.valueOf(base);
            for (char ch : s.toCharArray()) {
                num = num.multiply(biBase)
                         .add(BigInteger.valueOf(symbols.indexOf(ch)));
            }
            return num;
        }
        static String toString(BigInteger num, int base, String symbols) {
            StringBuilder sb = new StringBuilder();
            BigInteger biBase = BigInteger.valueOf(base);
            while (!num.equals(BigInteger.ZERO)) {
                sb.append(symbols.charAt(num.mod(biBase).intValue()));
                num = num.divide(biBase);
            }
            return sb.reverse().toString();
        }
        static String span(char from, char to) {
            StringBuilder sb = new StringBuilder();
            for (char ch = from; ch <= to; ch++) {
                sb.append(ch);
            }
            return sb.toString();
        }
    }
    

    Then you can have a main() test harness like the following:

    public static void main(String[] args) {
        final String SYMBOLS_AZ09_ = span('A','Z') + span('0','9') + "_";
        final String SYMBOLS_09AZ = span('0','9') + span('A','Z');
        final String SYMBOLS_AZaz09 = span('A','Z') + span('a','z') + span('0','9');
    
        BigInteger n = fromString("GFZHFFFZFZTFZTF_24_F34", 37, SYMBOLS_AZ09_);
    
        // let's convert back to base 37 first...
        System.out.println(toString(n, 37, SYMBOLS_AZ09_));
        // prints "GFZHFFFZFZTFZTF_24_F34"
    
        // now let's see what it looks like in base 62...       
        System.out.println(toString(n, 62, SYMBOLS_AZaz09));
        // prints "ctJvrR5kII1vdHKvjA4"
    
        // now let's test with something we're more familiar with...
        System.out.println(fromString("CAFEBABE", 16, SYMBOLS_09AZ));
        // prints "3405691582"
    
        n = BigInteger.valueOf(3405691582L);
        System.out.println(toString(n, 16, SYMBOLS_09AZ));
        // prints "CAFEBABE"        
    }
    

    Some observations

    • BigInteger is probably easiest if the numbers can exceed long
    • You can shuffle the char in the symbol String, just stick to one “secret” permutation

    Note regarding “50% compression”

    You can’t generally expect the base 62 string to be around half as short as the base 36 string. Here’s Long.MAX_VALUE in base 10, 20, and 30:

        System.out.format("%s%n%s%n%s%n",
            Long.toString(Long.MAX_VALUE, 10), // "9223372036854775807"
            Long.toString(Long.MAX_VALUE, 20), // "5cbfjia3fh26ja7"
            Long.toString(Long.MAX_VALUE, 30)  // "hajppbc1fc207"
        );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.