1

I am attempting to do the matasano cryptopals challenges in bash.

The first step is here

I found this stackexchange thread with a partial solution.

printf 49276d2 | xxd -r -p | base64

which produces SSdt as wanted.

I am looking to make a bash script so I can simply do

hexto64 49276d2 

and get the same result. I'm not sure where to start after the #!/bin/bash . I have not found a similar example which takes arguments and pipes them through other commands and then outputs a result.

1 Answer 1

4

In your script file named hexto64, simply write :

#!/bin/bash

printf "%s" "$1" | xxd -r -p | base64

And then you can use it as such :

hexto64 49276d2

Just so you know, $1 means the first parameter you gave after the program name : 49276d2 in our case.

2
  • 1
    Needs to be executable (chmod a+x hexto64) and placed somewhere in the PATH. I favour $HOME/bin/ myself but others might not. Commented May 26, 2015 at 23:01
  • Combing what you both said worked well. Thanks. Commented May 26, 2015 at 23:06

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.