Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # this script help find possible order of base64 fragment.
- #
- # like "hello world" is aGVsbG8gd29ybGQ= ,
- # it would help find "hello world" from "G8g Vsb d2 9yb GQ= aG"
- #
- # usage: sh find-base64-fragment-order.sh $known_start $frag1 $frag2 ...
- # unknown init base:
- # sh find-base64-fragment-order.sh '' G8g Vsb d2 9yb GQ= aG
- # know start with h, which is `a` in base64, so first is `aG`
- # sh find-base64-fragment-order.sh aG G8g Vsb d2 9yb GQ=
- #
- # just pick the longest match pattern,
- # because wrong base64 code # often cause
- # mojibake (like not printable text)
- #
- # need: base64 awk grep
- nth() {
- echo $list | awk "{print \$$1}"
- }
- debase64() {
- echo $1 | base64 -d 2>/dev/null
- }
- all_match() {
- for next in $list
- do
- debase64 "$base$next"
- echo
- done
- }
- filter_out() {
- match=$1
- echo $list | sed 's/ /\n/g' | grep --invert-match "^$match\$"
- }
- base=$1
- shift
- list="$*"
- while [ -n "$list" ]
- do
- echo
- echo base: $base
- echo list: $list
- echo possible match:
- all_match "$base" $list | nl
- echo -n 'which one most possible? '
- read n
- match_frag=$(nth $n $list)
- base="$base$match_frag"
- list=$(filter_out $match_frag $list)
- done
- debase64 $base
Add Comment
Please, Sign In to add comment