Skip to content

Commit

Permalink
πŸ—“ Mar 6, 2022 7:52:24 PM
Browse files Browse the repository at this point in the history
✨ google_search_ei_to_epoch
πŸ” update rot47 with amount arg
πŸ§ͺ tests added/updated
  • Loading branch information
securisec committed Mar 7, 2022
1 parent 21901e4 commit 631a999
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 8 deletions.
2 changes: 1 addition & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ Misc:
Archive:
βœ” split by newline @project(New ideas)
βœ” string to leetcode @project(New ideas)


2 changes: 1 addition & 1 deletion chepy/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "3.5.0" # pragma: no cover
__version__ = "3.5.1" # pragma: no cover
__author__ = "Hapsida @securisec" # pragma: no cover
7 changes: 5 additions & 2 deletions chepy/modules/encryptionencoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,15 @@ def rot_13(self) -> EncryptionEncodingT:
return self

@ChepyDecorators.call_stack
def rot_47(self) -> EncryptionEncodingT:
def rot_47(self, amount: int=14) -> EncryptionEncodingT:
"""ROT 47 encoding
A slightly more complex variation of a caesar cipher, which includes
ASCII characters from 33 '!' to 126 '~'. Default rotation: 47.
Args:
amount (int, optional): Amount to rotate by. Defaults to 14.
Returns:
Chepy: The Chepy object.
Expand All @@ -151,7 +154,7 @@ def rot_47(self) -> EncryptionEncodingT:
for i in range(len(self.state)):
j = ord(self.state[i])
if j >= 33 and j <= 126:
x.append(chr(33 + ((j + 14) % 94)))
x.append(chr(33 + ((j + amount) % 94)))
else: # pragma: no cover
x.append(self.state[i])
self.state = "".join(x)
Expand Down
2 changes: 1 addition & 1 deletion chepy/modules/encryptionencoding.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class EncryptionEncoding(ChepyCore):
def rotate(self: EncryptionEncodingT, rotate_by: int) -> EncryptionEncodingT: ...
def rotate_bruteforce(self: EncryptionEncodingT) -> EncryptionEncodingT: ...
def rot_13(self: EncryptionEncodingT) -> EncryptionEncodingT: ...
def rot_47(self: EncryptionEncodingT) -> EncryptionEncodingT: ...
def rot_47(self: EncryptionEncodingT, amount: int=...) -> EncryptionEncodingT: ...
def xor(self: EncryptionEncodingT, key: str, key_type: Literal['hex', 'utf', 'base64']=..., ascii: bool=...) -> EncryptionEncodingT: ...
def xor_bruteforce(self: EncryptionEncodingT, length: int=...) -> EncryptionEncodingT: ...
def jwt_decode(self: EncryptionEncodingT) -> EncryptionEncodingT: ...
Expand Down
20 changes: 20 additions & 0 deletions chepy/modules/links.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import base64
from typing import TypeVar

import regex as re
Expand Down Expand Up @@ -46,3 +47,22 @@ def github_to_raw(self) -> LinksT:
),
)
return self

@ChepyDecorators.call_stack
def google_search_ei_to_epoch(self) -> LinksT:
"""Convert a google search ei query param to epoch
Returns:
Chepy: The Chepy object.
Examples:
>>> Chepy("Bh8hYqykHc64mAXkkoTgCg==").google_search_ei_to_epoch()
1646337798
"""
decoded = base64.urlsafe_b64decode(self._convert_to_str())
timestamp = ord(chr(decoded[0]))
timestamp += ord(chr(decoded[1])) * 256
timestamp += ord(chr(decoded[2])) * 256 ** 2
timestamp += ord(chr(decoded[3])) * 256 ** 3
self.state = timestamp
return self
1 change: 1 addition & 0 deletions chepy/modules/links.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ class Links(ChepyCore):
state: Any = ...
def pastebin_to_raw(self) -> LinksT: ...
def github_to_raw(self) -> LinksT: ...
def google_search_ei_to_epoch(self) -> LinksT: ...
9 changes: 9 additions & 0 deletions hold47.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def rot47(data):
decode = []
for i in range(len(data)):
encoded = ord(data[i])
if encoded >= 33 and encoded <= 126:
decode.append(chr(33 + ((encoded + 14) % 94)))
else:
decode.append(data[i])
return ''.join(decode)
10 changes: 7 additions & 3 deletions tests/test_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ def test_pastebin_to_raw():

def test_github_to_raw():
assert (
Chepy(
"https://github.com/securisec/chepy/blob/master/README.md"
).github_to_raw().o
Chepy("https://github.com/securisec/chepy/blob/master/README.md")
.github_to_raw()
.o
== "https://raw.githubusercontent.com/securisec/chepy/master/README.md"
)


def test_google_search_ei_to_epoch():
assert Chepy("Bh8hYqykHc64mAXkkoTgCg==").google_search_ei_to_epoch().o == 1646337798


# def test_to_unix_ts():
# assert Chepy("Sun Nov 10 17:57:29 2019").to_unix_ts().o == 1573426649

0 comments on commit 631a999

Please sign in to comment.