OpenSSL 生成质数:openssl prime -generate -safe -bits BinBit,BinBit 为要求的二进制下位数。检验质数:openssl prime num。
安全的 Hash Function:
struct custom_hash
{
static uint64_t splitmix64(uint64_t x)
{
x += 0x9e3779b97f4a7c15ULL;
x = (x ^ (x >> 30ULL)) * 0xbf58476d1ce4e5b9ULL;
x = (x ^ (x >> 27ULL)) * 0x94d049bb133111ebULL;
return x ^ (x >> 31ULL);
}
size_t operator()(const uint64_t x) const
{
static const uint64_t FIXED_RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};让任意网页可以随意编辑:document.body.contentEditable = 'true';
若干随机数异或和为 的概率是 的。
显示文章 Markdown:console.log(JSON.parse(document.getElementById('lentille-context').innerText).data.article.content);
本地测试 IO 交互题(需要安装 Python,来自 https://znpdco.fun/2024/07/27/interactive/,许可证为 CC BY-SA 4.0):
import sys
import subprocess
from threading import Thread, Lock
stop = False
def judger(argv):
if len(argv) != 3:
print(f"Usage: {argv[0]} [command1] [command2]", file=sys.stderr)
return 1
command1 = argv[1]
command2 = argv[2]
def run_command(name, p1, p2):
global stop
while True:
lock = Lock()
lock.acquire()
line = p1.stdout.readline()
if not line or stop:
stop = True
lock.release()
break
print(name + ": " + line.decode(), end="")
p2.stdin.write(line)
p2.stdin.flush()
lock.release()
p1 = subprocess.Popen(command1, stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
p2 = subprocess.Popen(command2, stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
t1 = Thread(target=run_command, args=(command1, p1, p2))
t2 = Thread(target=run_command, args=(command2, p2, p1))
t1.start()
t2.start()
p1.wait()
p2.wait()
return 0
if __name__ == "__main__":
sys.exit(judger(sys.argv))