📚 IB Edexcel Computer Science: Encryption Key Points & Revision | IB Edexcel 计算机:加密 考点精讲
Encryption is the process of converting plaintext into ciphertext to ensure that only authorised parties can access the original data. It is a cornerstone of modern cybersecurity, protecting everything from online banking to personal messages. Understanding encryption is essential for IB and Edexcel Computer Science, as it links concepts of algorithms, data security, and network protocols.
加密是将明文转换成密文的过程,确保只有授权方才能访问原始数据。它是现代网络安全的基石,保护着从网上银行到个人消息的一切。理解加密对 IB 和 Edexcel 计算机科学至关重要,因为它连接了算法、数据安全和网络协议等概念。
1. Introduction to Encryption | 加密概述
Encryption ensures confidentiality by scrambling data so that it appears random to anyone without the decryption key. Modern encryption relies on mathematical algorithms and keys. The strength of an encryption system depends on the algorithm’s design and the key length, not on keeping the algorithm secret.
加密通过加扰数据来确保机密性,使没有解密密钥的人看到的数据像是随机的。现代加密依赖数学算法和密钥。加密系统的强度取决于算法的设计和密钥长度,而不是对算法本身保密。
There are two main types of encryption: symmetric and asymmetric. Symmetric encryption uses the same key for both encryption and decryption, while asymmetric encryption uses a public key for encryption and a private key for decryption.
加密有两种主要类型:对称加密和非对称加密。对称加密使用同一密钥进行加密和解密,而非对称加密使用公钥进行加密、私钥进行解密。
2. Symmetric Encryption | 对称加密
In symmetric encryption, a single shared key is used to encrypt and decrypt messages. Both the sender and receiver must possess the same secret key, which creates a key distribution problem—how to share the key securely without it being intercepted.
在对称加密中,使用一个共享密钥来加密和解密消息。发送方和接收方必须拥有相同的秘密密钥,这就产生了密钥分发问题——如何在不被截获的情况下安全地共享密钥。
Symmetric encryption is fast and suitable for encrypting large amounts of data. Common symmetric algorithms include AES (Advanced Encryption Standard) and the deprecated DES (Data Encryption Standard). AES operates on fixed-size blocks of 128 bits and uses key sizes of 128, 192, or 256 bits.
对称加密速度快,适合加密大量数据。常见的对称算法包括 AES(高级加密标准)和已弃用的 DES(数据加密标准)。AES 对 128 位的固定大小块进行操作,使用 128、192 或 256 位的密钥。
Symmetric ciphers can be block ciphers (processing data in fixed blocks) or stream ciphers (processing data bit by bit). Block ciphers often use modes of operation like CBC (Cipher Block Chaining) to improve security.
对称密码可以是分组密码(按固定块处理数据)或流密码(逐位处理数据)。分组密码通常使用像 CBC(密码块链接)这样的操作模式来提高安全性。
3. Asymmetric Encryption | 非对称加密
Asymmetric encryption, also known as public-key cryptography, uses a pair of mathematically related keys: a public key and a private key. The public key can be distributed openly, while the private key must be kept secret.
非对称加密,也称为公钥密码学,使用一对数学上相关的密钥:公钥和私钥。公钥可以公开发布,而私钥必须保密。
If someone wants to send a confidential message, they encrypt it with the recipient’s public key. Only the corresponding private key can decrypt it. This solves the key distribution problem inherent in symmetric encryption, but asymmetric encryption is computationally slower.
如果有人想发送机密消息,他们会用接收方的公钥加密。只有对应的私钥才能解密。这解决了对称加密中固有的密钥分发问题,但非对称加密的计算速度较慢。
Asymmetric encryption also enables digital signatures. The sender encrypts a hash of the message with their private key, and the recipient verifies it using the sender’s public key.
非对称加密还能实现数字签名。发送方用其私钥加密消息的哈希值,接收方用发送方的公钥进行验证。
4. Caesar Cipher and Simple Techniques | 凯撒密码与简单技术
The Caesar cipher is a basic substitution cipher where each letter in the plaintext is shifted by a fixed number of positions in the alphabet. For example, with a shift of 3, ‘A’ becomes ‘D’, ‘B’ becomes ‘E’, etc. The key is the shift value.
凯撒密码是一种基本的替换密码,明文中的每个字母按字母表移动固定数目的位置。例如,移位 3,’A’ 变成 ‘D’,’B’ 变成 ‘E’,等等。密钥就是移位数。
It is extremely weak against brute force attacks because there are only 25 possible shifts (in the English alphabet). It can also be easily broken using frequency analysis, since the underlying letter frequencies remain unchanged.
它对暴力破解极为脆弱,因为只有 25 种可能的移位(英语字母表内)。它也很容易通过频率分析破解,因为底层字母频率保持不变。
5. Vigenère Cipher | 维吉尼亚密码
The Vigenère cipher improves on the Caesar cipher by using a keyword to apply multiple shift values. Each letter of the keyword determines the shift for the corresponding plaintext letter. The encryption formula for the i-th character is: Cᵢ = (Pᵢ + Kᵢ) mod 26, where Pᵢ and Kᵢ are the numeric equivalents of the plaintext and key letters.
维吉尼亚密码通过使用一个关键词来应用多个移位值,改进了凯撒密码。关键词的每个字母决定对应明文字母的移位数。第 i 个字符的加密公式为:Cᵢ = (Pᵢ + Kᵢ) mod 26,其中 Pᵢ 和 Kᵢ 是明文和密钥字母的数字等价。
Although stronger than Caesar cipher, it is still vulnerable to frequency analysis if the key is short relative to the message. The Kasiski examination can reveal the key length.
虽然比凯撒密码强,但如果密钥相对消息较短,它仍然容易受到频率分析攻击。卡西斯基测试可以揭示密钥长度。
6. Modern Symmetric Algorithms: AES | 现代对称算法:AES
AES is the most widely used symmetric encryption standard. It processes data in 128-bit blocks and supports key lengths of 128, 192, or 256 bits. The algorithm consists of multiple rounds (10, 12, or 14 depending on key size) that apply a series of transformations: SubBytes, ShiftRows, MixColumns, and AddRoundKey.
AES 是使用最广泛的对称加密标准。它处理 128 位的数据块,支持 128、192 或 256 位密钥长度。算法由多轮组成(根据密钥大小,为 10、12 或 14 轮),应用一系列变换:SubBytes、ShiftRows、MixColumns 和 AddRoundKey。
SubBytes substitutes each byte using an S-box, ShiftRows shifts rows of the state array, MixColumns mixes the columns, and AddRoundKey XORs the state with a round key. The design ensures confusion and diffusion, making AES highly resistant to cryptanalysis.
SubBytes 使用 S 盒替换每个字节,ShiftRows 移位状态数组的行,MixColumns 混合列,AddRoundKey 将状态与轮密钥异或。这种设计确保了混淆和扩散,使 AES 对密码分析具有高度抵抗力。
7. RSA Algorithm | RSA 算法
RSA is an asymmetric algorithm based on the difficulty of factoring large numbers. Key generation: choose two large distinct primes p and q. Compute n = p × q and φ(n) = (p-1)(q-1). Select a public exponent e such that 1 < e < φ(n) and gcd(e, φ(n)) = 1. Determine the private exponent d as the modular multiplicative inverse: e × d ≡ 1 mod φ(n).
RSA 是一种基于大数分解困难性的非对称算法。密钥生成:选择两个不同的大素数 p 和 q。计算 n = p × q 和 φ(n) = (p-1)(q-1)。选择公开指数 e,满足 1 < e < φ(n) 且 gcd(e, φ(n)) = 1。确定私有指数 d 作为模反元素:e × d ≡ 1 mod φ(n)。
The public key is (e, n) and the private key is (d, n). Encryption is performed as: C = Mᵉ mod n. Decryption: M = Cᵈ mod n. The security relies on the fact that deriving d from e and n requires factoring n, which is infeasible for sufficiently large n.
公钥是 (e, n),私钥是 (d, n)。加密执行:C = Mᵉ mod n。解密:M = Cᵈ mod n。安全性依赖于从 e 和 n 推导 d 需要对 n 进行因数分解,对于足够大的 n 这是不可行的。
C = Mᵉ mod n M = Cᵈ mod n
8. Hashing and Digital Signatures | 哈希与数字签名
A hash function takes an arbitrary-length input and produces a fixed-size hash value (digest). It must be one-way (pre-image resistant) and collision resistant. Common hash functions include SHA-256 and MD5 (now broken). Hashing ensures data integrity, as any change in input produces a completely different hash.
哈希函数接受任意长度的输入,产生固定大小的哈希值(摘要)。它必须是单向的(抗原像攻击)和抗碰撞的。常见的哈希函数包括 SHA-256 和 MD5(现已破解)。哈希保证数据完整性,因为输入的任何变化都会产生完全不同的哈希。
Digital signatures combine hashing and asymmetric encryption. A sender creates a hash of the message, then encrypts it with their private key. The encrypted hash is the digital signature. The receiver decrypts the signature with the sender’s public key and compares it to a freshly computed hash of the message.
数字签名结合了哈希和非对称加密。发送方创建消息的哈希,然后用其私钥加密。加密的哈希就是数字签名。接收方用发送方的公钥解密签名,并将其与消息新计算的哈希值进行比较。
Formally:
Signature S = H(M)ᵈ mod n Verify: H(M) == Sᵉ mod n
If they match, the message is authentic and unaltered. This provides authentication, non-repudiation, and integrity.
如果它们匹配,则消息是真实的且未被篡改。这提供了认证、不可否认性和完整性。
9. Public Key Infrastructure (PKI) and Certificates | 公钥基础设施和证书
Public Key Infrastructure (PKI) is a framework used to manage digital certificates and public-key encryption. A digital certificate binds a public key to an entity (person or server) and is issued by a trusted Certificate Authority (CA). The CA verifies the identity and signs the certificate with its own private key.
公钥基础设施(PKI)是一个用于管理数字证书和公钥加密的框架。数字证书将公钥绑定到一个实体(人或服务器),并由受信任的证书颁发机构(CA)签发。CA 验证身份,并用其自己的私钥签署证书。
Trust is hierarchical: root CA certificates are self-signed and trusted by operating systems and browsers. Intermediate CAs are signed by the root, and end-entity certificates are signed by intermediates. This chain of trust enables secure web browsing (HTTPS).
信任是分层的:根 CA 证书是自签名的,并被操作系统和浏览器信任。中间 CA 由根 CA 签名,最终实体证书由中间 CA 签名。这种信任链实现了安全的网页浏览(HTTPS)。
10. SSL/TLS and HTTPS | SSL/TLS 和 HTTPS
SSL (Secure Sockets Layer) and its successor TLS (Transport Layer Security) are protocols that provide encryption, authentication, and integrity for data transmitted over a network. HTTPS is HTTP over TLS. During the TLS handshake, the client and server negotiate and establish a secure connection.
SSL(安全套接层)及其后继者 TLS(传输层安全)是为网络传输数据提供加密、认证和完整性的协议。HTTPS 是基于 TLS 的 HTTP。在 TLS 握手期间,客户端和服务器协商并建立安全连接。
Typical handshake: Client sends ‘ClientHello’ with supported cipher suites. Server responds with ‘ServerHello’, its digital certificate, and possibly a request for a client certificate. Client verifies the certificate, generates a pre-master secret, encrypts it with the server’s public key, and sends it. Both sides derive session keys for symmetric encryption.
典型握手过程:客户端发送带有支持的密码套件的 ‘ClientHello’。服务器以 ‘ServerHello’、其数字证书以及可能对客户端证书的请求进行响应。客户端验证证书,生成预主密钥,用服务器的公钥加密并发送。双方生成用于对称加密的会话密钥。
Ephemeral Diffie-Hellman key exchange is often used for perfect forward secrecy. The client and server agree on parameters g and p, choose private numbers a and b, compute public values A = gᵃ mod p and B = gᵇ mod p, exchange them, and compute the shared secret gᵃᵇ mod p.
为了完美前向保密,通常使用临时 Diffie-Hellman 密钥交换。客户端和服务器商定参数 g 和 p,选择私有数字 a 和 b,计算公开值 A = gᵃ mod p 和 B = gᵇ mod p,交换后计算共享秘密 gᵃᵇ mod p。
11. Cryptanalysis and Security Risks | 密码分析与安全风险
Cryptanalysis is the study of breaking encryption. Common attacks include brute force (trying all possible keys), frequency analysis (exploiting patterns in ciphertext), known-plaintext attacks (having samples of plaintext and ciphertext pairs), and side-channel attacks (exploiting physical implementation leaks).
密码分析是研究破解加密的学科。常见的攻击包括暴力破解(尝试所有可能的密钥)、频率分析(利用密文中的模式)、已知明文攻击(拥有明文和密文样本对)以及旁路攻击(利用物理实现中的泄漏)。
Man-in-the-middle attacks can intercept public key exchange if not properly authenticated, which is why certificates and PKI are essential. Weak random number generation, short key lengths, and deprecated algorithms (e.g., DES, RC4, MD5) pose significant risks.
如果未正确认证,中间人攻击可以截获公钥交换,这就是证书和 PKI 至关重要的原因。弱随机数生成、短密钥长度和已弃用的算法(如 DES、RC4、MD5)会带来重大风险。
With the advent of quantum computing, algorithms like Shor’s algorithm can factor large integers efficiently, threatening RSA. Post-quantum cryptography is being developed to mitigate this.
随着量子计算的出现,像 Shor 算法这样的算法可以有效分解大整数,威胁到 RSA。后量子密码学正在开发中,以缓解这一问题。
12. Exam Tips for Encryption | 加密考试技巧
When answering exam questions on encryption, always define key terms: plaintext, ciphertext, key, symmetric, asymmetric. Clearly distinguish between symmetric and asymmetric encryption and know their use cases. Be able to describe the steps of the TLS handshake and the role of certificates.
在回答加密相关考试问题时,始终定义关键术语:明文、密文、密钥、对称、非对称。清楚区分对称和非对称加密,并了解它们的用途。能够描述 TLS 握手的步骤以及证书的作用。
Practice numerical examples of RSA with small primes to understand key generation, encryption, and decryption. Remember that digital signatures use the sender’s private key to encrypt the hash, providing non-repudiation, while encryption uses the recipient’s public key for confidentiality.
用小素数练习 RSA 的数值例子,以理解密钥生成、加密和解密。记住数字签名使用发送方的私钥加密哈希,提供不可否认性,而加密则使用接收方的公钥实现机密性。
Use accurate terminology: ‘symmetric’ not ‘same key encryption’, ‘certificate authority’ not ‘certificate company’. In extended response questions, structure your answer by first explaining the problem, then the encryption solution, and finally the security properties achieved.
使用准确的术语:说“对称加密”而非“相同密钥加密”,说“证书颁发机构”而非“证书公司”。在扩展回答题中,先解释问题,再说明加密解决方案,最后说明实现的安全属性,以此构建答案。
Expect questions asking you to compare algorithms or to suggest appropriate encryption methods for a given scenario, such as protecting data at rest vs. data in transit.
预期题目会要求比较算法,或针对给定情境(如保护静态数据与传输中的数据)建议合适的加密方法。
Published by TutorHao | Computer Science Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)
屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导