Answer the question
In order to leave comments, you need to log in
What mathematical method or algorithm should be chosen to form a number from a range?
As I understand that knowledge lies in front of me, but I don’t know where to look.
For example: there is such a route
172.16.100.11:54550 -> 10.0.88.1:445if you cast the address separately to a uint32 number, then
172.16.100.11 = 2886755339 and 10.0.88.1 = 167794699and there are more ports, the important question is how to get from two numbers uint32 and two uint16 to the maximum a random number from the range of numbers 0-65535 (uint16) , naturally, that with the RST and FIN flags, the value will be released. Tell me where to look.
Answer the question
In order to leave comments, you need to log in
What you are looking for is called a hash function .
Take the first (or any) two bytes from the result of any hash function on this data.
I hope you understand that the cardinality of your set of address pairs is much larger than 2**16. This means that collisions are inevitable.
Here's how to get this number in a bash one-liner using python:
py '(lambda a, b: 256 * a + b)(*hashlib.md5(b"any bytes for hashing").digest()[:2])'
echo 'any text' | py '(lambda a, b: 256 * a + b)(*hashlib.md5(sys.stdin.read().encode("utf-8")).digest()[:2])'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question