Encryption in Computer Science | 计算机科学中的加密

📚 Encryption in Computer Science | 计算机科学中的加密

Encryption is the process of transforming readable plaintext into unintelligible ciphertext using an algorithm and a key, ensuring that only authorised parties can access the original information. In modern computer science and cybersecurity, encryption is fundamental for protecting data confidentiality, integrity, and authentication across networks and storage. IB and WJEC specifications cover both classical ciphers (such as Caesar and Vigenère) and modern symmetric and asymmetric schemes, along with hash functions, digital signatures, and the practical deployment of encryption in protocols like SSL/TLS.

加密是使用算法和密钥将可读的明文转换成无法理解的密文的过程,确保只有授权方才能访问原始信息。在现代计算机科学与网络安全中,加密是保护数据机密性、完整性和认证的基础,贯穿网络传输与存储过程。IB 与 WJEC 考试大纲涵盖了古典密码(如凯撒密码和维吉尼亚密码)以及现代对称与非对称加密方案,同时还包括哈希函数、数字签名,以及 SSL/TLS 等协议中加密的实际应用。

1. Core Concepts of Encryption | 加密的核心概念

The core components of any encryption system are the plaintext (original readable message), the ciphertext (scrambled output), the encryption algorithm (mathematical procedure), and the key (secret value that controls the transformation). In symmetric encryption the same key is used for both encryption and decryption, while in asymmetric encryption a pair of mathematically linked keys — public and private — is used. A fundamental principle in modern cryptography is Kerckhoffs’s principle: a cryptosystem should remain secure even if everything about the system except the key is publicly known.

任何加密系统的核心组成部分是明文(原始可读消息)、密文(混淆后的输出)、加密算法(数学过程)以及密钥(控制转换的秘密值)。在对称加密中,加密和解密使用同一个密钥;而在非对称加密中,则使用一对数学上关联的密钥——公钥和私钥。现代密码学的一个基本原则是柯克霍夫原则:即使除了密钥之外系统的所有细节都是公开的,密码系统仍应保持安全。

The strength of encryption is typically measured by the size of the key space — the total number of possible keys. For example, a 128-bit key provides 2¹²⁸ possible combinations, making brute-force attacks infeasible with current computing power. Encryption can be applied to data at rest (stored files) and data in transit (network communications).

加密的强度通常用密钥空间的大小来衡量——即可能密钥的总数。例如,128 位密钥提供了 2¹²⁸ 种可能的组合,使得用当前计算能力进行暴力破解变得不可行。加密可以应用于静态数据(存储的文件)和传输中的数据(网络通信)。


2. Symmetric vs Asymmetric Encryption | 对称加密与非对称加密

Symmetric encryption uses a single shared secret key for both encryption and decryption. It is fast and efficient, making it suitable for encrypting large volumes of data. The main challenge is secure key distribution — the key must be shared between sender and receiver over a secure channel before communication begins. Common symmetric algorithms include AES and the older DES.

对称加密使用单一的共享密钥进行加密和解密。它速度快、效率高,适合加密大量数据。其主要挑战在于安全的密钥分发——在通信开始前,必须通过安全通道在发送方和接收方之间共享密钥。常见的对称算法包括 AES 和较旧的 DES。

Asymmetric encryption, also called public-key cryptography, uses a key pair: a public key that can be freely distributed, and a private key kept secret. Data encrypted with the public key can only be decrypted with the corresponding private key, and vice versa for digital signatures. This solves the key distribution problem but is computationally slower. RSA and Elliptic Curve Cryptography (ECC) are prominent asymmetric algorithms.

非对称加密,也称为公钥密码学,使用一对密钥:一个可以自由分发的公钥和一个保密的私钥。用公钥加密的数据只能用对应的私钥解密,而数字签名则反之。这解决了密钥分发问题,但计算速度较慢。RSA 和椭圆曲线密码学 (ECC) 是主要的非对称算法。

