Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Base64 (GNU/Linux vs Python) [duplicate]

On Linux I can use the command "base64" to encode a string or "python -m base64 -e". They had the same output, but inside of the Python shell, when I use the base64, I had a different output.

#Linux prompt

Command : echo 'HelloWorld' | base64

Output  : SGVsbG9Xb3JsZAo=

Command : echo 'HelloWorld' | python -m base64 -e

Output  : SGVsbG9Xb3JsZAo=

--== inside of the Python shell ==--

import base64

word = "HelloWorld".encode()
new_word = base64.b64encode(word)
print(word)
print(new_word)

Output:

b'HelloWord'
b'SGVsbG9Xb3JsZA=='

What can I do? And why this is happening?

Solved:

Why that happens:

Because the echo puts " \n " at the end of the string.

like image 869
Davi Mello Avatar asked Aug 29 '26 18:08

Davi Mello


1 Answers

You forgot that echo outputs a newline.

$ echo -n 'HelloWorld' | base64
SGVsbG9Xb3JsZA==
like image 157
Ignacio Vazquez-Abrams Avatar answered Aug 31 '26 07:08

Ignacio Vazquez-Abrams



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!