Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/bash
- # 16 juli 2018 by Hendriyawan (gdev)
- # thanks to : stackoverflow
- # program bash untuk konversi text
- # text ke ascii
- # text ke hexadesimal
- # text ke octal
- # ini method / fungsi ubah text ke ascii
- text_to_ascii(){
- words=$1
- ascii_code=() #ini list dalam pemrograman bash
- for ((i=0; i < ${#words}; i++)); do
- ascii=$(printf %d \'${words:$i:1})
- #menambahkan ke list
- ascii_code+=($ascii)
- done
- echo ""
- echo -e "ASCII : \033[1;32m${ascii_code[@]}\033[0m"
- echo ""
- # [@] = artinya menampilkan seluruh item list
- }
- # ini method / fungsi ubah text ke hexadecimal
- text_to_hex(){
- words=$1
- hexacode=() #ini list dalam pemrograman bash
- for ((i=0; i < ${#words}; i++)); do
- hexadecimal=$(printf %X \'${words:$i:1})
- hexacode+=($hexadecimal)
- done
- echo ""
- echo -e "HEXADECIMAL : \033[1;32m${hexacode[@]}\033[0m"
- echo ""
- # [@] = artinya menampilkan seluruh item list
- }
- # ini method / fungsi ubah text ke octal
- text_to_octal(){
- words=$1
- octal_code=()
- for ((i=0; i < ${#words}; i++)); do
- octal=$(printf %o \'${words:$i:1})
- octal_code+=($octal)
- done
- echo ""
- echo -e "OCTAL : \033[1;32m${octal_code[@]}\033[0m"
- echo ""
- }
- options=$1
- words=$2
- if [ -z $options ] || [ -z $words ]; then
- echo "gunakan : texttool [options] kata/kalimat !"
- echo "options are :"
- echo "-tta\t ubah text ke ascii"
- echo "-tth\t ubah text ke hexadecimal"
- echo ""
- exit 1
- elif [ $options == "-tta" ]; then
- text_to_ascii $words
- elif [ $options == "-tth" ]; then
- text_to_hex $words
- elif [ $options == "-tto" ]; then
- text_to_octal $words
- fi
Add Comment
Please, Sign In to add comment