0NG / Format-Preserving-Encryption

FPE Implementation in C [Preparing for improvement]
MIT License
45 stars 30 forks source link

radix 62 and 95 not supported ? #6

Closed shaakaud closed 3 years ago

shaakaud commented 3 years ago

Hi,

When I tried radix 62 and radix 95, i get the below error. Is it not supported ?

I added the below test case under AES-256 in test.py

[ 95, "2B7E151628AED2A6ABF7158809CF4F3CEF4359D8D580AA4F7F036D6F04FC6A94", "3737373770717273373737", "0123456789abcdefghi", "xs8a0azh2avyalyzuwd", ],

ERROR: on executing test.py

Traceback (most recent call last): File "test.py", line 234, in main() File "test.py", line 198, in main results = regexp.findall(output.decode('utf-8'))[0] UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa6 in position 318: invalid start byte

0NG commented 3 years ago

It supports.

I have run the code with your test data. Then, I found decrypt(encrypt(plaintext)) == plaintext, so I think there's nothing wrong with the decryption and encryption procedures.

The error comes from my example code. You can look at this line to find my implementation of the (inverse) mapping between numeral string and character string. These implementations only support radix up to 36. Thus, if you need larger radix, you can implement the mappings by yourself.

Hmmm...There is actually something strange... Are you sure that the ciphertext is xs8a0azh2avyalyzuwd? I found the numeral string of the ciphertext is 79 57 54 15 10 8 6 87 3 9 65 1 69 83 1 73 53 46 80 (FF1) and 72 60 77 39 93 64 0 47 34 54 75 0 25 94 49 62 11 75 89 (FF3).

shaakaud commented 3 years ago

Thank you. I was able to figure out the mapping and inverse mapping part of your code. I was able to modify those and get it working. Thanks for your response.

The ciphertext that i pasted above is wrong. (that ciphertex is for radix 36). I am closing this issue.

Thanks again for your prompt response.