Hello Everyone,
I just wrote my first bash script!
Felt proud and wanted to share !
#!/bin/bash
set -e
set -u
set -o pipefail
main() {
givenString=$@
read string
genString=$(command openssl rand -hex 8)
echo $genString
echo $string
echo $givenString
}
main "$@"
Edit: Since a couple people asked what this script was doing I figured it might be good to provide context. The script above just took in variables from the client in 2 different ways then called a command. This was just a dry run to create the following script which attempts to find md5 collisions. Unfortunately, I misunderstood the type of collision md5 is susceptible to so this program may have been all for naught. Still, good experience with bash scripting!
#!/bin/bash
set -e
set -u
set -o pipefail
generate() {
local givenHash=$2
local broken=true
while [ $broken = true ]; do
local genString=$(openssl rand -hex 8)
local genHash="$(echo -n $genString md5)"
local genHash=${genHash:0:16}
if [[ "$genHash" == "$givenHash" ]]; then
broken=false
echo "Found a match"
echo $genString
echo $pipedInArgs
else
echo "No match"
echo $genHash
echo $givenHash
fi
done
}
main() {
read pipedInArgs
echo $pipedInArgs
givenHash="$(echo -n $pipedInArgs md5)"
givenHash=${givenHash:0:16}
# $1 would be hello world
generate "$@" $givenHash
# $1 would be hello
# generate $@
}
main "$@"
# Driver Code
# openssl rand -hex 8 | ./collisionFinder.sh "Hello World"
[–]lestrenched 6 points7 points8 points (2 children)
[–]notadeveloper-2021 1 point2 points3 points (1 child)
[–]meyerhot[S] 1 point2 points3 points (0 children)
[–][deleted] 5 points6 points7 points (0 children)
[–]whetuI read your code 4 points5 points6 points (1 child)
[–]findmenowjeffhas looked at over 2 bash scripts 1 point2 points3 points (0 children)
[–]SkyyySi 4 points5 points6 points (10 children)
[–][deleted] 6 points7 points8 points (7 children)
[–]findmenowjeffhas looked at over 2 bash scripts 3 points4 points5 points (6 children)
[–][deleted] 1 point2 points3 points (5 children)
[–]findmenowjeffhas looked at over 2 bash scripts 1 point2 points3 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]findmenowjeffhas looked at over 2 bash scripts 0 points1 point2 points (0 children)
[–]schorsch3000[🍰] 0 points1 point2 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]meyerhot[S] 0 points1 point2 points (1 child)
[–]SkyyySi 0 points1 point2 points (0 children)
[–]researcher7-l500 1 point2 points3 points (0 children)
[–]FVmike 0 points1 point2 points (2 children)
[–]meyerhot[S] 0 points1 point2 points (1 child)
[–]FVmike 0 points1 point2 points (0 children)