Skip to content

Instantly share code, notes, and snippets.

@skull-squadron
Last active April 9, 2024 05:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skull-squadron/dab9b703b10c52c3ff91245b99da1849 to your computer and use it in GitHub Desktop.
Save skull-squadron/dab9b703b10c52c3ff91245b99da1849 to your computer and use it in GitHub Desktop.
Figlet sample viewer (require crc32 from Perl)
#!/usr/bin/env bash
#
#
# _______ _____ ______ _______ _______ _______ _____ _______
# |______ | | ____ |______ |_____| | | | |_____] | |______
# | __|__ |_____| ______| | | | | | | |_____ |______
#
#
# ___ ___ ___
#
#
# _______ _ _ _______ _______ _______ _______ _______ _______ _______ _______
# | |_____| |______ |______ |_____| |______ | |______ |______ |
# | | | |______ | | | ______| | |______ ______| |
#
# _______ _____ ______ _______ _______ _______ _____ __ _ _______
# |______ | | ____ | |______ | |______ | | | \ | |
# | __|__ |_____| |_____ |______ | | |_____| | \_| |
#
# _______ _____ __ _ ______ _______ ______
# |______ | | \ | | \ |______ |_____/
# | __|__ | \_| |_____/ |______ | \_
#
#
#
set -Eeuo pipefail
locations=(
/usr/share/figlet/fonts
/usr/share/figlet
/usr/local/share/figlet/fonts
/usr/local/share/figlet
/usr/pkg/share/figlet/fonts
/usr/pkg/share/figlet
/opt/figlet/fonts
/opt/figlet
"$HOME"/.config/figlet/fonts
"$HOME"/.config/figlet
)
buggy_fonts=(
C64-fonts/1943____.flf C64-fonts/4x4_offr.flf C64-fonts/64f1____.flf C64-fonts/a_zooloo.flf C64-fonts/advenger.flf
C64-fonts/aquaplan.flf C64-fonts/asc_____.flf C64-fonts/ascii___.flf C64-fonts/assalt_m.flf C64-fonts/asslt__m.flf
C64-fonts/atc_____.flf C64-fonts/atc_gran.flf C64-fonts/b_m__200.flf C64-fonts/battle_s.flf C64-fonts/battlesh.flf
C64-fonts/baz__bil.flf C64-fonts/beer_pub.flf C64-fonts/bubble__.flf C64-fonts/bubble_b.flf C64-fonts/c1______.flf
C64-fonts/c2______.flf C64-fonts/c_ascii_.flf C64-fonts/c_consen.flf C64-fonts/caus_in_.flf C64-fonts/char1___.flf
C64-fonts/char4___.flf C64-fonts/charact1.flf C64-fonts/charact2.flf C64-fonts/charact3.flf C64-fonts/charact4.flf
C64-fonts/charact5.flf C64-fonts/charact6.flf C64-fonts/characte.flf C64-fonts/coil_cop.flf C64-fonts/com_sen_.flf
C64-fonts/computer.flf C64-fonts/convoy__.flf C64-fonts/d_dragon.flf C64-fonts/dcs_bfmo.flf C64-fonts/deep_str.flf
C64-fonts/demo_m__.flf C64-fonts/devilish.flf C64-fonts/druid___.flf C64-fonts/e__fist_.flf C64-fonts/ebbs_1__.flf
C64-fonts/ebbs_2__.flf C64-fonts/eca_____.flf C64-fonts/etcrvs__.flf C64-fonts/f15_____.flf C64-fonts/faces_of.flf
C64-fonts/fair_mea.flf C64-fonts/fairligh.flf C64-fonts/fantasy_.flf C64-fonts/fbr12___.flf C64-fonts/fbr1____.flf
C64-fonts/fbr2____.flf C64-fonts/fbr_stri.flf C64-fonts/fbr_tilt.flf C64-fonts/finalass.flf C64-fonts/fireing_.flf
C64-fonts/flyn_sh.flf C64-fonts/fp1_____.flf C64-fonts/fp2_____.flf C64-fonts/funky_dr.flf C64-fonts/future_1.flf
C64-fonts/future_2.flf C64-fonts/future_3.flf C64-fonts/future_4.flf C64-fonts/future_5.flf C64-fonts/future_6.flf
C64-fonts/future_7.flf C64-fonts/future_8.flf C64-fonts/gauntlet.flf C64-fonts/ghost_bo.flf C64-fonts/gothic.flf
C64-fonts/gothic__.flf C64-fonts/grand_pr.flf C64-fonts/green_be.flf C64-fonts/hades___.flf C64-fonts/heavy_me.flf
C64-fonts/heroboti.flf C64-fonts/high_noo.flf C64-fonts/hills___.flf C64-fonts/home_pak.flf C64-fonts/house_of.flf
C64-fonts/hypa_bal.flf C64-fonts/hyper___.flf C64-fonts/italics_.flf C64-fonts/joust___.flf C64-fonts/kgames_i.flf
C64-fonts/kik_star.flf C64-fonts/krak_out.flf C64-fonts/lazy_jon.flf C64-fonts/letter_w.flf C64-fonts/letterw3.flf
C64-fonts/lexible_.flf C64-fonts/mad_nurs.flf C64-fonts/magic_ma.flf C64-fonts/master_o.flf C64-fonts/mayhem_d.flf
C64-fonts/mcg_____.flf C64-fonts/mig_ally.flf C64-fonts/modern__.flf C64-fonts/new_asci.flf C64-fonts/nfi1____.flf
C64-fonts/notie_ca.flf C64-fonts/odel_lak.flf C64-fonts/ok_beer_.flf C64-fonts/outrun__.flf C64-fonts/p_s_h_m_.flf
C64-fonts/p_skateb.flf C64-fonts/pacos_pe.flf C64-fonts/panther_.flf C64-fonts/pawn_ins.flf C64-fonts/phonix__.flf
C64-fonts/platoon2.flf C64-fonts/platoon_.flf C64-fonts/pod_____.flf C64-fonts/r2-d2___.flf C64-fonts/rad_____.flf
C64-fonts/rad_phan.flf C64-fonts/rainbow_.flf C64-fonts/rally_s2.flf C64-fonts/rally_sp.flf C64-fonts/rampage_.flf
C64-fonts/rastan__.flf C64-fonts/raw_recu.flf C64-fonts/rci_____.flf C64-fonts/ripper!_.flf C64-fonts/road_rai.flf
C64-fonts/rockbox_.flf C64-fonts/rok_____.flf C64-fonts/roman.flf C64-fonts/roman___.flf C64-fonts/script__.flf
C64-fonts/skate_ro.flf C64-fonts/skateord.flf C64-fonts/skateroc.flf C64-fonts/sketch_s.flf C64-fonts/sm______.flf
C64-fonts/space_op.flf C64-fonts/spc_demo.flf C64-fonts/star_war.flf C64-fonts/stealth_.flf C64-fonts/stencil1.flf
C64-fonts/stencil2.flf C64-fonts/street_s.flf C64-fonts/subteran.flf C64-fonts/super_te.flf C64-fonts/t__of_ap.flf
C64-fonts/tav1____.flf C64-fonts/taxi____.flf C64-fonts/tec1____.flf C64-fonts/tec_7000.flf C64-fonts/tecrvs__.flf
C64-fonts/ti_pan__.flf C64-fonts/timesofl.flf C64-fonts/tomahawk.flf C64-fonts/top_duck.flf C64-fonts/trashman.flf
C64-fonts/triad_st.flf C64-fonts/ts1_____.flf C64-fonts/tsm_____.flf C64-fonts/tsn_base.flf C64-fonts/type_set.flf
C64-fonts/ucf_fan_.flf C64-fonts/ugalympi.flf C64-fonts/unarmed_.flf C64-fonts/usa_____.flf C64-fonts/usa_pq__.flf
C64-fonts/vortron_.flf C64-fonts/war_of_w.flf C64-fonts/yie-ar__.flf C64-fonts/yie_ar_k.flf C64-fonts/z-pilot_.flf
C64-fonts/zig_zag_.flf C64-fonts/zone7___.flf bdffonts/5x8.flf eftichess eftipiti
eftiwall pyramid runic smtengwar twopoint
)
bark() {
echo "$@"
}
howl() {
echo >&2 "$@"
}
dog() {
cat "$@"
}
goto_doggie_heaven() {
howl "$@"
exit 1
}
has() {
command -v "$1" &>/dev/null
}
font_dirs() {
{ bark "$fig_prefix"; default_prefixes; } | sort -u
}
default_prefixes() {
local f exit_code=1
for f in "${locations[@]}"; do
if [ -d "$f" ]; then
bark "$f"
exit_code=0
fi
done
return $exit_code
}
format_font_file() {
if [[ "$1" = "$fig_prefix"* ]]; then
local relative=${1/$fig_prefix\//}
if [[ "$relative" = */* ]]; then
bark "${1/$fig_prefix/\"\$(figlet -I2)\"}"
else
bark "${relative/%.flf/}"
fi
else
bark "$1"
fi
}
is_buggy() {
local postfix
for postfix in "${buggy_fonts[@]}"; do
[[ "$1" = *"$postfix"* ]] && return 0
done
return 1
}
shell_escape() {
local first=1
for arg in "$@"; do
if [ $first = 1 ]; then
first=0
else
bark -n ' '
fi
case "$arg" in
*'!'*|*'"'*|*\'*|*'$'*|*'%'*|*' '*|*\\*)
arg="${arg//\\/\\\\}"
arg="${arg//\'/\'\\\'\'}"
bark -n "'$arg'" ;;
*) bark -n "$arg"
esac
done
}
sample_file() {
local display_file_as file="$1"; shift
display_file_as="$(format_font_file "$(shell_escape "$file")")"
! is_buggy "$display_file_as" || return 0
bark
bark
bark
bark
figlet -w"$cols" -f "$file" "${args[@]}"
bark
bark
bark -n "figlet -w\$(tput cols) -f $display_file_as "; shell_escape "${args[@]}"
}
locate_fonts() {
local dir
font_dirs | while read -r dir; do
find "$dir" -type f -name '*.flf'
done | sort
}
show_fonts() {
local font
while read -r font; do
sample_file "$font"
done
bark
bark
}
#### main
sum=a8d07ae1
has crc32 || goto_doggie_heaven "Missing command \`crc32\`"
[ "$(crc32 "$0")" = "$sum" ] || goto_doggie_heaven 'Failed checksum test'
has figlet || goto_doggie_heaven "Missing command \`figlet\`"
cols=$(tput cols)
fig_prefix=$(figlet -I2)
if (( $# )); then
args=("$@")
else
args=('Sphinx of black quartz, judge my vow.') # Dogs were too tired
fi
locate_fonts | show_fonts
@skull-squadron
Copy link
Author

Found 2 crc32 hash collisions that satisfy this property.

@skull-squadron
Copy link
Author

# On an arm64 mac

Valid hash collision for CRC-32 is a8d07ae1
Valid hash collision for CRC-32 is 4520f653
bash ./find-crc32-in-parallel figsample  1577.74s user 3.82s system 901% cpu 2:55.45 total

# On x86_66 linux
Valid hash collision for CRC-32 is a8d07ae1
Valid hash collision for CRC-32 is 4520f653

real	8m55.743s
user	841m18.286s
sys	0m1.257s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment