Guest User

Untitled

a guest
Feb 19th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. #!/bin/sh
  2. # this script help find possible order of base64 fragment.
  3. #
  4. # like "hello world" is aGVsbG8gd29ybGQ= ,
  5. # it would help find "hello world" from "G8g Vsb d2 9yb GQ= aG"
  6. #
  7. # usage: sh find-base64-fragment-order.sh $known_start $frag1 $frag2 ...
  8. # unknown init base:
  9. # sh find-base64-fragment-order.sh '' G8g Vsb d2 9yb GQ= aG
  10. # know start with h, which is `a` in base64, so first is `aG`
  11. # sh find-base64-fragment-order.sh aG G8g Vsb d2 9yb GQ=
  12. #
  13. # just pick the longest match pattern,
  14. # because wrong base64 code # often cause
  15. # mojibake (like not printable text)
  16. #
  17. # need: base64 awk grep
  18.  
  19.  
  20. nth() {
  21. echo $list | awk "{print \$$1}"
  22. }
  23.  
  24. debase64() {
  25. echo $1 | base64 -d 2>/dev/null
  26. }
  27.  
  28. all_match() {
  29. for next in $list
  30. do
  31. debase64 "$base$next"
  32. echo
  33. done
  34. }
  35.  
  36. filter_out() {
  37. match=$1
  38. echo $list | sed 's/ /\n/g' | grep --invert-match "^$match\$"
  39. }
  40.  
  41. base=$1
  42. shift
  43. list="$*"
  44.  
  45. while [ -n "$list" ]
  46. do
  47. echo
  48. echo base: $base
  49. echo list: $list
  50. echo possible match:
  51. all_match "$base" $list | nl
  52. echo -n 'which one most possible? '
  53. read n
  54. match_frag=$(nth $n $list)
  55. base="$base$match_frag"
  56. list=$(filter_out $match_frag $list)
  57. done
  58.  
  59. debase64 $base
Add Comment
Please, Sign In to add comment