Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # The script generates readable hashes, for example, "opepurosog". It
- # receives a path to a file as a positional parameter and outputs
- # a sequence consisting of "vowel + consonat" combinations.
- vowels=(a e i o u)
- consonants=(b d f g h k l m n p r s t v z)
- parity_flag=0
- carry=0
- # Getting the checksum; it consists of digits only
- checksum=$(cksum $1 | cut -d " " -f 1)
- checksum_length=${#checksum}
- max_position_number=$((checksum_length - 1))
- # Turning the checksum string into an array
- array=($(echo $checksum | sed 's/./& /g'))
- # Picking items from the array
- for position_number in $(seq 0 $max_position_number); do
- # Identifying what type of position is dealt with: odd or even; if
- # the position is odd, a vowel is picked and vice versa
- parity_flag=$((position_number % 2))
- if test $parity_flag -eq 0; then
- position_contents=${array[position_number]}
- # As there are only 5 items in the "vowels" array and the
- # value of each checksum digit may range from 0 to 9, each
- # index value is divided by two
- vowel_array_index=$((position_contents / 2))
- # A vowel from the "vowel" array is picked and output to
- # stdout
- echo -n ${vowels[$vowel_array_index]}
- # The remainder is not wasted: it influences the choice of the
- # following consonant letter
- if test $position_contents -gt 4; then
- carry=$((position_contents - 4))
- fi
- else
- position_contents=${array[position_number]}
- # The remainder is added to an index used to pick a consonant
- consonant_array_index=$((position_contents + carry))
- echo -n ${consonants[$consonant_array_index]}
- carry=0
- fi
- parity_flag=0
- done
- # A newline is added
- echo
Add Comment
Please, Sign In to add comment