shasum will always produce a 40 digit hash value. If a file/folder name which is shorter than 40 digits is encoded , it actually gets longer than shorter. Steps to reproduce:
mkdir -p abcdefghij/abcdefghij/abcdefghij
shorten-filenames.sh . encode 25
This results in ./abcdefghij/abcdefghij/b92ab2ae522e8b2a922b9c9b2c4fa7f677373489 which is actually longer than the original folder ./abcdefghij/abcdefghij/abcdefghij