Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Need Python script to decode or encode in base64
-
Hi,
Any one know the script to decode or encode in base64 because in FileZilla FTP client using the base64 encryption to encrypt passwords i need to decode those passwords for our record. Normally i am using mobile phone for travel so i need the python script for the same.
Note: I need prompt for input the encoded value & decoded value.
-
There's the
base64
module in the standard library. It can encode and decode base64, base32 and base16 ("hex").FYI, encoding is not the same as encryption. Encoding means converting data to a different format that can be converted back to the original format. For example, converting audio files to MP3, saving an image as PNG, writing a plain text file as UTF-8 or encoding data in base64 are all encoding, not encryption. In all cases you are able to (and want to) get back the original data.
Encryption means converting data in a way that normal people cannot easily find out the original data, but the intended recipient can. For example HTTPS (which uses SSL/TLS) is encryption - by looking at the data that is sent between client and server, you cannot see what they are talking about, but if you access a website over HTTPS your browser can display the result.
-
import base64 encsting = raw_input('Encoded Value:') decstring = base64.b64decode(encsting) print decstring
-
@filippocld Thank you.
-
@filippocld Hi, I have to do some modification, raw_input (From clipboard) without return a value & the output pasted to clipboard automatically. Please help me.
import base64
encsting = raw_input ('Encoded Value:' "from clipboard")
decstring = base64.b64decode (encsting)
print 'Decoded Value:',decstring "to clipboard -
import base64 import clipboard encsting = clipboard.get() decstring = base64.b64decode(encsting) clipboard.set(decstring)
-
@filippocld Thank you very much.
-
@filippocld I need some clarification in the below script.
from __future__ import absolute_import from __future__ import print_function import base64 import clipboard decoded = clipboard.get() encoded =base64.b64encode (decoded) clipboard.set(encoded) print("Encoded Value:" ,encoded, end=' ')
When i run the script in Python 2.7 i am getting output but in python 3.5 i am getting error. Please help me.
-
you did not say what error you get, but i can guess it relates to unicode vs bytes.
base64.encode takes a bytes object, you are giving it a string.
try replaceing decoded with decoded.encode('ascii') before passing into base64.b64encode