Created
October 24, 2021 19:53
-
-
Save dialluvioso/0ae643ff3bfca583ec3ab0479ee0034e to your computer and use it in GitHub Desktop.
Solution for the last flareon2021 challenge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| # -*- coding: utf-8 -*- | |
| import sys | |
| table = [90, 132, 6, 69, 174, 203, 232, 243, 87, 254, 166, 61, 94, 65, 8, 208, 51, 34, 33, 129, 32, 221, 0, 160, 35, 175, 113, 4, 139, 245, 24, 29, 225, 15, 101, 9, 206, 66, 120, 62, 195, 55, 202, 143, 100, 50, 224, 172, 222, 145, 124, 42, 192, 7, 244, 149, 159, 64, 83, 229, 103, 182, 122, 82, 78, 63, 131, 75, 201, 130, 114, 46, 118, 28, 241, 30, 204, 183, 215, 199, 138, 16, 121, 26, 77, 25, 53, 22, 125, 67, 43, 205, 134, 171, 68, 146, 212, 14, 152, 20, 185, 155, 167, 36, 27, 60, 226, 58, 211, 240, 253, 79, 119, 209, 163, 12, 72, 128, 106, 218, 189, 216, 71, 91, 250, 150, 11, 236, 207, 73, 217, 17, 127, 177, 39, 231, 197, 178, 99, 230, 40, 54, 179, 93, 251, 220, 168, 112, 37, 246, 176, 156, 165, 95, 184, 57, 228, 133, 169, 252, 19, 2, 81, 48, 242, 105, 255, 116, 191, 89, 181, 70, 23, 194, 88, 97, 153, 235, 164, 158, 137, 238, 108, 239, 162, 144, 115, 140, 84, 188, 109, 219, 44, 214, 227, 161, 141, 80, 247, 52, 213, 249, 1, 123, 142, 190, 104, 107, 85, 157, 45, 237, 47, 147, 21, 31, 196, 136, 170, 248, 13, 92, 234, 86, 3, 193, 154, 56, 5, 111, 98, 74, 18, 223, 96, 148, 41, 117, 126, 173, 233, 10, 49, 180, 187, 186, 135, 59, 38, 210, 110, 102, 200, 76, 151, 198] | |
| key = [97, 49, 49, 95, 109, 89, 95, 104, 111, 109, 49, 101, 115, 95, 104, 52, 116, 51, 95, 98, 52, 114, 100, 115] | |
| def encrypt(plaintext): | |
| ciphertext = [0] * len(plaintext) | |
| for i in range(len(plaintext)): | |
| k = key[i % len(key)] | |
| if (i&1): | |
| k = (k ^ -1) & 255 | |
| r = table[k ^ table[plaintext[i]]] | |
| if (r&128): | |
| r ^= 66 | |
| ciphertext[i] = (r ^ -1) & 255 | |
| return ciphertext | |
| def decrypt(ciphertext): | |
| plaintext = [0] * len(ciphertext) | |
| for i in range(len(ciphertext)): | |
| c = (ciphertext[i] ^ -1) & 255 | |
| if (c&128): | |
| c ^= 66 | |
| k = key[i % len(key)] | |
| if (i&1): | |
| k = (k ^ -1) & 255 | |
| plaintext[i] = table.index(table.index(c) ^ k) | |
| return plaintext | |
| pt = decrypt(open("ciphertext.raw", "rb").read()) | |
| open("flag.png", "wb").write(bytearray(pt)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment