I wrote a program that generates a md5 hash onto a printed out bill. I want to be able to check the hash against a generated list of hashes. I then use a Levenshtein distance function to figure out which hash has the lowest edit distance from the printed out bill.
Here is my code:
func checkIfBillIsLegit(stringToCheck:String) -> Bool {
for i in 0...((secretWords.count)) { // for loop runs about 5 times
let hashs = String().generateAll(secretWords[i]) // create the md5 hashs to check against, returns an array with 50 elements
for j in 0...(hashs.count) {
if (stringToCheck.minimumEditDistance(hashs[j]) < 5) { // Levenshtein distance function
print("legit")
print(secretWords[i])
return true
}
}
}
print("not legit")
return false
}
I want to be able to run this method multiple times per second. It works now, but it's slightly too slow for what I want to do. Problem is, the generateAll() method is too slow to generate 50 hashes per second. I was thinking of calling generateAll outside of this method, but I can't figure out how I would be able to keep track of the list?
Any help would be appreciated.
generateAll() method: