I need some pointers or a practical example on how to encrypt an int to another int, and a secret key would be required to decrypt the value.
Something like:
The answer I posted to that question applies to yours as well: use a short block cipher. Assuming your identifiers are 64 bits, in fact, you can simply use the XTEA cipher as-is, with a 64 bit integer as the data block.
Simple XOR cannot be called encryption. Obfuscation is a more appropriate word for it. I have developed a compact, fast and hopefully secure algorithm that I call it Ayden. It is on public domain and can be downloaded from Github. Hope it is useful.
You may look at this paper: Perfect Block Ciphers with Small Blocks and the slides of the presentation at the FSE 2007 conference.
The paper explains how to randomly select a permutation of n elements (e.g. the integer between 0 and n-1) which can be viewed as a cipher for this set of n elements.
It depends how cryptographically secure you want to be. For not-very-secure (in the crypto sense - probably fine for everyday use if you don't really expect serious attack) then XOR with a fixed secret key will work. Just be aware that it will be vulnerable to some fairly basic cryptanalysis.
If you want real encryption, you'll probably have to use a stream cipher like RC4. You can grab 32 bits of keystream and XOR it with your value to encrypt it. As long as you get a new 32 bits of keystream for each value you'll be fine.
RC4 has some caveats, however, so read up on it first.
Block ciphers will not be your friend in this case as they all have block sizes of 64 bits or more. This means you need to pad your 32 bit integer to 64 bits and you'll get 64 bits back out...but you can't choose which 32 to keep. You won't be able to decrypt it with only half the bits. If you're happy to move to longs then you can use 3DES or Blowfish.
It all depends on exactly what you are encrypting and why, so it's hard to give a definitive answer. I hope this gives an idea of where to start, at least.
You want to encrypt just a single 'int' ie q 32/64 bit number?
Then the easiest way is to just XOR it with a 32/64bit secret key.