Feature Symmetric Asymmetric
Keys Single shared key Public + private key pair
Speed Fast Slower
Key distribution Difficult, needs secure channel Easy, public key can be open
Use cases Bulk data encryption Key exchange, digital signatures

3. Caesar Cipher | 凯撒密码

The Caesar cipher is a classic substitution cipher where each letter in the plaintext is shifted by a fixed number of positions down the alphabet. For a shift of 3, A becomes D, B becomes E, and Z wraps around to C. Mathematically, for a letter with position x (A=0, B=1, …), the encryption function is E(x) = (x + k) mod 26, and decryption is D(x) = (x − k) mod 26, where k is the key (shift value).

凯撒密码是一种经典的替换密码,明文中每个字母都在字母表中向后移动固定数量的位置。对于移位 3,A 变成 D,B 变成 E,Z 则绕回 C。数学上,对于位置为 x 的字母(A=0, B=1, …),加密函数为 E(x) = (x + k) mod 26,解密函数为 D(x) = (x − k) mod 26,其中 k 是密钥(移位值)。

Despite its historical significance, the Caesar cipher is extremely weak by today’s standards. With only 25 possible keys (k = 1 to 25), it is vulnerable to brute-force attacks and frequency analysis, which exploits the fact that letters in a language appear with predictable frequencies (e.g., ‘E’ is the most common letter in English).

尽管凯撒密码具有历史意义,但以今天的标准来看它极其脆弱。由于只有 25 个可能的密钥(k = 1 到 25),它容易受到暴力破解攻击和频率分析的攻击——后者利用的是一种语言中字母出现的频率是可预测的这一事实(例如,’E’ 是英语中最常见的字母)。


4. Vigenère Cipher | 维吉尼亚密码

The Vigenère cipher improves upon the Caesar cipher by using a keyword to apply multiple different shifts throughout the message. Each letter of the keyword determines the shift for the corresponding plaintext letter, repeating the keyword as needed. If the keyword is ‘KEY’ and plaintext is ‘HELLO’, then H is shifted by K (10), E by E (4), L by Y (24), and so on. The Vigenère square (tabula recta) facilitates manual encryption and decryption.

维吉尼亚密码通过使用一个关键词在整条消息中应用多个不同的移位,从而改进了凯撒密码。关键词的每个字母决定了对应明文字母的移位量,并按需重复关键词。如果关键词是 ‘KEY’,明文是 ‘HELLO’,那么 H 按 K (10) 移位,E 按 E (4) 移位,L 按 Y (24) 移位,以此类推。维吉尼亚方阵(tabula recta)有助于手工加密和解密。

For centuries the Vigenère cipher was considered unbreakable (‘le chiffre indéchiffrable’), but it is susceptible to the Kasiski examination and frequency analysis once the key length is determined. Its main weakness is the repeating key pattern that reveals the key length when identical plaintext segments are encrypted with the same part of the keyword.

几个世纪以来,维吉尼亚密码曾被认为是无法破解的(’le chiffre indéchiffrable’),但它容易受到卡西斯基测试和频率分析的攻击,一旦确定了密钥长度,就能被破解。其主要弱点是重复的密钥模式——当相同的明文段用关键词的同一部分加密时,会暴露出密钥长度。


5. One-Time Pad | 一次性密码本

The one-time pad (OTP) is a theoretically perfect encryption method if implemented correctly. It uses a truly random key that is as long as the plaintext, each key character being used only once to encrypt a single plaintext character by modular addition (e.g., XOR for binary data). The ciphertext reveals no information about the plaintext without the key, achieving perfect secrecy as proved by Claude Shannon.

一次性密码本 (OTP) 如果正确实施,是一种理论上完美的加密方法。它使用一个与明文一样长的真正随机的密钥,每个密钥字符仅使用一次,通过模加(例如,对于二进制数据使用异或操作)加密单个明文字符。没有密钥,密文不会泄露任何关于明文的信息,正如克劳德·香农所证明的那样,实现了完美保密。

