Skip to content

Commit c06ee58

Browse files
committed
Renamed debase to unbase
1 parent 2944192 commit c06ee58

3 files changed

Lines changed: 33 additions & 21 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Check the [documentation](https://python-codext.readthedocs.io/en/latest/howto.h
2626

2727
<p align="center"><img src="https://raw.githubusercontent.com/dhondta/python-codext/master/docs/demos/using-codext.gif" alt="Using CodExt from the command line"></p>
2828
<p align="center"><img src="https://raw.githubusercontent.com/dhondta/python-codext/master/docs/demos/using-bases.gif" alt="Using base tools from the command line"></p>
29-
<p align="center"><img src="https://raw.githubusercontent.com/dhondta/python-codext/master/docs/demos/using-debase.gif" alt="Using the debase command line tool"></p>
29+
<p align="center"><img src="https://raw.githubusercontent.com/dhondta/python-codext/master/docs/demos/using-unbase.gif" alt="Using the unbase command line tool"></p>
3030

3131
## :computer: Usage (main CLI tool) <a href="https://twitter.com/intent/tweet?text=CodExt%20-%20Encode%2Fdecode%20anything.%0D%0APython%20tool%20for%20encoding%20and%20decoding%20almost%20anything,%20including%20a%20guess%20feature%20based%20on%20AI.%0D%0Ahttps%3a%2f%2fgithub%2ecom%2fdhondta%2fpython-codext%0D%0A&hashtags=python,encodings,codecs,cryptography,morse,base,stegano,steganography,ctftools"><img src="https://img.shields.io/badge/Tweet%20(codext)--lightgrey?logo=twitter&style=social" alt="Tweet on codext" height="20"/></a>
3232

@@ -80,7 +80,7 @@ $ codext list macros
8080
example-macro
8181
```
8282

83-
## :computer: Usage (base CLI tool) <a href="https://twitter.com/intent/tweet?text=Debase%20-%20Decode%20any%20multi-layer%20base-encoded%20string.%0D%0APython%20tool%20for%20decoding%20any%20base-encoded%20string,%20even%20when%20encoded%20with%20multiple%20layers.%0D%0Ahttps%3a%2f%2fgithub%2ecom%2fdhondta%2fpython-codext%0D%0A&hashtags=python,base,encodings,codecs,cryptography,stegano,steganography,ctftools"><img src="https://img.shields.io/badge/Tweet%20(debase)--lightgrey?logo=twitter&style=social" alt="Tweet on debase" height="20"/></a>
83+
## :computer: Usage (base CLI tool) <a href="https://twitter.com/intent/tweet?text=UnBase%20-%20Decode%20any%20multi-layer%20base-encoded%20string.%0D%0APython%20tool%20for%20decoding%20any%20base-encoded%20string,%20even%20when%20encoded%20with%20multiple%20layers.%0D%0Ahttps%3a%2f%2fgithub%2ecom%2fdhondta%2fpython-codext%0D%0A&hashtags=python,base,encodings,codecs,cryptography,stegano,steganography,ctftools"><img src="https://img.shields.io/badge/Tweet%20(unbase)--lightgrey?logo=twitter&style=social" alt="Tweet on unbase" height="20"/></a>
8484

8585
```session
8686
$ echo "Test string !" | base122
@@ -100,10 +100,10 @@ Test string !
100100
```
101101

102102
```session
103-
$ echo "Test string !" | base91 | base85 | base36 | base58-flickr | debase -m 3
103+
$ echo "Test string !" | base91 | base85 | base36 | base58-flickr | unbase -m 3
104104
Test string !
105105
106-
$ echo "Test string !" | base91 | base85 | base36 | base58-flickr | debase -f Test
106+
$ echo "Test string !" | base91 | base85 | base36 | base58-flickr | unbase -f Test
107107
Test string !
108108
```
109109

codext/base/__init__.py

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,45 +13,57 @@
1313

1414

1515
def main():
16-
descr = """Usage: debase [OPTION]... [FILE]
17-
Base decode multi-layer FILE, or standard input, to standard output.
16+
descr = """Usage: unbase [OPTION]... [FILE]
17+
Decode multi-layer base encoded FILE, or standard input, to standard output.
1818
1919
With no FILE, or when FILE is -, read standard input.
2020
2121
Optional arguments:
22+
-e, --extended also consider generic base codecs while guess-decoding
2223
-f, --stop-function set the result chceking function (default: text)
23-
format: printables|text|flag|lang_[bigram]|[regex]
24-
-i, --ignore-generic ignore generic base codecs while guess-decoding
24+
format: printables|text|flag|lang_[bigram]
2525
-M, --max-depth maximum codec search depth (default: 5)
2626
-m, --min-depth minimum codec search depth (default: 0)
27-
-s, --do-not-stop do not stop if a valid output is found
27+
-p, --pattern pattern to be matched while searching
28+
-s, --show show the decoding chain
2829
2930
--help display this help and exit
3031
--verbose show guessing information and steps
3132
--version output version information and exit
3233
33-
Report debase bugs to <https://github.com/dhondta/python-codext/issues/new>
34+
Report unbase bugs to <https://github.com/dhondta/python-codext/issues/new>
3435
Full documentation at: <https://python-codext.readthedocs.io/en/latest/enc/base.html>
3536
"""
3637
parser = ArgumentParser(description=descr, formatter_class=RawTextHelpFormatter, add_help=False)
3738
parser.format_help = MethodType(lambda s: s.description, parser)
3839
parser.add_argument("file", nargs="?")
40+
parser.add_argument("-e", "--extended", action="store_true")
3941
parser.add_argument("-f", "--stop-function", default="text")
40-
parser.add_argument("-i", "--ignore-generic", action="store_true")
41-
parser.add_argument("-M", "--max-depth", default=5, type=int)
42-
parser.add_argument("-m", "--min-depth", default=0, type=int)
43-
parser.add_argument("-s", "--do-not-stop", action="store_true")
42+
parser.add_argument("-M", "--max-depth", type=int, default=10)
43+
parser.add_argument("-m", "--min-depth", type=int, default=0)
44+
parser.add_argument("-p", "--pattern")
45+
parser.add_argument("-s", "--show", action="store_true")
4446
parser.add_argument("--help", action="help")
4547
parser.add_argument("--version", action="version")
4648
parser.add_argument("--verbose", action="store_true")
4749
parser.version = "CodExt " + __version__
4850
args = parser.parse_args()
49-
excl = [[], ["base%d-generic" % i for i in range(2, 255)]][args.ignore_generic]
50-
sfunc = getattr(stopfunc, args.stop_function, args.stop_function)
51+
excl, s = [["base%d-generic" % i for i in range(2, 256)], []][args.extended], args.stop_function
52+
if re.match(r"lang_[a-z]{2}$", s) and all(re.match(r"lang_[a-z]{2}$", x) is None for x in dir(stopfunc)):
53+
stopfunc._reload_lang(stopfunc.LANG_BACKEND)
54+
#TODO: validate args.stop_function
55+
#TODO: make --stop-function and --pattern mutually exclusive
56+
sfunc = getattr(stopfunc, s, s)
5157
c = _input(args.file)
5258
c = c.rstrip("\r\n") if isinstance(c, str) else c.rstrip(b"\r\n")
53-
r = codecs.guess(c, sfunc, args.min_depth, args.max_depth, exclude=excl, codec_categories="base",
54-
stop=not args.do_not_stop, show=True, scoring_heuristic=False, debug=args.verbose)
55-
if not args.do_not_stop:
56-
print("Could not decode :-(" if len(r) == 0 else ensure_str(list(r.items())[0][1]))
59+
r = codecs.guess(c, sfunc, 0, args.max_depth, exclude=tuple(excl), codec_categories="base",
60+
stop=False, show=args.verbose, scoring_heuristic=False, debug=args.verbose)
61+
if len(r) == 0:
62+
print("Could not decode :-(")
63+
return 0
64+
ans = max(r.items(), key=lambda x: len(x[0]))
65+
if args.show:
66+
print(" - ".join(ans[0]))
67+
print(ensure_str(ans[1]))
68+
return 0
5769

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,4 @@ console_scripts =
7777
base100 = codext.base.base100:main100
7878
base122 = codext.base.base122:main122
7979
codext = codext.__init__:main
80-
debase = codext.base.__init__:main
80+
unbase = codext.base.__init__:main

0 commit comments

Comments
 (0)