Cryptography Stack Exchange is a question and answer site for software developers, mathematicians and others interested in cryptography. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to implement an FPE for a 19-digit long number. I am trying to follow the lecture of Prof. Dan Boneh and here is how I understand it:

  1. Get the nearest power of two greater than $10^{19} \rightarrow 2^{64}$,
  2. Get the binary representation of the 19-digit number,
  3. Split the 64-bit long binary representation into two 32-bit for Feistel network,
  4. Perform 7 rounds of Feistel network with AES (PRF),

    • pad zeroes to left of 32-bit until 128 bits for AES,
    • truncate cipherText obtained to the 32 Least significant bits for Feistel XOR and next rounds,
  5. Convert the output of the Feistel network to Decimal and check if it is in the range of $0 - 10^{19}$ (some values are between $10^{19}$ and $2^{64}$), if not perform Feistel on the cipher text until it is within the range.

I am trying to do pad-encrypt-truncate for step 4 but I was not able to recover the plaintext from the truncated ciphertext. I am doing these decrypt steps right now:

  1. Pad zeroes to the left of the 32-bit ciphertext (truncated) until 128-bits,
  2. Decrypt using AES,
  3. Truncate to Least Significant 32 bits (this is different from the ciphertext).
share|improve this question
Truncation is not reversible. These truncated values are only used in the Feistel network. The feistel network ensures reversibility even when using a non reversible function. – CodesInChaos Aug 20 '14 at 12:12
You might want to take a look at FFX mode which uses a pretty similar principl. – CodesInChaos Aug 20 '14 at 12:14
Thanks for the info. I'll look into FFX later. For now, how should I implement the decryption algo for the FPE I used above? I am still trying to learn the basic :D – Frank Smith Aug 20 '14 at 12:21
Read the Feistel network article I linked. – CodesInChaos Aug 20 '14 at 12:23
Yes, changing the AES key round would suffice, but (IMHO) is more heavy weight than you need. Instead, I would suggest you put the round index into the (currently zero) padding you use to pad out the 32-bit into a full 128 bits. – poncho Aug 20 '14 at 15:52

In the decrypting steps use AES_encrypt itself instead of AES_decrypt, AES decrypt is never needed.

Remember while encrypting, AES_encrypt is only used as a Pseudo Random Function, we don't really need AES_decrypt method even in decrypting phase. This might seem little confusing at first but not needed. Please check the proof given for this answer

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.