In practice, OTP faces severe limitations: the key must be truly random, securely distributed to both parties, never reused, and as long as the message itself. Key distribution and management make it impractical for most applications; nevertheless, it remains an important theoretical benchmark and is used in some high-security environments like diplomatic communications.

在实践中,OTP 面临严重的限制:密钥必须是真正随机的,需要安全地分发给双方,绝不能重复使用,并且必须与消息本身一样长。密钥分发和管理使其在大多数应用中不切实际;尽管如此,它仍然是一个重要的理论基准,并在外交通信等某些高安全性环境中得到使用。


6. Modern Symmetric Encryption: DES and AES | 现代对称加密:DES 与 AES

The Data Encryption Standard (DES) was a widely adopted symmetric algorithm with a 56-bit key and a 64-bit block size, using a Feistel network structure with 16 rounds of substitution and permutation. By the late 1990s, its short key became vulnerable to exhaustive key search attacks, and it was deprecated in favour of Triple DES (3DES), which applies DES three times with different keys for strengthened security.

数据加密标准 (DES) 是一种广泛采用的对称算法,密钥长度为 56 位,分组大小为 64 位,使用了 16 轮替换和置换的 Feistel 网络结构。到 20 世纪 90 年代末,其短密钥变得容易受到穷举密钥搜索攻击,因此被废弃,转而使用三重 DES (3DES),它使用不同密钥应用三次 DES 以增强安全性。

The Advanced Encryption Standard (AES) is the modern replacement, chosen through a public competition by NIST. AES operates on 128-bit blocks with key sizes of 128, 192, or 256 bits. It uses a substitution-permutation network (not Feistel) with 10, 12, or 14 rounds depending on key length. AES is fast in both hardware and software and is considered secure against all known practical attacks when used correctly. It is employed worldwide in protocols such as WPA2 for Wi-Fi, TLS for web traffic, and file encryption.

高级加密标准 (AES) 是现代替代方案,通过 NIST 的公开竞赛选出。AES 以 128 位分组大小工作,密钥大小可为 128、192 或 256 位。它使用替换-置换网络(非 Feistel),根据密钥长度进行 10、12 或 14 轮。AES 在硬件和软件中都很快,在正确使用的情况下,被认为能够抵御所有已知的实际攻击。它被全球广泛用于 Wi-Fi 的 WPA2、Web 流量的 TLS 以及文件加密等协议中。


7. Public Key Cryptography and RSA | 公钥密码学与 RSA

RSA (Rivest–Shamir–Adleman) is the most famous asymmetric encryption algorithm. Its security relies on the practical difficulty of factoring the product of two large prime numbers. Key generation involves selecting two large primes p and q, computing n = p × q, and choosing public exponent e (usually 65537) and private exponent d such that e × d ≡ 1 mod φ(n), where φ(n) = (p-1)(q-1). The public key is (n, e) and the private key is (n, d).

RSA(Rivest–Shamir–Adleman)是最著名的非对称加密算法。其安全性依赖于对两个大素数乘积进行因数分解的实际难度。密钥生成包括选择两个大素数 p 和 q,计算 n = p × q,并选择公开指数 e(通常为 65537)和私有指数 d,使得 e × d ≡ 1 mod φ(n),其中 φ(n) = (p-1)(q-1)。公钥为 (n, e),私钥为 (n, d)。

Encryption: C = Mᵉ mod n    Decryption: M = Cᵈ mod n

RSA is used for secure key exchange (e.g., sending an AES symmetric key encrypted with the recipient’s public key) and digital signatures. Its main drawbacks are slower processing speed and key sizes that need to grow as computing power increases (currently 2048-bit keys are recommended for security).

RSA 用于安全密钥交换(例如,用接收者的公钥加密发送 AES 对称密钥)和数字签名。其主要缺点是处理速度较慢,以及随着计算能力的提高密钥长度需要相应增长(目前推荐使用 2048 位密钥以确保安全)。


8. Hash Functions | 哈希函数

