MCPcopy Create free account
hub / github.com/subbarayudu-j/TheAlgorithms-Python / decodeBase64

Function decodeBase64

ciphers/base64_cipher.py:26–56  ·  view source on GitHub ↗
(text)

Source from the content-addressed store, hash-verified

24 return r[0: len(r)-len(p)] + p
25
26def decodeBase64(text):
27 base64chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
28 s = ""
29
30 for i in text:
31 if i in base64chars:
32 s += i
33 c = ""
34 else:
35 if i == '=':
36 c += '='
37
38 p = ""
39 if c == "=":
40 p = 'A'
41 else:
42 if c == "==":
43 p = "AA"
44
45 r = ""
46 s = s + p
47
48 i = 0
49 while i < len(s):
50 n = (base64chars.index(s[i]) << 18) + (base64chars.index(s[i+1]) << 12) + (base64chars.index(s[i+2]) << 6) +base64chars.index(s[i+3])
51
52 r += chr((n >> 16) & 255) + chr((n >> 8) & 255) + chr(n & 255)
53
54 i += 4
55
56 return r[0: len(r) - len(p)]
57
58def main():
59 print(encodeBase64("WELCOME to base64 encoding"))

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected