6

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 python shell, when i use the base64 i had a different output.

#Linux promt

Command : echo 'HelloWorld' | base64

Output  : SGVsbG9Xb3JsZAo=

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

Output  : SGVsbG9Xb3JsZAo=

--== inside of python ==--

import base64

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

output :

b'HelloWord'
b'SGVsbG9Xb3JsZA=='

what i can do ? And why this is happening ? Thanks all.

Solved :

Why that happens :

because the echo put " \n " on the end of string.

Davi Mello
  • 173
  • 8

1 Answers1

11

You forgot that echo outputs a newline.

$ echo -n 'HelloWorld' | base64
SGVsbG9Xb3JsZA==
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358