diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 46c0ff9..bbfa45a 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -491,3 +491,7 @@ Name: [antoooks](https://github.com/antoooks)
Place: Indonesia / Singapore
Coding Experience: JS, TS, PHP, Java, Go. Specialize in CI/CD, Cloud Architecture, and Automation. Email: antokurnianto82@gmail.com
+ +Name: [okok](https://github.com/okok7711)
+Place: Germany
+Coding Experience: Python, JS, Cpp experience in one-liners
diff --git a/python/okok_sha256.py b/python/okok_sha256.py new file mode 100644 index 0000000..5061571 --- /dev/null +++ b/python/okok_sha256.py @@ -0,0 +1,2 @@ +#Usage: sha256(b"data") +sha256 = lambda data: (type("SHAConstructor", (object, ) , {'__init__': lambda self, data, **kwargs: [[setattr(self, key, value) for key, value in zip(["data", "hashes", "round_constants", "preprocessed_data"], [data, [0x6A09E667,0xBB67AE85,0x3C6EF372,0xA54FF53A,0x510E527F,0x9B05688C,0x1F83D9AB,0x5BE0CD19,], [0x428A2F98,0x71374491,0xB5C0FBCF,0xE9B5DBA5,0x3956C25B,0x59F111F1,0x923F82A4,0xAB1C5ED5,0xD807AA98,0x12835B01,0x243185BE,0x550C7DC3,0x72BE5D74,0x80DEB1FE,0x9BDC06A7,0xC19BF174,0xE49B69C1,0xEFBE4786,0x0FC19DC6,0x240CA1CC,0x2DE92C6F,0x4A7484AA,0x5CB0A9DC,0x76F988DA,0x983E5152,0xA831C66D,0xB00327C8,0xBF597FC7,0xC6E00BF3,0xD5A79147,0x06CA6351,0x14292967,0x27B70A85,0x2E1B2138,0x4D2C6DFC,0x53380D13,0x650A7354,0x766A0ABB,0x81C2C92E,0x92722C85,0xA2BFE8A1,0xA81A664B,0xC24B8B70,0xC76C51A3,0xD192E819,0xD6990624,0xF40E3585,0x106AA070,0x19A4C116,0x1E376C08,0x2748774C,0x34B0BCB5,0x391C0CB3,0x4ED8AA4A,0x5B9CCA4F,0x682E6FF3,0x748F82EE,0x78A5636F,0x84C87814,0x8CC70208,0x90BEFFFA,0xA4506CEB,0xBEF9A3F7,0xC67178F2,], self.preprocessing(data)])][0], self.finalhash()][0],'preprocessing': lambda self, data: data + b"\x80" + (b"\x00" * (63 - (len(data) + 8) % 64)) + __import__("struct").pack(">Q", (len(data) * 8)),'ror': lambda self, value, rotations: 0xFFFFFFFF & (value << (32 - rotations)) | (value >> rotations),'finalhash': lambda self: [func() for func in [lambda: setattr(self, "blocks", [self.preprocessed_data[x : x + 64] for x in range(0, len(self.preprocessed_data), 64)]),lambda: [[setattr(self, "words", list(__import__("struct").unpack(">16L", block))), setattr(self, "words", self.words + ([0] * 48)), [setattr(self, c, v) for c,v in zip(list("abcdefgh"), self.hashes)], [[(self.zero(index) if index > 15 else None), setattr(self, "S1", self.ror(self.e, 6) ^ self.ror(self.e, 11) ^ self.ror(self.e, 25)), setattr(self, "ch", (self.e & self.f) ^ ((~self.e & (0xFFFFFFFF)) & self.g)), setattr(self, "temp1", (self.h + self.S1 + self.ch + self.round_constants[index] + self.words[index]) % 0x100000000), setattr(self, "S0", self.ror(self.a, 2) ^ self.ror(self.a, 13) ^ self.ror(self.a, 22)), setattr(self, "maj", (self.a & self.b) ^ (self.a & self.c) ^ (self.b & self.c)), setattr(self, "temp2", (self.S0 + self.maj) % 0x100000000), [setattr(self, f, m) for f, m in zip(list("hgfedcba"), [self.g, self.f, self.e, ((self.d + self.temp1) % 0x100000000), self.c, self.b, self.a, ((self.temp1 + self.temp2) % 0x100000000),])]] for index in range(0,64)], self.final()] for block in self.blocks],lambda: setattr(self, "hash", "".join([hex(value)[2:].zfill(8) for value in self.hashes])),lambda: self.hash]][-1],'final': lambda self: [setattr(self, "mutated_hash_values", [self.a, self.b, self.c, self.d, self.e, self.f, self.g, self.h]), setattr(self, "hashes", [((element + self.mutated_hash_values[index]) % 0x100000000)for index, element in enumerate(self.hashes)])],'zero': lambda self, index: [setattr(self, "s0", (self.ror(self.words[index - 15], 7) ^ self.ror(self.words[index - 15], 18) ^ (self.words[index - 15] >> 3))), setattr(self, "s1", (self.ror(self.words[index - 2], 17)^ self.ror(self.words[index - 2], 19)^ (self.words[index - 2] >> 10))), self.words.__setitem__(index, (self.words[index - 16] + self.s0 + self.words[index - 7] + self.s1) % 0x100000000),], '__repr__': lambda self: self.hash, '__str__': lambda self: self.hash}))(data) \ No newline at end of file