A hash function takes an input (message) of arbitrary length and produces a fixed-size string of bytes called a hash value, message digest, or fingerprint. Important properties include: deterministic (same input always gives same output), fast to compute, preimage resistance (infeasible to find original message from hash), second preimage resistance (infeasible to find different message with same hash), and collision resistance (infeasible to find any two different messages with the same hash).

哈希函数接受任意长度的输入(消息),并产生一个固定大小的字节串,称为哈希值、消息摘要或指纹。重要的属性包括:确定性(相同输入始终产生相同输出)、快速计算、原像抵抗(从哈希值寻找原始消息不可行)、第二原像抵抗(寻找具有相同哈希值的不同消息不可行)以及碰撞抵抗(寻找任意两个具有相同哈希值的不同消息不可行)。

Common hash functions include the SHA-2 family (SHA-256, SHA-512) and the older MD5 and SHA-1, both now broken for collision resistance and deprecated for security-sensitive applications. Hashes are widely used for integrity verification (checksums), password storage (hashing with salt), and as building blocks for digital signatures and Message Authentication Codes (HMAC).

常见的哈希函数包括 SHA-2 系列(SHA-256、SHA-512)以及较旧的 MD5 和 SHA-1,后两者现在在碰撞抵抗方面已被破解,不再用于安全敏感的应用程序中。哈希广泛用于完整性验证(校验和)、密码存储(带盐哈希),以及作为数字签名和消息认证码 (HMAC) 的构建模块。


9. Digital Signatures and Certificates | 数字签名与证书

A digital signature provides authentication, non-repudiation, and integrity. The sender creates a hash of the message and encrypts that hash with their private key; the result is the digital signature. The recipient decrypts the signature with the sender’s public key and compares it with a freshly computed hash of the received message. If they match, the message is authentic and unaltered, and the sender cannot deny having sent it.

数字签名提供了认证、不可否认性和完整性。发送方创建消息的哈希值,并用其私钥对该哈希值进行加密;结果即为数字签名。接收方使用发送方的公钥解密签名,并将其与接收到的消息新计算的哈希值进行比较。如果匹配,则消息是真实的且未被篡改,发送方也无法否认曾发送过该消息。

Digital certificates bind a public key to an identity (e.g., a domain name or an individual) and are issued by trusted Certificate Authorities (CAs). A certificate contains the owner’s public key, identity information, validity period, and the CA’s digital signature. The X.509 standard governs certificate format, forming the trust backbone for HTTPS and secure email.

数字证书将公钥与一个身份(例如域名或个人)绑定,并由受信任的证书颁发机构 (CA) 签发。证书包含所有者的公钥、身份信息、有效期以及 CA 的数字签名。X.509 标准管理证书格式,构成了 HTTPS 和安全电子邮件的信任骨干。


10. SSL/TLS and Encryption in Practice | SSL/TLS 与实际应用中的加密

Transport Layer Security (TLS), successor to SSL, is the protocol that secures communications over a computer network. The TLS handshake uses asymmetric encryption (often RSA or ECDHE) to securely negotiate a shared symmetric session key. Subsequent data transfer then uses symmetric encryption (e.g., AES-GCM) for efficiency. This hybrid approach leverages the best of both worlds: secure key exchange via public-key cryptography and fast bulk encryption via symmetric ciphers.

传输层安全协议 (TLS) 是 SSL 的后继协议,用于保护计算机网络上的通信。TLS 握手使用非对称加密(通常是 RSA 或 ECDHE)来安全协商一个共享的对称会话密钥。随后的数据传输则使用对称加密(例如 AES-GCM)以提高效率。这种混合方法利用了两种加密的优点:通过公钥密码学进行安全的密钥交换,通过对称密码进行快速的大批量加密。

In a typical HTTPS session (HTTP over TLS), the browser validates the server’s X.509 certificate, verifies its chain of trust, and performs key exchange. All subsequent HTTP traffic is encrypted and authenticated. Modern applications also employ Perfect Forward Secrecy (PFS), ensured by using ephemeral Diffie-Hellman key exchange, so that compromise of a long-term key does not compromise past session keys.

