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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:39:26+00:00 2026-05-25T19:39:26+00:00

I have a database id that start from 1 to … and I need

  • 0

I have a database id that start from 1 to … and I need encrypt this number to use for pursuit number.
how to generate numeric string by encrypting the database id and decrypt it?
pursuit number must be short as possible.

  • 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-25T19:39:27+00:00Added an answer on May 25, 2026 at 7:39 pm

    How secure do you need this encryption to be? A simple XOR with another int might be what you need, though you might have to be careful with sign bits.

    Alternatively, if you want something more secure, just implement a simple 32 bit Feistel cypher. Here’s one I prepared earlier:

    /**
     * IntegerPerm is a reversible keyed permutation of the integers.
     * This class is not cryptographically secure as the F function
     * is too simple and there are not enough rounds.
     *
     * @author Martin Ross
     */
    public final class IntegerPerm {
    
        //////////////////
        // Private Data //
        //////////////////
    
        /** Non-zero default key, from www.random.org */
        private final static int DEFAULT_KEY = 0x6CFB18E2;
    
        private final static int LOW_16_MASK = 0xFFFF;
        private final static int HALF_SHIFT = 16;
        private final static int NUM_ROUNDS = 4;
    
        /** Permutation key */
        private int mKey;
    
        /** Round key schedule */
        private int[] mRoundKeys = new int[NUM_ROUNDS];
    
        //////////////////
        // Constructors //
        //////////////////
        public IntegerPerm() { this(DEFAULT_KEY); }
    
        public IntegerPerm(int key) { setKey(key); }
    
        ////////////////////
        // Public Methods //
        ////////////////////
        /** Sets a new value for the key and key schedule. */
        public void setKey(int newKey) {
            assert (NUM_ROUNDS == 4) : "NUM_ROUNDS is not 4";
            mKey = newKey;
    
            mRoundKeys[0] = mKey & LOW_16_MASK;
            mRoundKeys[1] = ~(mKey & LOW_16_MASK);
            mRoundKeys[2] = mKey >>> HALF_SHIFT;
            mRoundKeys[3] = ~(mKey >>> HALF_SHIFT);
        } // end setKey()
    
        /** Returns the current value of the key. */
        public int getKey() { return mKey; }
    
        /**
         * Calculates the enciphered (i.e. permuted) value of the given integer
         * under the current key.
         *
         * @param plain the integer to encipher.
         *
         * @return the enciphered (permuted) value.
         */
        public int encipher(int plain) {
            // 1 Split into two halves.
            int rhs = plain & LOW_16_MASK;
            int lhs = plain >>> HALF_SHIFT;
    
            // 2 Do NUM_ROUNDS simple Feistel rounds.
            for (int i = 0; i < NUM_ROUNDS; ++i) {
                if (i > 0) {
                    // Swap lhs <-> rhs
                    final int temp = lhs;
                    lhs = rhs;
                    rhs = temp;
                } // end if
                // Apply Feistel round function F().
                rhs ^= F(lhs, i);
            } // end for
    
            // 3 Recombine the two halves and return.
            return (lhs << HALF_SHIFT) + (rhs & LOW_16_MASK);
        } // end encipher()
    
    
        /**
         * Calculates the deciphered (i.e. inverse permuted) value of the given
         * integer under the current key.
         *
         * @param cypher the integer to decipher.
         *
         * @return the deciphered (inverse permuted) value.
         */
        public int decipher(int cypher) {
            // 1 Split into two halves.
            int rhs = cypher & LOW_16_MASK;
            int lhs = cypher >>> HALF_SHIFT;
    
            // 2 Do NUM_ROUNDS simple Feistel rounds.
            for (int i = 0; i < NUM_ROUNDS; ++i) {
                if (i > 0) {
                    // Swap lhs <-> rhs
                    final int temp = lhs;
                    lhs = rhs;
                    rhs = temp;
                } // end if
                // Apply Feistel round function F().
                rhs ^= F(lhs, NUM_ROUNDS - 1 - i);
            } // end for
    
            // 4 Recombine the two halves and return.
            return (lhs << HALF_SHIFT) + (rhs & LOW_16_MASK);
        } // end decipher()
    
        /////////////////////
        // Private Methods //
        /////////////////////
    
        // The F function for the Feistel rounds.
        private int F(int num, int round) {
            // XOR with round key.
            num ^= mRoundKeys[round];
            // Square, then XOR the high and low parts.
            num *= num;
            return (num >>> HALF_SHIFT) ^ (num & LOW_16_MASK);
        } // end F()
    
    } // end class IntegerPerm
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database that I would like class files generated from, and also
I have a database that contains a table that looks a bit like this:
I have a database table that contains entries for start time and end time
I have several records in a database that have Start and End Dates 09/15/2011
I have an Eventmachine process that I start from my Procfile on Heroku. I'm
we have a 500gb database that performs about 10,000 writes per minute. This database
I currently have a database that gets updated from a legacy application. I'd like
I have some database table and need to process records from it 5 at
If have a control that acts like a record selector from a database, say,
I have a development database that re-deploy frequently from a Visual Studio Database project

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.