Skip to content

Instantly share code, notes, and snippets.

@dspinellis
Last active February 16, 2020 12:58
Show Gist options
  • Save dspinellis/f51d31995261daaa4d541f42bc73dc4f to your computer and use it in GitHub Desktop.
Save dspinellis/f51d31995261daaa4d541f42bc73dc4f to your computer and use it in GitHub Desktop.
Decompress an MD5 checksum into the file it represents :-)
#!/bin/bash
#
# "Decompress" an MD5 sum into the file it represents.
# This was created following a tongue-in-cheek challenge by Tom Limoncelli.
# https://twitter.com/yesthattom/status/716670884698828800
#
# Try md5decompress.sh c1a5298f939e87e8f962a5edfc206918
#
if [ "x$1" = x ] ; then
echo "Usage: $0 MD5sum" 1>&2
exit 1
fi
echo 0 > num
while : ; do
{ echo 'obase = 256' ; cat num ; } |
bc |
sed 's/ 0*\([1-9]\)/ \1/g;s/\\//;s/^ *//;s/ */\n/g' |
while read b ; do
printf %b '\0'$(printf %o $b)
done >try
if [ "$1 -" = "$(md5sum <try)" ] ; then
cat try
exit 0
fi
echo $(cat num) + 1 | bc >next
mv next num
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment