var ( ans [N]int// 暂存一个排列 mark [N]bool// 标记用过的数 n int results []string// )
funcdfs(u int) { // 到达末尾,保存一个排列 if u == n { var b strings.Builder for i := 0; i < n; i++ { fmt.Fprintf(&b, "%d ", ans[i]) #将数组写入字符串b } results = append(results, b.String()) return }
for i := 1; i <= n; i++ { if !mark[i] { mark[i] = true ans[u] = i dfs(u + 1) // 复原 mark[i] = false ans[u] = 0 } } }
funcmain() { fmt.Scan(&n) dfs(0) #(初始化长度为0)
// 统一输出 for _, line := range results { fmt.Println(line) } }
from Crypto.Util.number import * from Crypto.Cipher import AES from Crypto.Util.Padding import pad from hashlib import md5 from secret import flag import random
assert flag.startswith(b"flag{")
class LCG: def __init__(self, seed, a, b, m): self.seed = seed self.a = a self.b = b self.m = m
p = 2**512 a = getPrime(512) b = getPrime(512) seed = getRandomRange(1, p) cipher = AES.new(key=md5(long_to_bytes(seed)).digest(), mode=AES.MODE_CTR) L = LCG(seed, a, b, p)
def replace_with_question_marks(input_str, probability): if not input_str: return input_str length = len(input_str) indices = set() while len(indices) < int(length * probability): indices.add(random.randint(0, length - 1))
output_str = list(input_str) for index in indices: output_str[index] = "?"
import itertools import random from Crypto.Cipher import AES from Crypto.Util.number import * from hashlib import md5 from sympy import sqrt_mod a = "1100001101001?101111100?01110001010011?1???11???01000011100101010100101??011?01?00?0?000110000?01?01010?10101?1101010100010011?101010010000?10110??10100?000?1?11?10???0?1111?1000100100?1110111010?0?01?00?11?0011?0101101?100000?1??0101010?1?101?1001?0011110??0000000?00100?1010011100001111111001?10?001??0110001111?100110000110011011?111101?1??1010101101?01?0000011?1111001?000111??1??00010?10011001?000110000??10?10100000100?10?1101111?101?001??00?01111???01??1?10100??0101?011?1000?011101?110???0110111011?101?1" b = "1000?11?0111000?1001??11?1100?001?0?0111011011100?0?110?11111?1?0?111100?0111???01?001100?000?001??0110??0?001000000110?0100?01100?001000011?01001000011010100?01110000001??0000111???101101?0100?011??010011?0?100?0?111100?00110000111?10???0?01?100?1100?0111001?11?1110?011?100101101?10?0??00010011?101?111?110001100?0??0?10?11100100111?100100001?0?00000??1101001?010?110000110?0001101000010011001100?010?100000100001?10100101110010000?0111?0001??1?001100000010000?011000??0?10?1001000100???1100111?11?11011010100?" c1 = "1100101001100???1??101100?00101111?000001011?0??0?0?1??11?0001?1?01111?0?1100011101?01011??110011100001100100???000101?1011010100111110?11?010111101?0?0110?0100001?000?1011?111111111000001?100000001011?0110111?11010010100?10011110000?0101??1?00001111010110?00110001111011001?0010110101100011111?01?0000?0?0011?0?101??1111100?11?11100010???1?0?1?11?1100?1100010?1111111011?100100111?11?11?1101?1?1100111?01?01111?11?0??1111?001000?0000?1?010?100111101?01011?1?1?111?01???01?1111?01?????0?001011000111010010?111101" c2 = "00000000011?1000110011?001???10011010?0?01?11010011010??10010111?1111?1000?1??11?1111??111?1010001001111?10?0111001??101?10000000101111110111??11111?0?0??10?0101?111001101000101?00010?111?1100111?0?1110?1111?0110?11010110001100000111101?010010??0??101?1001000?010101?01110?01001010001?0?01?00?0110100100??10?00??1010111010010??1?100110?????01001?001110101111?1?00?0?00101?101?0?101?110011?1?00111100??1?1?00?1110?010?110?00?010011010001101?00110101?1??0010?101111000?11011101011?0010010110000000110110101??1?011?" enc = b'\xcb\xe0wY\xe3\\\xf7\xc8\x89/\x1c\xdb^P\xc09\xca\xcf\xe7\xa7\xa4\xb5\xaeQ\xc8K\xabg_\x8e\xfa?\xdc\xce9\xd7\x0en"?\xc0\n\xe0hT+\xc0\x81' nonce = b'n\x13\xd1\xdf\xb6]\xb5\xf7' import itertools
p = 2 ** 512 A = [a, b, c1, c2] b = b[:-1] + '1' LL=[]
def dfs(bbbb): i = len(bbbb[0]) + 1 if len(bbbb[0]) == 512: LL.append(bbbb) else: tmp=[] for c in A: if (c[-i]=='?'): tmp.append(['0','1']) else: tmp.append([None]) for G in itertools.product(*tmp): L = [] for j,k in enumerate(G): if k is None: L.append(A[j][-i]+bbbb[j]) else: L.append(k+bbbb[j]) func=lambda x: int(x, 2) a, b, c1, c2 = map(func, L) if (a * c1**2 + b) % 2**i == c2: dfs(L)
dfs(["", "", "", ""]) for a,b,c1,c2 in LL: a = int(a, 2) b = int(b, 2) c1 = int(c1, 2) c2 = int(c2, 2) ss = (c1 - b) * pow(a, -1, 2 ** 512) % 2 ** 512 s=sqrt_mod(ss,2**512,all_roots=True) for seed in s: cipher = AES.new(key=md5(long_to_bytes(seed)).digest(), mode=AES.MODE_CTR, nonce=nonce) res = cipher.decrypt(enc) if b"flag" in res: print(res)