Skip to content

Commit

Permalink
Improving randomness quality with 'od' (retro-compatible if not avail…
Browse files Browse the repository at this point in the history
…able)
  • Loading branch information
dougy147 committed Sep 29, 2023
1 parent c487c95 commit 01c0c88
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
8 changes: 7 additions & 1 deletion bin/mcbash
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,13 @@ random_mac() {
missing_mac_values=$(( max_mac_length - number_chars_prefix ))
suffix=""
for (( i=0;i<${missing_mac_values};i++ )); do
suffix=$(echo $suffix)$(echo ${a[RANDOM%16]})
#suffix=$(echo $suffix)$(echo ${a[RANDOM%16]})
random_number=$(echo "$(od -An -N4 -tu4 /dev/random) % 16" | bc) 2>/dev/null
if [[ -z "${random_number+x}" ]]; then
suffix=$(echo $suffix)$(echo ${a[RANDOM%16]})
else
suffix=$(echo $suffix)$(echo ${a[${random_number}]})
fi
done
mac_without_colon=$(echo $mac_prefix | sed 's/://g')$(echo $suffix)
new_mac=$(echo $mac_without_colon | sed -r 's/.{2}/&:/g ; s/:$//')
Expand Down
2 changes: 1 addition & 1 deletion func/00_dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ check_dependencies() {
exit 1
fi
done
opt_dep=("md5sum" "sha256sum") # optional dependencies
opt_dep=("md5sum" "sha256sum" "od") # optional dependencies
for o in ${opt_dep[@]}; do
if ! [[ $(which $o 2>/dev/null) ]]; then
echo -e "${_YELLOW}${_BOLD}WARNING: mcbash could need optional dependency ${_RED}${o}${_YELLOW}. \nConsider installing it on your machine.${_RESET}"
Expand Down
8 changes: 7 additions & 1 deletion func/08_mac
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ random_mac() {
missing_mac_values=$(( max_mac_length - number_chars_prefix ))
suffix=""
for (( i=0;i<${missing_mac_values};i++ )); do
suffix=$(echo $suffix)$(echo ${a[RANDOM%16]})
#suffix=$(echo $suffix)$(echo ${a[RANDOM%16]})
random_number=$(echo "$(od -An -N4 -tu4 /dev/random) % 16" | bc) 2>/dev/null
if [[ -z "${random_number+x}" ]]; then
suffix=$(echo $suffix)$(echo ${a[RANDOM%16]})
else
suffix=$(echo $suffix)$(echo ${a[${random_number}]})
fi
done
mac_without_colon=$(echo $mac_prefix | sed 's/://g')$(echo $suffix)
new_mac=$(echo $mac_without_colon | sed -r 's/.{2}/&:/g ; s/:$//')
Expand Down
1 change: 1 addition & 0 deletions misc/infos.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Dependencies : NAME : PACKAGE TO INSTALL
- echo : core/utils
- md5sum : core/utils
- sha256sum : core/utils
- od : core/utils

dougy147 [2022]
https://github.com/dougy147/mcbash
Expand Down

0 comments on commit 01c0c88

Please sign in to comment.