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).
  • $\begingroup$ 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. $\endgroup$ Aug 20, 2014 at 12:12
  • 2
    $\begingroup$ You might want to take a look at FFX mode which uses a pretty similar principl. $\endgroup$ Aug 20, 2014 at 12:14
  • $\begingroup$ 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 $\endgroup$ Aug 20, 2014 at 12:21
  • $\begingroup$ Read the Feistel network article I linked. $\endgroup$ Aug 20, 2014 at 12:23
  • 1
    $\begingroup$ 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. $\endgroup$
    – poncho
    Aug 20, 2014 at 15:52

1 Answer 1


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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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