Friday, December 30, 2016

Convert String to Base64 in Python


Code to convert string (from utf-8) to base64 encoding and base64 back to utf-8:

import base64

si = input('\nenter text:\n')
print('\nyou entered\n' + si)

b64 = base64.b64encode(bytes(si, 'utf-8'))
print('\nbase64 is\n' + str(b64))

b64_bs = bytearray(base64.b64encode(bytes(si, 'utf-8')))
print('\nbase64 byte stream is\n' + str(list(b64_bs)))

so = base64.b64decode(b64).decode('utf-8', 'ignore')
print('\nstring is\n' + so)

6 comments:

  1. To alter video, finished edition genius and imovie both are magnificent, however they likewise has the basic issue, they are not perfect with avchd record position well.AnyConv

    ReplyDelete
  2. Here in Mac The Ripper Lion, you get the choices to set your locale code to '0" for all inclusive playing choice. FLV to MP4 video converter

    ReplyDelete
  3. The entire conversion process is also a breeze with the user only to perform a few clicks to complete the whole conversion within limited time. Since the screens are extremely user friendly and self explanatory, file converter

    ReplyDelete
  4. Excellent article and a truly amazing blog Keep it up. Same Day Geek is a reputed computer and IT Support firm in Canada.

    ReplyDelete
  5. And most of them have adopted the new changes. So, the scope in this field is quite impressive in India. 360DigiTMG data science training in hyderabad

    ReplyDelete