Can I implementation of Luhn's algorithm to validate a credit card number encrypted using homomorphic encryption, using concrete TFHE Compiler?
Am0stafa opened this issue · 3 comments
Am0stafa commented
Here are the steps used in Luhn's algorithm, can they be made using homomorphic encryption or is it impossible due to certain operations?
- Double every second digit from right to left: Start with the second-to-last digit and double the value of every other digit. If you're working with a credit card number, begin from the rightmost digit and move left, doubling every second digit.
- Sum the digits of the doubled values and the undoubled digits: If any of the doubled values are greater than 9, add the digits of these values together to get a single digit (e.g., if the doubled value is 14, then 1 + 4 = 5). Add these sums together with the digits that were not doubled
- Check if the total sum is divisible by 10: The validity of the credit card number is confirmed if the total sum of the digits (after doubling and adding) is divisible by 10. This divisibility indicates that the credit card number is valid according to Luhn's algorithm.
Here is a Python implementation of unencrypted Luhn's algorithm:
def normal_luhn_check(card_number):
def digits_of(n):
return [int(d) for d in str(n)]
digits = digits_of(card_number)
odd_digits = digits[-1::-2]
even_digits = digits[-2::-2]
checksum = sum(odd_digits)
for d in even_digits:
checksum += sum(digits_of(d*2))
return checksum % 10 == 0
I would hight appreciate the discussion of whether it is feasible to implement it or no
Am0stafa commented
I want an explanation if that is even possible and potential roadblocks
andrei-stoian-zama commented
It look doable to me, just one thing to have in mind is that variable sized inputs are not supported, but that shouldn't be an issue for CC numbers.
I don't see any roadblocks:
- you should take as input a tensor of size
(16,)
which contains the digits already separated, to get rid ofdigits_of
. sum(digits_of(d*2))
will be computed as a look-up table (check out fhe.Univariate)- the indexing you show for odd/even digits should be supported (if it's not tell us and we'll see about a workaround)
Am0stafa commented
what about the modulus operation, as it is not natively supported? That is my only roadblock
What do you think? @andrei-stoian-zama
Thanks