Reputation: 5
i am making a program for me to use in school (on a public server) and some people are changing it and ruining my passwords that are stored in it, could someone please tell me how to convert a string to binary or hex and vice-versa so that people cant see the passwords bear in mind that the people in school are not so brilliant at coding and will be fooled by something quite simple i also dont think that i have the rights to install things on the school computers.
Upvotes: 0
Views: 462
Reputation: 485
Besides the fact, that you should not store your passwords so accessible, the base64 module does exactly what you want.
Here an example:
from base64 import b64encode, b64decode
mypw = "mypassword".encode() # needs to be a binary-string
encrPW = b64encode(mypw) # equals b'bXlwYXNzd29yZA=='
assert mypw == b64decode(encrPW) # decoding results in the password
strPW = mypw.decode() # the python-string representation of the password
# (most possibly the one you need later on)
Upvotes: 1