[Solved] Decoding reversed mulitline string encoded in base64 format automatically [closed]


From the OP’s comment:

list = ['LnNlbHBtYXhlIGVzdSBvdCBlZXJmIGxlZUYgLnNldGlzYmV3IGNpZmZhcnQgaGdpaCBubyBub2l0YXNpbGFtcm9uZWQgZm8gdHBlY25vYyBlaHQgZWJpcmNzZUQgLjQ=', 'ZWxpZiBlbm8gbmkgZWIgdHN1TSApaXYgICAg', 'c25vaXRhY2lmaWNlcHMgOC1QRVAgdGVlbSB0c3VNICl2ICAgIA==', 'Ni4yIG5vaHR5UCBodGl3IGtyb3cgdHN1TSApdmkgICAg', 'c2VsdWRvbSByZWh0byB5YiBlbGJhdHJvcG1pIGViIGRsdW9ocyBzc2FsQyApaWlpICAgIA==']
s="".join(list)
s = s.decode('base64', 'strict')
print (s[::-1])

the join operation connects all of the strings together, but only the first string is translated. This is because, when decoding a base 64 string, everything in the string past the first one or two = characters is ignored. Instead of joining, iterate:

list = ['LnNlbHBtYXhlIGVzdSBvdCBlZXJmIGxlZUYgLnNldGlzYmV3IGNpZmZhcnQgaGdpaCBubyBub2l0YXNpbGFtcm9uZWQgZm8gdHBlY25vYyBlaHQgZWJpcmNzZUQgLjQ=', 'ZWxpZiBlbm8gbmkgZWIgdHN1TSApaXYgICAg', 'c25vaXRhY2lmaWNlcHMgOC1QRVAgdGVlbSB0c3VNICl2ICAgIA==', 'Ni4yIG5vaHR5UCBodGl3IGtyb3cgdHN1TSApdmkgICAg', 'c2VsdWRvbSByZWh0byB5YiBlbGJhdHJvcG1pIGViIGRsdW9ocyBzc2FsQyApaWlpICAgIA==']
for s in list:
    s = s.decode('base64', 'strict')
    print (s[::-1])

Or use a list comprehension.

list = ['LnNlbHBtYXhlIGVzdSBvdCBlZXJmIGxlZUYgLnNldGlzYmV3IGNpZmZhcnQgaGdpaCBubyBub2l0YXNpbGFtcm9uZWQgZm8gdHBlY25vYyBlaHQgZWJpcmNzZUQgLjQ=', 'ZWxpZiBlbm8gbmkgZWIgdHN1TSApaXYgICAg', 'c25vaXRhY2lmaWNlcHMgOC1QRVAgdGVlbSB0c3VNICl2ICAgIA==', 'Ni4yIG5vaHR5UCBodGl3IGtyb3cgdHN1TSApdmkgICAg', 'c2VsdWRvbSByZWh0byB5YiBlbGJhdHJvcG1pIGViIGRsdW9ocyBzc2FsQyApaWlpICAgIA==']
print "\n".join(s.decode('base64')[::-1] for s in list)

Output:

4. Describe the concept of denormalisation on high traffic websites. Feel free to use examples.
    vi) Must be in one file
    v) Must meet PEP-8 specifications
    iv) Must work with Python 2.6
    iii) Class should be importable by other modules

solved Decoding reversed mulitline string encoded in base64 format automatically [closed]