2018-11-13 16:47:00 +05:30
|
|
|
import base64 as b64
|
2018-11-15 15:41:01 +05:30
|
|
|
import re
|
2018-11-13 16:47:00 +05:30
|
|
|
|
2018-11-16 21:13:45 +05:30
|
|
|
|
2018-11-13 16:47:00 +05:30
|
|
|
def base64(string):
|
2018-11-16 21:13:45 +05:30
|
|
|
if re.match(r'^[A-Za-z0-9+\/=]+$', string) and (len(string) % 4) == 0:
|
|
|
|
|
return b64.b64decode(string.encode('utf-8')).decode('utf-8')
|
|
|
|
|
else:
|
|
|
|
|
return b64.b64encode(string.encode('utf-8')).decode('utf-8')
|