python hash_func.py

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python hash_func.py相关的知识,希望对你有一定的参考价值。

#hash function for integers

def int_hash(num):
	alpha = [str(elem) for elem in range(10)]
	numbers = ['a', 'b', 'c', 'e']
	num += num * 13
	hashed = ''
	while len(hashed) < 8:
		if hashed == '':
			if num % 2 == 0:
				hashed += numbers[1]
			elif num % 5 == 0:
				hashed += numbers[2]
			elif num % 3 == 0:
				hashed += numbers[3]
			else:
				hashed += alpha[0]
		else:
			if hashed[len(hashed)-1] == 'a':
				if num % 2 == 0:
					hashed += alpha[2]
				else:
					hashed += 'y'
			elif hashed[len(hashed)-1] == 'c':
				if len(hashed) % 2 == 0:
					hashed += alpha[0]
				else:
					hashed += numbers[3]
			elif hashed[len(hashed)-1] == '1':
				if num % 2 == 0:
					hashed += alpha[1]
				else:
					hashed += numbers[0]
			else:
				if hashed[len(hashed)-1] == '2':
					hashed += 'e'
				elif hashed[len(hashed)-1] == 'e':
					hashed += alpha[3]
				else:
					hashed += alpha[len(hashed)]
					num *= 13
				
	return hashed

以上是关于python hash_func.py的主要内容,如果未能解决你的问题,请参考以下文章

001--python全栈--基础知识--python安装

Python代写,Python作业代写,代写Python,代做Python

Python开发

Python,python,python

Python 介绍

Python学习之认识python