Last active
August 20, 2020 10:35
-
-
Save fabiolimace/79ff9e98d9f5d331525b34341c80e61c to your computer and use it in GitHub Desktop.
Calculate uniqueness of hostname hashes using SHA256 algorithm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # | |
| # Calculate uniqueness of hostname hashes using SHA256 algorithm | |
| # | |
| # hostname-0001, hostname-0002, hostname-0003... | |
| HOSTNAME_BASE="hostname"; | |
| # % of unique hashes for 256 host names: 0.65625000000000000000 | |
| USED_NODES=256; # used nodes | |
| CUT_DIGITS='cut -c-2'; # max nodes: 2**8=256 | |
| for i in `seq 1 $USED_NODES`; do HOST=`printf "$HOSTNAME_BASE-%05d" $i`; echo -n $HOST | sha256sum | $CUT_DIGITS ; done > /tmp/hashlist.txt; | |
| UNIQUE_HASHES=`cat /tmp/hashlist.txt | sort -u | wc -l`; echo $UNIQUE_HASHES / $USED_NODES | bc -l; | |
| # % of unique hashes for 4096 host names: 0.62768554687500000000 | |
| USED_NODES=4096; # used nodes | |
| CUT_DIGITS='cut -c-3'; # max nodes: 2**12=4096 | |
| for i in `seq 1 $USED_NODES`; do HOST=`printf "$HOSTNAME_BASE-%05d" $i`; echo -n $HOST | sha256sum | $CUT_DIGITS ; done > /tmp/hashlist.txt; | |
| UNIQUE_HASHES=`cat /tmp/hashlist.txt | sort -u | wc -l`; echo $UNIQUE_HASHES / $USED_NODES | bc -l; | |
| # % of unique hashes for 65536 host names: 0.63201904296875000000 | |
| USED_NODES=65536; # used nodes | |
| CUT_DIGITS='cut -c-4'; # max nodes: 2**16=65536 | |
| for i in `seq 1 $USED_NODES`; do HOST=`printf "$HOSTNAME_BASE-%05d" $i`; echo -n $HOST | sha256sum | $CUT_DIGITS ; done > /tmp/hashlist.txt; | |
| UNIQUE_HASHES=`cat /tmp/hashlist.txt | sort -u | wc -l`; echo $UNIQUE_HASHES / $USED_NODES | bc -l; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment