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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:26:26+00:00 2026-05-14T05:26:26+00:00

I’m looking for an easy and reversible method of obfuscating integer IDs. Ideally, I’d

  • 0

I’m looking for an easy and reversible method of obfuscating integer IDs. Ideally, I’d want the resulting obfuscation to be at most eight characters in length and non-sequential, meaning that the obfuscation of “1” should look nothing like the obfuscation for “2” and so on.

This isn’t meant to be secure by any means, so this isn’t a huge concern. Additionally, the integers I’ll be obfuscating aren’t large – between one and 10,000 – but I don’t want any collisions, either.

Does anybody have any ideas for something that would fit this criteria?

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

    I derived an idea from Pearson hashing which will work for arbitrary inputs as well, not just 32-bit integers. I don’t know if this is the exact same as Greg answer, but I couldn’t get at what he meant. But what I do know is that the memory requirements are constant here. No matter how big the input, this is still a reliable obfuscation/encryption trick.

    For the record, this method is not hashing, and it does not have collisions. It’s a perfectly sound method of obfuscating a byte string.

    What you need for this to work is a secret key _encryptionTable which is a random permutation of the inclusive range 0..255. You use this to shuffle bytes around. To make it really hard to reverse it uses XOR to mix the byte string a bit.

    public byte[] Encrypt(byte[] plaintext)
    {
        if (plaintext == null)
        {
            throw new ArgumentNullException("plaintext");
        }
        byte[] ciphertext = new byte[plaintext.Length];
        int c = 0;
        for (int i = 0; i < plaintext.Length; i++)
        {
            c = _encryptionTable[plaintext[i] ^ c];
            ciphertext[i] = (byte)c;
        }
        return ciphertext;
    }
    

    You can then use the BitConverter to go between values and byte arrays or some convert to base 64 or 32 to get a textual representation. Base 32 encoding can be URL friendly if that’s important. Decrypting is as simply as reversing the operation by computing the inverse of the _encryptionTable.

        public byte[] Decrypt(byte[] ciphertext)
        {
            if (ciphertext == null)
            {
                throw new ArgumentNullException("ciphertext");
            }
            byte[] plaintext = new byte[ciphertext.Length];
            int c = 0;
            for (int i = 0; i < ciphertext.Length; i++)
            {
                plaintext[i] = (byte)(_decryptionTable[ciphertext[i]] ^ c);
                c = ciphertext[i];
            }
            return plaintext;
        }
    

    You can also do other fun things if you’re working on a 32-bit integer and only care about the numbers greater than or equal to 0 which makes it harder to guess an obfuscated number.

    I also use a secret word to seed a pseudo number generator and use that to setup the initial permutation. That’s why I can simply get the value by knowing what secret word I used to create every thing.

    var mt = new MersenneTwister(secretKey.ToUpperInvariant());
    var mr = new byte[256];
    for (int i = 0; i < 256; i++)
    {
        mr[i] = (byte)i;
    }
    var encryptionTable = mt.NextPermutation(mr);
    var decryptionTable = new byte[256];
    for (int i = 0; i < 256; i++)
    {
        decryptionTable[encryptionTable[i]] = (byte)i;
    }
    this._encryptionTable = encryptionTable;
    this._decryptionTable = decryptionTable;
    

    This is somewhat secure, the biggest flaw here is that the encryption, XOR with 0, happens to be the identity of XOR and doesn’t change the value (a ^ 0 == a). Thus the first encrypted byte represent the random position of that byte. To work around this you can pick a initial value for c, that is not constant, based of the secret key by just asking the PRNG (after init with seed) for a random byte. That way it’s immensely more difficult even with a large sample to crack the encryption as long as you can’t observe input and output.

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

Sidebar

Ask A Question

Stats

  • Questions 357k
  • Answers 357k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The other answers are correct. Here is some code you… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer you ruin the noConflict concept by reassigning the jquery to… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer If you get that particular error, you don't actually have… May 14, 2026 at 9:40 am

Related Questions

No related questions found

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.