Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement closest zipcode finder concept. #4

Open
a-t-0 opened this issue Jan 24, 2024 · 0 comments
Open

Implement closest zipcode finder concept. #4

a-t-0 opened this issue Jan 24, 2024 · 0 comments

Comments

@a-t-0
Copy link
Owner

a-t-0 commented Jan 24, 2024

Context

You want to know which shop/zipcode is closest to your own zipcode, without telling the website where you live.

Note

The zipcode is not an appropriate application of FHE because the list of zipcodes is not private data, so instead of running an encrypted computation on the zipcode of the user, one could just send the whole zipcode list to the user, and let the user do the computation client/user-side, e.g. using javascript in the browser. However, this was an interesting case to learn about how the FHE would work in code.

Approach/Idea using Paillier cryptosystem

Create the list of distances to the zipcodes.
pass the encrypted zipcode, encrypted 1, and encrypted 0 into the function.
Compute differences between the incoming zipcodes and the shop zipcodes.
Then subtract 1 from all distances until subtractedDistance equals the encrypted 0.

Doubts

Can one derive the incoming zipcode based on the existing list of zipcodes?
Perhaps the randomness implies the subtractedDistance value of zero is different than the incoming encrypted 0 value.

First draft outline

func main() {
	// Assuming you have the Paillier public key
	n, g, lambda, mu := keygen.GetKeys()

	// Encrypt zipcodes
	zipcodeList := []int{12345, 56789, 98765}
	encryptedZipcodes := encryptZipcodes(zipcodeList, pubKey)

	// Given zipcode X
	X := 54321
	encryptedX := encryptNumber(X, pubKey)

	// Compute encrypted distances
	encryptedDistances := computeEncryptedDistances(encryptedZipcodes, encryptedX, pubKey)

	// Find the minimum distance
	minimumDistance, _ := findMinimumDistance(encryptedDistances, pubKey)

	// Decrypt minimum distance to get plaintext distance
	plaintextDistance, _ := pubKey.Decrypt(minimumDistance)

	// Retrieve closest zipcode
	closestZipcode := decryptClosestZipcode(encryptedDistances, minimumDistance, pubKey)

	fmt.Printf("Closest Zipcode to %d: %d (Distance: %d)\n", X, closestZipcode, plaintextDistance)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant