capitalone / fpe

A format-preserving encryption implementation in Go
Apache License 2.0
202 stars 41 forks source link

Plaintext is not equal to Original #14

Closed nitrieu closed 6 years ago

nitrieu commented 6 years ago

Description of Issue:

Plaintext is not equal to Original

Steps to Reproduce:

Follow Example Usage in main.go. Just replace original := "11111010", radix = 2, maxTlen=128

Output

Original: 11111010 Ciphertext: 1110011 Plaintext: 1011011

If applicable, mention which version(s) of Go you are able to reproduce this on, along with go env output. go version go1.9.2 windows/amd64

What did you expect to see?

Expect: Plaintext=Original=11111010

anitgandhi commented 6 years ago

Thanks for reporting. I'm able to reproduce this. It seems partially related to trailing zeros as I just tested that string with a base of 4 and got the same issue. I'm also able to reproduce it with various base2 strings but not all.

I'll continue to investigate.

nitrieu commented 6 years ago

Thank you. I got this example because I tested for all possible numbers from {0,1}^8. FYI, the code is correct for all cases from base 10

anitgandhi commented 6 years ago

This is due to not 0-padding both A and B. Fix is in branch issue-14, will merge tomorrow.

nitrieu commented 6 years ago

thanks!