Skip to content

UnicodeDecodeError while calling to_binary() #27

@laurenthuang

Description

@laurenthuang

Following code :

from chepy import Chepy
print(Chepy('80').from_hex().to_binary().o)

Causing the following exception:

UnicodeDecodeError Traceback (most recent call last)
Cell In[48], line 2
1 from chepy import Chepy
----> 2 print(Chepy('80').from_hex().to_binary().o)

File d:\codebase\CTF\tools\binary_recon.venv\lib\site-packages\decorator.py:232, in decorate..fun(*args, **kw)
230 if not kwsyntax:
231 args, kw = fix(args, kw, sig)
--> 232 return caller(func, *(extras + args), **kw)

File d:\codebase\CTF\tools\binary_recon.venv\lib\site-packages\chepy\core.py:51, in ChepyDecorators.call_stack(func, *args, **kwargs)
48 func_sig["args"] = func_arguments
49 func_self._stack.append(func_sig)
---> 51 return func(*args, **kwargs)

File d:\codebase\CTF\tools\binary_recon.venv\lib\site-packages\chepy\modules\dataformat.py:935, in DataFormat.to_binary(self, join_by)
920 @ChepyDecorators.call_stack
921 def to_binary(self, join_by: str = " ") -> DataFormatT:
922 """Convert string characters to binary
923
924 Args:
(...)
932 "01100001 01100010 01100011"
933 """
934 self.state = join_by.join(
--> 935 list(format(ord(s), "08b") for s in list(self._convert_to_str()))
936 )
937 return self

File d:\codebase\CTF\tools\binary_recon.venv\lib\site-packages\chepy\core.py:583, in ChepyCore._convert_to_str(self)
573 """This method is used to coerce the curret object in
574 the state variable into bytes. The method should be
575 called inside any method that operates on a bytes object
(...)
580 for the current state type.
581 """
582 if isinstance(self.state, bytes):
--> 583 return self.state.decode()
584 elif isinstance(self.state, str):
585 return self.state

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions