2

Not even sure what terms would describe what I'm looking for, but the general idea:

Given a list of strings of a finite length, determine whether or not a test string belongs to the list. Then, produce a new list of strings containing the difference of the original list and the test string.

In pseudocode, this would probably look something like:

def list = envelope(["string1", "string2", "string3"])

def validate( collection, test ) {
    if ( contains( collection, test ) ) {
        return remove( collection, test )
    } else {
        throw Exception
    }
}

// In Use
validate( list, "string2")
-> envelope( ["string1", "string3"] )

validate( list, "string4")
-> Exception

One person told me this sounded like the way a blockchain works, but given everything I've read and my rudimentary understanding of blockchain, I'm skeptical. Is there another process or protocol available that I can use to make the above function?

EAMann
  • 205
  • 1
  • 2
  • 5

1 Answers1

2

You could use convergent encryption for this.

  1. For each item to be inserted, compute its hash, then encrypt it by deriving a key from that hash. Insert the ciphertext (discarding the hash/key).

  2. To test for the presence of an item, hash it, encrypt, look for matching ciphertext.

You would likely want to use something like a hash table or a search tree (dictionary or set), instead of a flat list, to avoid $O(n)$ scan when looking for an item.

Note that the user can brute force / dictionary attack the scheme by encrypting chosen items and checking them against the list.

otus
  • 32,132
  • 5
  • 70
  • 165