Skip to content

Commit

Permalink
Confirmed B64 encode and decode works
Browse files Browse the repository at this point in the history
Issue #5
  • Loading branch information
damies13 committed Apr 8, 2023
1 parent f46baf1 commit f8819ca
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/modules/h2r_base64.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self, parent):
#

b64 = "03:self.h2r_base64.base64_decode"
if b64 not in self.parent.encoders:
if b64 not in self.parent.decoders:
self.parent.decoders[b64] = {}
self.parent.decoders[b64]["robottranscode"] = "self.h2r_base64.base64_encode"

Expand All @@ -40,10 +40,12 @@ def __init__(self, parent):
#

def base64_encode(self, s):
self.parent.debugmsg(9, "s:", s)
try:
s_bytes = s.encode('utf_8')
base64_bytes = base64.b64encode(s_bytes)
base64_s = base64_bytes.decode('utf_8')
self.parent.debugmsg(5, "s:", s, " base64_s:", base64_s)
return base64_s
except Exception:
return s
Expand All @@ -53,14 +55,21 @@ def base64_encode(self, s):
#

def base64_decode(self, s):
self.parent.debugmsg(9, "s:", s)
try:
# s_bytes = s.encode('utf_8')
s_bytes = s.encode()
self.parent.debugmsg(8, "s_bytes:", s_bytes)
dec_bytes = base64.b64decode(s_bytes)
self.parent.debugmsg(8, "dec_bytes:", dec_bytes)
# dec_s = dec_bytes.decode('utf_8')
dec_s = dec_bytes.decode()
self.parent.debugmsg(8, "dec_s:", dec_s)
self.parent.debugmsg(5, "s:", s, " dec_s:", dec_s)
return dec_s
except Exception:
except Exception as e:
self.parent.debugmsg(8, "s:", s)
self.parent.debugmsg(8, "e:", e)
return s


Expand Down

0 comments on commit f8819ca

Please sign in to comment.