0

Here is my code.

import base64

encoded = base64.b64encode(b"data to be encoded")
print(encoded)
print(encoded.replace("b", ""))

Here is my output

b'ZGF0YSB0byBiZSBlbmNvZGVk'
Traceback (most recent call last):
File "C:\Users\user\Desktop\base64_obfuscation.py", line 8, in <module>
print(decoded.replace("b", ""))
TypeError: a bytes-like object is required, not 'str'

My overall task is to remove the single quotes and the "b" chracter from the string but I'm unsure on how to do so?

y.luis.rojo
  • 1,794
  • 4
  • 22
  • 41
  • 1
    The b part at the front is there to indicate it's a bytes object. It's how python prints stuff. The same for the quotes. – Reti43 Oct 13 '17 at 11:02

1 Answers1

-2
print(str(encoded).replace("b", ""))
y.luis.rojo
  • 1,794
  • 4
  • 22
  • 41
  • Thank you very much for the quick reply how would I remove the quotes as well? –  Oct 13 '17 at 11:03
  • @99Con Are you sure this is what you want? If `ZGF0YSB0byBiZSBlbmNvZGVk` is your base-64 string, this will result to `ZGF0YSB0yBiZSBlmNvZGVk`. – Reti43 Oct 13 '17 at 11:05
  • `print(str(encoded).replace("b", "").strip('"\''))` (https://stackoverflow.com/a/1482660/3286487) – y.luis.rojo Oct 13 '17 at 11:05
  • 2
    I downvoted since it is a) a solution to something that is no real problem and b) will damage the data if there is any `b` in the encoded data. – Klaus D. Oct 13 '17 at 11:27
  • It is a solution to the problem stated as it is. If you consider it is a "real problem" or not, you (down)vote on the problem, not the solution. Also, how could you decide whether it damages the data or not? You do not know the original problem requirements. It may be a simplification. – y.luis.rojo Oct 13 '17 at 14:15