Skip to content

Commit

Permalink
πŸ“… Commit Sat, 25 Sep 2021 22:01:32
Browse files Browse the repository at this point in the history
✨ swap_strings method
✨ int_to_base method
βœ… tests added/updated
  • Loading branch information
securisec committed Sep 26, 2021
1 parent b234c18 commit 2661bf2
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 3 deletions.
3 changes: 3 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ New ideas:
☐ fuzzy search
☐ pgp, generate, encrypt, decrypt, verify
☐ swap little and big endian
☐ ignore error method
☐ swap bytes

Bug:

Expand Down Expand Up @@ -47,6 +49,7 @@ Misc:
☐ cyberchef recipe to chepy recipe converter

Archive:
βœ” convert int to specified base. like int(.., base) @project(New ideas)
βœ” crib dragging @project(New ideas)
βœ” xor data with key @project(Utility)
βœ” strip ansi color codes @project(New ideas)
Expand Down
15 changes: 14 additions & 1 deletion chepy/modules/aritmeticlogic.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import binascii
import statistics
from typing import TypeVar
from typing import TypeVar, Union

from ..core import ChepyCore, ChepyDecorators
from .exceptions import StateNotList
Expand Down Expand Up @@ -144,3 +144,16 @@ def median(self) -> AritmeticLogicT:
numbers = list(self.__hex_to_int(x) for x in self.state)
self.state = statistics.median(numbers)
return self

@ChepyDecorators.call_stack
def int_to_base(self, base: Union[int, str]) -> AritmeticLogicT:
"""Convert the state to a different base
Args:
base (int): Base to convert to
Returns:
Chepy: The Chepy object.
"""
self.state = int(self.state, base)
return self
3 changes: 2 additions & 1 deletion chepy/modules/aritmeticlogic.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from ..core import ChepyCore
from typing import Any, TypeVar
from typing import Any, TypeVar, Union

AritmeticLogicT = TypeVar("AritmeticLogicT", bound="AritmeticLogic")

Expand All @@ -15,3 +15,4 @@ class AritmeticLogic(ChepyCore):
def sum(self: AritmeticLogicT) -> AritmeticLogicT: ...
def mean(self: AritmeticLogicT) -> AritmeticLogicT: ...
def median(self: AritmeticLogicT) -> AritmeticLogicT: ...
def int_to_base(self: AritmeticLogicT, base: Union[int, str]) -> AritmeticLogicT: ...
15 changes: 15 additions & 0 deletions chepy/modules/dataformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1068,3 +1068,18 @@ def convert_to_nato(self, join_by: str = " ") -> DataFormatT:
hold.append(d)
self.state = join_by.join(hold)
return self

@ChepyDecorators.call_stack
def swap_strings(self, by: int) -> DataFormatT:
"""Swap characters in string
Args:
by (int): Number of bytes to swap
Returns:
Chepy: The Chepy object
"""
t = list(self.state)
t[::by], t[1::by] = t[1::by], t[::by]
self.state = "".join(t)
return self
1 change: 1 addition & 0 deletions chepy/modules/dataformat.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,4 @@ class DataFormat(ChepyCore):
def from_braille(self: DataFormatT) -> DataFormatT: ...
def trim(self: DataFormatT) -> DataFormatT: ...
def convert_to_nato(self: DataFormatT, join_by:str) -> DataFormatT: ...
def swap_strings(self: DataFormatT, by:int) -> DataFormatT: ...
3 changes: 3 additions & 0 deletions tests/test_aritmeticlogic.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ def test_median():
def test_subtract():
assert Chepy(["0x02", "0x04"]).loop_list("subtract", {"n": 1}).o == [1, 3]


def test_int_to_base():
assert Chepy("067165").int_to_base(8).o == 28277
7 changes: 6 additions & 1 deletion tests/test_dataformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def test_yaml_to_json():
BSc in the Internet of Things
"""
assert (
Chepy(data).yaml_to_json().o != ""
Chepy(data).yaml_to_json().o
!= ""
# == '{"name":"Martin D\'vloper","job":"Developer","skill":"Elite","employed":true,"foods":["Apple","Orange","Strawberry","Mango"],"languages":{"perl":"Elite","python":"Elite","pascal":"Lame"},"education":"4 GCSEs\\n3 A-Levels\\nBSc in the Internet of Things\\n"}'
)

Expand Down Expand Up @@ -347,3 +348,7 @@ def test_from_hexdump():

def test_nato_convert():
assert Chepy("abc:1").convert_to_nato().o == "Alpha Bravo Charlie : 1"


def test_swap_strings():
assert Chepy("oY u").swap_strings(2).o == "You "

0 comments on commit 2661bf2

Please sign in to comment.