From 77b90fdf4dd3cc3f7a4c6deaec04b29122eb9b1a Mon Sep 17 00:00:00 2001 From: Roman Babenko Date: Sun, 10 Nov 2024 12:00:02 +0200 Subject: [PATCH] etc --- base64magic.py | 56 +++++++++++++++++++++++++++++++++++++ crc32file.py | 30 ++++++++++++++++++++ gnutar.py | 30 ++++++++++++++++++++ perf_enumerate.py | 71 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 187 insertions(+) create mode 100644 base64magic.py create mode 100644 crc32file.py create mode 100644 gnutar.py create mode 100644 perf_enumerate.py diff --git a/base64magic.py b/base64magic.py new file mode 100644 index 0000000..114e7ce --- /dev/null +++ b/base64magic.py @@ -0,0 +1,56 @@ +import base64 +import re +import string +import struct +import unittest + + +def gen_encoded(size, text=''): + size -= 1 + if 0 <= size: + for x in string.digits + string.ascii_letters: + yield from gen_encoded(size, text + x) + else: + yield text + + +def check_asc_or_desc(line_data_value: str) -> bool: + """ValuePatternCheck as example""" + count_asc = 1 + count_desc = 1 + for i in range(len(line_data_value) - 1): + if line_data_value[i] in string.ascii_letters + string.digits \ + and ord(line_data_value[i + 1]) - ord(line_data_value[i]) == 1: + count_asc += 1 + if 4 == count_asc: + return True + else: + count_asc = 1 + if line_data_value[i] in string.ascii_letters + string.digits \ + and ord(line_data_value[i]) - ord(line_data_value[i + 1]) == 1: + count_desc += 1 + if 4 == count_desc: + return True + else: + count_desc = 1 + continue + return False + + +def main(): + pattern_similar = re.compile(r"(\w)\1{3,}") + counter = 0 + for x in gen_encoded(4): + v="pA5s"+x + if pattern_similar.findall(v) or check_asc_or_desc(v): + continue + outer = sum(ord(i) for i in v) + data = base64.b64decode(v) + inner1, inner2, inner3 = struct.unpack(" 1 << 30: + print("Quota reached") + continue + with tf.extractfile(tfi) as f: + f_seek = f.seek(io.SEEK_END) + f_tell = f.tell() + if f_tell > 1 << 30: + print("Quota reached") + continue + f.seek(io.SEEK_SET) + d = f.read() + print(len(d)) + + +if __name__ == """__main__""": + main("gnu-sparse-big.tar") diff --git a/perf_enumerate.py b/perf_enumerate.py new file mode 100644 index 0000000..57e48f9 --- /dev/null +++ b/perf_enumerate.py @@ -0,0 +1,71 @@ +""" +MIT License + +Copyright (c) 2024 Roman Babenko + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +""" +import statistics +import sys +import time +from typing import List + +LEN = 100 +SIZE = 10000 + + +def perf_enum_list(args): + x = args[0] + for i in range(SIZE): + for n, i in x: + assert str(n) == i + + +def perf_plain_list(args): + x = args[0] + for i in range(SIZE): + for n, i in enumerate(x): + assert str(n) == i + + +def perf_test(func, data): + stat: List[float] = [] + for n in range(LEN): + start_time = time.time() + func(data) + stat.append(time.time() - start_time) + print(f"{func} Average = {statistics.mean(stat)} Deviation = {statistics.stdev(stat)}") + + +def main() -> int: + start_time = time.time() + l = [str(x) for x in range(10)] + n = enumerate(l) + perf_test(perf_enum_list, (n,)) + perf_test(perf_plain_list, (l,)) + print(f"Total time: {time.time() - start_time} SIZE={SIZE}") + return 0 + + +# Average = 0.00018164873123168945 Deviation = 1.3166524916387962e-05 +# Average = 0.008094820976257324 Deviation = 0.0003013285439674138 +# Total time: 0.8281574249267578 SIZE=10000 + +if __name__ == "__main__": + sys.exit(main())