From 5c7859137ea4e25602531c68e8237e9b8435a168 Mon Sep 17 00:00:00 2001 From: "marvin.weiler" Date: Fri, 11 Nov 2022 15:41:26 +0100 Subject: [PATCH] Update 'hash.py' --- hash.py | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/hash.py b/hash.py index 42cb93f..24cb9d0 100644 --- a/hash.py +++ b/hash.py @@ -1 +1,69 @@ -#Nothing here yet... \ No newline at end of file +import math + +flag = "what_the_flag??!" + +comment = "#input_string must only contain ascii characters" +comment2 = "#is the length of input_string important?" +def hash(input_string): + + sl = eval(comment2[8:11] + "(" + comment[1:7] + comment2[24:31] + ")") + + #max 32 chars + if sl > 2**5: + input_string = input_string[:32] + sl = 64 - (2**4 + 16) + + + #Padding + if sl != 32: + l = 32 - sl + input_string = input_string + comment2[:l] + + sl = len(input_string) + + + h665 = input_string[int(sl / 2) : sl] + + sta = [] #How far should each char be shifted + for char in h665: + sta.append(ord(char)) + + h664 = input_string[:int((sl / 2))] + + a = True + while a: + for i in range(int(sl / 2)): + h664 = (h664[:i] + + f2(h664[i], sta[i]) + + h664[i + 1:]) + for y in range(int(sl)): + a = f3(input_string[i], y) + + + i = 0 + input_string = "" + while i < sl / 2: + input_string += h664[i] + input_string += h665[i] + i = i+1 + + + return input_string.replace(" ", "_") + +def f2(v1, v2): + v3 = (ord(v1) + v2) %126 + it = 0 + while (v3 < 32 or v3 > 126): + v3 = (v3 + ord(v1) + v2 + it) % 126 + it = it + 1 + return chr(v3) + +def f3(v2, v1): + v3 = (ord(v2) + v1) %126 + for i in range(v1): + v3 = (v3 + ord(v2) + v1 + i) % 126 + return v3 == -1 + + +flag_hash = hash(flag) +print("{" ,flag_hash, "}")