Skip to content

Instantly share code, notes, and snippets.

@mertyildiran
Last active August 29, 2015 13:57
Show Gist options
  • Save mertyildiran/9600561 to your computer and use it in GitHub Desktop.
Save mertyildiran/9600561 to your computer and use it in GitHub Desktop.
Excellent Hash Algorithm :)
import csv
import time
started = time.clock()
hash_list = []
unique_hash_list = []
print "\n>> TABLE: << \n"
with open('liste.csv', 'rb') as csvfile:
spamreader = csv.reader(csvfile)
for row in spamreader:
var = ' '.join(row).replace(";", " ")
i = 0
hash_result = 0
weighted_sum = 0
while (i < len(var)):
weighted_sum += ord(var[i]) * (i+1)
i += 1
hash_result = weighted_sum % 148
hash_list.append(hash_result)
print '%-20s' %(var) + '%38s' %(hash_result)
print "------------------------------------------------------------"
print "\n\n>> HASH LIST: << \n"
hash_list.sort()
print hash_list
print "\n"
for i in hash_list:
if i not in unique_hash_list:
unique_hash_list.append(i)
print "\n\n>> UNIQUE HASH LIST: << \n"
unique_hash_list.sort()
print unique_hash_list
print "\n"
print "\n\n>> RESULT: << \n"
print str(len(hash_list) - len(unique_hash_list)) + " conflict has been found!"
print "\n"
print str(len(unique_hash_list)) + " unique hash has been produced!"
print "\n"
print str(len(hash_list)) + " total hash. Mode: 148"
print "\n\n>> This script written by MEHMET MERT YILDIRAN --- 12060367 << \n"
ended = time.clock()
print "Elapsed time: " + str(ended-started) + "\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment