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:
- Get the nearest power of two greater than $10^{19} \rightarrow 2^{64}$,
- Get the binary representation of the 19-digit number,
- Split the 64-bit long binary representation into two 32-bit for Feistel network,
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,
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:
- Pad zeroes to the left of the 32-bit ciphertext (truncated) until 128-bits,
- Decrypt using AES,
- Truncate to Least Significant 32 bits (this is different from the ciphertext).