Symmetric Pairs(连接、分组,聚合)

有一张表functions(x,y),有 记录(x1,y1),(x2,y2)如果x1=y2并且x2=y1认为存在对称点

找出表中的对称点,要求按x升序

思路:在作连接操作时,分组后,需要统计个数 ,

1、对于x与y相等时,个数要大于1

2、x与y不等时,个数等于1

sql为

select f1.x, f1.y from functions as f1 inner join functions as f2 on f1.x = f2.y and f1.y = f2.x where f1.x <= f1.y group by f1.x, f1.y having count(*) > 1 or (f1.x < f1.y and count(*) = 1) order by f1.x;

### 对称性在编程和密码学中的应用 #### 密码学中的对称加密 在密码学领域,对称加密是一种加密方法,其中用于加密数据的密钥与解密数据的密钥相同。这意味着相同的参数既适用于加密也适用于解密过程[^1]。这种特性使得对称加密成为一种高效且广泛使用的安全通信方式。 以下是实现简单对称加密的一个例子,使用 Python 的 `cryptography` 库: ```python from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes import os def derive_key(password: bytes, salt: bytes): kdf = PBKDF2HMAC( algorithm=hashes.SHA256(), length=32, salt=salt, iterations=100000, backend=default_backend() ) return kdf.derive(password) def encrypt_message(key: bytes, message: str): iv = os.urandom(16) cipher = Cipher(algorithms.AES(key), modes.CFB(iv)) encryptor = cipher.encryptor() encrypted_message = encryptor.update(message.encode()) + encryptor.finalize() return (iv, encrypted_message) def decrypt_message(key: bytes, iv: bytes, ciphertext: bytes): cipher = Cipher(algorithms.AES(key), modes.CFB(iv)) decryptor = cipher.decryptor() decrypted_message = decryptor.update(ciphertext) + decryptor.finalize() return decrypted_message.decode() password = b"super_secret_password" salt = os.urandom(16) key = derive_key(password, salt) message = "This is a secret message." iv, encrypted = encrypt_message(key, message) decrypted = decrypt_message(key, iv, encrypted) print(f"Original Message: {message}") print(f"Encrypted Message: {encrypted.hex()}") print(f"Decrypted Message: {decrypted}") ``` 这段代码展示了如何利用 AES 加密算法进行对称加密和解密操作。 #### 编程中的对称结构 除了密码学外,在编程中也可以发现许多基于对称性的概念。例如,《禅与计算机程序设计艺术》一书中提到,编写简洁而优雅的代码可以体现某种形式的对称美[^2]。这通常体现在函数的设计上——输入和输出之间的关系应保持一致性和可预测性。 另一个具体的实例是对排列组合问题的研究,比如生成所有的可能子集或排列时会涉及递归调用模式下的镜像效应。这些都反映了数学意义上的对称性质。 此外,“广义表”作为一种抽象的数据结构也能表现出层次间的平衡分布特征[^3],这也是另一种类型的对称表现形式之一。 #### 数学基础支持 最大公约数(GCD)计算也是展现数值间内在联系的一种手段,并且其迭代求解过程中往往蕴含着重复规律,间接体现了运算逻辑内部存在的潜在对称属性。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kgduu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值