Reputation: 1478
So I have a file that I have already encoded with base64, now I want to decode it back but instead of creating another file, I want to decode it in the console and print the results to screen. How to do that?
encoded file string = MUhRRy1ITVRELU0zWDItNlcxSA==
FYI: this would mean first opening the file in console, then decoding the give string
Thanks
Upvotes: 0
Views: 1656
Reputation: 29
This python simple script help you instantly
import base64
encode_pass = 'ENCODED-STRING-TO-BE-DECODED'
def decode_string(string):
decoded_bytes = base64.b64decode(string.encode())
return decoded_bytes.decode()
decoded_password=decode_string(encode_pass)
print(f"Decoded Password: {decoded_password}")
Upvotes: 0
Reputation: 368954
Using base64.decode, set sys.stdout
(sys.stdout.buffer.raw
in python 3.x) as output.
import sys
import base64
with open('filepath') as f:
base64.decode(f, sys.stdout)
Upvotes: 1
Reputation: 37319
Unless I'm overlooking something, this is as simple as reading in your encoded string and then calling the standard library's base64.b64decode
function on it.
Something like:
with open(path_to_encoded_file) as encoded_file:
print base64.b64decode(encoded_file.read().strip())
Upvotes: 2