在一个典型的 HTTPS 会话(基于 TLS 的 HTTP)中,浏览器验证服务器的 X.509 证书,验证其信任链,并执行密钥交换。之后所有的 HTTP 流量都经过加密和认证。现代应用程序还采用完美前向保密 (PFS),通过使用短暂的 Diffie-Hellman 密钥交换来确保,即便长期密钥被泄露,过去的会话密钥也不会泄露。


11. Weaknesses, Attacks, and Legal Considerations | 弱点、攻击与法律考量

Encryption systems can be compromised through implementation flaws, poor key management, side-channel attacks (measuring timing, power consumption, or electromagnetic leaks), or advances in mathematical cryptography (e.g., quantum computing threatens RSA and ECC via Shor’s algorithm). Brute-force remains a threat for short keys; man-in-the-middle attacks can intercept traffic if certificate validation fails; and social engineering can bypass technical safeguards altogether.

加密系统可能因实现缺陷、密钥管理不当、侧信道攻击(测量时序、功耗或电磁泄露)或数学密码学的进步(例如,量子计算通过 Shor 算法威胁 RSA 和 ECC)而受到破坏。暴力破解对于短密钥仍然构成威胁;如果证书验证失败,中间人攻击可以拦截流量;而社会工程则可以完全绕过技术防护。

Legal and ethical dimensions also arise. Governments may mandate lawful access mechanisms (key escrow, backdoors) which weaken overall security. Legislation such as the UK’s Investigatory Powers Act and debates around encryption backdoors affect how cryptography is deployed. Students should recognise that encryption is a tool for privacy but must be balanced with legal oversight.

法律和伦理方面的问题也随之出现。政府可能强制要求合法访问机制(密钥托管、后门),这会削弱整体安全性。英国的《调查权力法案》等立法以及围绕加密后门的辩论,影响着密码学的部署方式。学生应认识到,加密是保护隐私的工具,但必须与法律监督相平衡。


12. Summary of Key Examination Points | 考点总结

For IB and WJEC examinations, candidates should be able to define and distinguish between symmetric and asymmetric encryption, explain the workings of classical ciphers (Caesar, Vigenère, one-time pad), describe modern standards (AES, RSA, SHA-2), and understand applications in digital signatures, certificates, and TLS. They must also analyse the strengths and weaknesses of different schemes, including vulnerability to brute-force, frequency analysis, and known-plaintext attacks, and discuss ethical and societal implications.

在 IB 和 WJEC 考试中,考生应能够定义并区分对称加密与非对称加密,解释古典密码(凯撒密码、维吉尼亚密码、一次性密码本)的工作原理,描述现代标准(AES、RSA、SHA-2),并理解在数字签名、证书和 TLS 中的应用。他们还必须分析不同方案的优缺点,包括易受暴力破解、频率分析和已知明文攻击的影响,并讨论相关的伦理和社会影响。

Key formulas to recall include Caesar shift E(x) = (x+k) mod 26, RSA encryption C = Mᵉ mod n and decryption M = Cᵈ mod n, and the properties of a secure hash function. Understanding the hybrid encryption model used in TLS — asymmetric for handshake, symmetric for session — is essential. Finally, stay updated with current threats such as quantum computing and the importance of key length in maintaining security margins.

需要掌握的关键公式包括:凯撒移位 E(x) = (x+k) mod 26,RSA 加密 C = Mᵉ mod n 和解密 M = Cᵈ mod n,以及安全哈希函数的属性。理解 TLS 中使用的混合加密模型——非对称用于握手,对称用于会话——至关重要。最后,要关注当前的威胁,如量子计算,以及密钥长度在维持安全余量方面的重要性。

Published by TutorHao | Computer Science Revision Series | aleveler.com

更多咨询请联系16621398022(同微信)

Comments

屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from aleveler.com

Subscribe now to keep reading and get access to the full archive.

Continue reading