Angelo Fazzina
Angelo Fazzina

Reputation: 35

base64 syntax in python is not working

this code works on the command line.

python -c 'import base64,sys; u,p=sys.argv[1:3]; print  base64.encodestring("%s\x00%s\x00%s" % (u,u,p))' user pass

output is dXNlcgB1c2VyAHBhc3M=

I am trying to get this to work in my script

test = base64.encodestring("{0}{0}{1}").format(acct_name,pw)
print test

output is ezB9ezB9ezF9

anyone no what i am doing wrong ? thank you.

Upvotes: 0

Views: 253

Answers (2)

Angelo Fazzina
Angelo Fazzina

Reputation: 35

Thanks SZYM i am all set. This is the code that gets it to work

test = base64.encodestring("{0}\x00{0}\x00{1}".format(acct_name,pw))

Turns out the hex \x00 is needed so program getting the hash knows where username stops and password begins. -ALF

Upvotes: 0

szym
szym

Reputation: 5846

You have a mistake in parenthesis. Instead of:

test = base64.encodestring("{0}{0}{1}").format(acct_name,pw)

(which first encodes "{0}{0}{1}" in base64 and then tries to substitute variables using format),

you should have

test = base64.encodestring("{0}{0}{1}".format(acct_name,pw))

(which first substitutes variables using format and then encodes in base64).

Upvotes: 1

Related Questions