1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| import hashlib from os import urandom from flag import FLAG
def gen_pubkey(secret: bytes, hasher=hashlib.sha512) -> list: def hash(m): return hasher(m).digest() state = hash(secret) pubkey = [] for _ in range(len(hash(b'0')) * 4): pubkey.append(int.from_bytes(state, 'big')) state = hash(state) return pubkey
def happiness(x: int) -> int: return x - sum((x >> i) for i in range(1, x.bit_length()))
def encode_message(message: bytes, segment_len: int) -> list: message += bytes(segment_len - len(message) % (segment_len)) encoded = [] for i in range(0, len(message), segment_len): block = message[i:i + segment_len] encoded.append(int.from_bytes(block, 'big')) return encoded
def encrypt(pubkey: list, message: bytes) -> list: encrypted_blocks = [] for block_int in encode_message(message, len(pubkey) // 4): encrypted_blocks.append([happiness(i & block_int) for i in pubkey]) return encrypted_blocks
secret = urandom(16) A = gen_pubkey(secret, hashlib.sha256) enc = encrypt(A, FLAG) print(secret.hex()) print(enc) """ d83ff3295e051dbbe9d49a3a701ab028 [[67, 70, 70, 71, 75, 76, 66, 68, 74, 73, 65, 61, 74, 72, 64, 73, 66, 71, 68, 72, 63, 76, 78, 72, 72, 70, 66, 69, 76, 75, 63, 76, 71, 78, 70, 66, 70, 69, 85, 68, 72, 62, 77, 78, 65, 67, 73, 69, 65, 71, 73, 72, 59, 73, 64, 68, 76, 74, 69, 75, 76, 61, 68, 68, 68, 62, 73, 71, 69, 74, 68, 66, 64, 81, 72, 59, 61, 73, 72, 63, 68, 49, 71, 79, 78, 57, 66, 71, 72, 68, 66, 68, 65, 72, 82, 83, 70, 63, 70, 62, 76, 69, 58, 68, 70, 76, 67, 76, 66, 70, 75, 64, 64, 67, 69, 63, 71, 68, 70, 69, 66, 73, 77, 67, 70, 66, 75, 81], [71, 71, 62, 69, 71, 76, 66, 52, 69, 72, 67, 59, 73, 70, 65, 66, 65, 65, 70, 75, 64, 77, 72, 74, 66, 70, 66, 71, 72, 73, 58, 67, 70, 72, 67, 67, 77, 74, 80, 64, 72, 61, 69, 73, 75, 59, 69, 68, 65, 72, 72, 65, 56, 67, 64, 73, 73, 73, 63, 71, 68, 60, 60, 71, 63, 62, 66, 65, 69, 68, 68, 67, 69, 75, 72, 60, 61, 74, 60, 63, 70, 66, 68, 79, 72, 59, 68, 69, 57, 71, 71, 67, 67, 70, 71, 81, 69, 63, 69, 57, 74, 61, 67, 78, 64, 71, 63, 71, 65, 69, 72, 66, 57, 72, 71, 60, 72, 68, 77, 70, 64, 64, 70, 69, 64, 64, 76, 79], [28, 29, 24, 30, 34, 34, 30, 24, 29, 27, 23, 33, 29, 28, 29, 37, 32, 20, 31, 35, 29, 29, 30, 38, 26, 36, 30, 27, 32, 28, 21, 28, 29, 34, 24, 31, 33, 34, 36, 25, 32, 29, 31, 27, 30, 28, 33, 31, 30, 29, 33, 26, 29, 31, 29, 34, 31, 26, 30, 31, 33, 35, 32, 26, 29, 26, 28, 32, 32, 31, 26, 29, 30, 34, 33, 23, 28, 31, 26, 25, 32, 30, 29, 27, 31, 26, 28, 29, 32, 31, 33, 25, 28, 38, 31, 33, 27, 29, 29, 23, 33, 26, 30, 38, 38, 27, 32, 31, 24, 25, 35, 33, 29, 25, 32, 24, 29, 26, 29, 24, 27, 31, 28, 28, 28, 24, 28, 36]]
184add015c820d022133c0094fafadc4 [[79, 64, 71, 67, 75, 72, 79, 72, 78, 64, 65, 67, 73, 68, 63, 59, 67, 64, 69, 64, 67, 70, 69, 64, 64, 67, 67, 71, 62, 70, 67, 66, 62, 72, 65, 68, 59, 62, 73, 67, 63, 68, 74, 71, 62, 69, 62, 64, 73, 70, 73, 71, 74, 71, 65, 74, 67, 54, 78, 72, 68, 75, 70, 71, 75, 64, 76, 71, 72, 75, 86, 73, 73, 77, 71, 68, 69, 63, 77, 62, 69, 64, 62, 73, 71, 76, 61, 74, 69, 74, 74, 62, 69, 64, 70, 64, 77, 78, 71, 79, 67, 73, 63, 72, 80, 66, 67, 76, 65, 72, 74, 55, 71, 75, 71, 73, 61, 62, 79, 65, 76, 72, 76, 68, 81, 86, 65, 71], [80, 59, 70, 72, 76, 64, 77, 75, 67, 66, 59, 71, 70, 69, 62, 71, 65, 65, 70, 72, 62, 66, 70, 69, 69, 63, 66, 66, 61, 61, 69, 68, 67, 66, 66, 62, 61, 61, 74, 73, 66, 65, 63, 75, 63, 64, 62, 64, 73, 68, 67, 73, 76, 69, 58, 73, 58, 57, 66, 66, 74, 78, 70, 71, 69, 60, 75, 61, 70, 72, 83, 72, 61, 80, 69, 68, 62, 71, 72, 64, 61, 72, 53, 67, 66, 75, 63, 65, 67, 62, 74, 68, 72, 70, 70, 59, 80, 76, 72, 75, 78, 72, 71, 65, 75, 63, 66, 81, 71, 70, 72, 58, 69, 77, 74, 64, 64, 67, 82, 61, 72, 73, 73, 62, 75, 81, 72, 67], [28, 27, 32, 31, 30, 32, 31, 24, 32, 32, 30, 23, 28, 30, 21, 30, 29, 28, 32, 31, 23, 33, 29, 28, 30, 31, 30, 29, 28, 23, 31, 30, 32, 28, 33, 31, 30, 25, 30, 30, 31, 29, 27, 35, 29, 28, 30, 32, 29, 35, 38, 29, 32, 34, 31, 37, 29, 31, 31, 29, 29, 32, 32, 33, 30, 29, 34, 26, 27, 29, 35, 27, 30, 34, 33, 26, 24, 36, 30, 31, 25, 30, 28, 31, 34, 30, 29, 30, 23, 30, 29, 32, 33, 27, 24, 29, 34, 33, 29, 32, 36, 32, 28, 33, 35, 28, 29, 34, 30, 33, 34, 27, 35, 32, 34, 34, 23, 31, 38, 25, 30, 32, 34, 31, 34, 38, 31, 30]] """
|