Sunday, April 20, 2014

ASCII to Hex Encoder Another Version of a Previous Encoder

#!/bin/bash

# Usage: ./script-name <ASCII FILE> | tr -d '\n' > <ENCODED FILE>
# Take a file as the input

testInput=$1

function encode {

    case ${1} in
        "") echo "\x20" ;; "!") echo "\x21" ;; "\"") echo "\x22" ;;
        "#") echo "\x23"    ;; "$") echo "\x24" ;; "&") echo "\x26" ;;
        "%") echo "\x25"    ;; "'") echo "\x27" ;; "(") echo "\x28" ;;
        ")") echo "\x29" ;; '*') echo '\x2a' ;; '+') echo '\x2b' ;; 
        ',') echo '\x2c' ;; '-') echo '\x2d' ;; '.') echo '\x2e' ;; 
        "/") echo '\x2f' ;; '0') echo '\x30' ;; '1') echo '\x31' ;; 
        '2') echo '\x32' ;; '3') echo '\x33' ;; '4') echo '\x34' ;; 
        '5') echo '\x35' ;; '6') echo '\x36' ;; '7') echo '\x37' ;; 
        '8') echo '\x38' ;; '9') echo '\x39' ;; ':') echo '\x3a' ;; 
        ';') echo '\x3b' ;; '<') echo '\x3c' ;; '=') echo '\x3d' ;; 
        '>') echo '\x3e' ;; '?') echo '\x3f' ;; '@') echo '\x40' ;;
        'A') echo '\x41' ;; 'B') echo '\x42' ;; 'C') echo '\x43' ;; 
        'D') echo '\x44' ;; 'E') echo '\x45' ;; 'F') echo '\x46' ;; 
        'G') echo '\x47' ;; 'H') echo '\x48' ;; 'I') echo '\x49' ;; 
        'J') echo '\x4a' ;; 'K') echo '\x4b' ;; 'L') echo '\x4c' ;; 
        'M') echo '\x4d' ;; 'N') echo '\x4e' ;; 'O') echo '\x4f' ;; 
        'P') echo '\x50' ;; 'Q') echo '\x51' ;; 'R') echo '\x52' ;; 
        'S') echo '\x53' ;; 'T') echo '\x54' ;; 'U') echo '\x55' ;; 
        'V') echo '\x56' ;; 'W') echo '\x57' ;; 'X') echo '\x58' ;; 
        'Y') echo '\x59' ;; 'Z') echo '\x5a' ;; '[') echo '\x5b' ;; 
        '\\') echo '\x5c' ;; ']') echo '\x5d' ;; '^') echo '\x5e' ;; 
        '_') echo '\x5f' ;; '`') echo '\x60' ;; 'a') echo '\x61' ;; 
        'b') echo '\x62' ;; 'c') echo '\x63' ;; 'd') echo '\x64' ;; 
        'e') echo '\x65' ;; 'f') echo '\x66' ;; 'g') echo '\x67' ;; 
        'h') echo '\x68' ;; 'i') echo '\x69' ;; 'j') echo '\x6a' ;; 
        'k') echo '\x6b' ;; 'l') echo '\x6c' ;; 'm') echo '\x6d' ;; 
        'n') echo '\x6e' ;; 'o') echo '\x6f' ;; 'p') echo '\x70' ;; 
        'q') echo '\x71' ;; 'r') echo '\x72' ;; 's') echo '\x73' ;; 
        't') echo '\x74' ;; 'u') echo '\x75' ;; 'v') echo '\x76' ;; 
        'w') echo '\x77' ;; 'x') echo '\x78' ;; 'y') echo '\x79' ;; 
        'z') echo '\x7a' ;; '{') echo '\x7b' ;; '|') echo '\x7c' ;; 
        '}') echo '\x7d' ;; '~') echo '\x7e' ;;
        *) echo $1 ;;
    esac

}

while read line
do


    for (( c=0; c<${#line}; c++ ))
    do
        encode ${line:$c:1} 
    done

    echo "\x0a"


done < $testInput

echo "\n"

No comments:

Post a Comment

Powershell - Gather Mapped Drives from a List of Computer Names

I created the following Powershell script to gather remotely the mapped drives that users had in their profiles.  I had to create the script...