jjf2009/cryptography-network-security-lab
GitHub: jjf2009/cryptography-network-security-lab
面向高校密码学与网络安全课程的 Python 实验集合,涵盖数论基础、公钥密码体制及浏览器端图像加密的完整教学实现。
Stars: 0 | Forks: 0
# 密码学与网络安全实验室 (CNT College)
[](https://www.python.org/)
[](#license)
[](#topics-covered)
[](https://cnt-college.vercel.app)
**经典数论、公钥密码学和网络安全算法的 Python 实现** —— 为密码学与网络安全 (CNT) 的大学实验室实验而构建。
非常适合学习 **RSA**、**Diffie–Hellman**、**中国剩余定理**、**模算术**、**素性测试**、**整数分解**以及**客户端 AES-256-GCM 图像加密**的学生。
## 目录
- [本仓库是什么](#what-this-repository-is)
- [快速开始](#quick-start)
- [仓库结构](#repository-structure)
- [实验室实验目录](#lab-experiments-catalog)
- [SecureImage 作业](#secureimage-assignment)
- [涵盖主题](#topics-covered)
- [如何运行每个实验](#how-to-run-each-experiment)
- [依赖项](#dependencies)
- [学习成果](#learning-outcomes)
- [常见问题解答](#faq)
- [贡献](#contributing)
- [许可证](#license)
## 本仓库是什么
**密码学与网络安全实验室** (`cryptography-network-security-lab`) 是一个注重实践的实验室集合。每个 `exptN` 文件夹对应一个标准的大学实验单元:从整除和欧几里得算法一直到 RSA 和 Diffie–Hellman 密钥交换。
你可以用它来:
- 练习现代密码学中使用的**数论基础**
- 体验**交互式 CLI 演示**(输入素数、模数、消息)
- 研究一个真实的 **Web Crypto API** 项目,该项目使用 **AES-256-GCM** 和 **PBKDF2** 对图像进行加密
- 使用可运行的参考代码复习 **CNT / 信息安全**考试
## 快速开始
```
# Clone 仓库
git clone https://github.com/jjf2009/cryptography-network-security-lab.git
cd cryptography-network-security-lab
# 运行任意 experiment(示例:RSA)
python3 expt11/main.py
# 可选:pretty tables + plots (expt2)
pip install prettytable matplotlib
```
**SecureImage (浏览器):** 在本地打开 `Assignment/index.html`,或访问[在线演示](https://cnt-college.vercel.app)。
## 仓库结构
```
cryptography-network-security-lab/
├── README.md # This file (project overview & SEO hub)
├── llms.txt # AI / generative-engine summary
├── expt1/ … expt12/ # Lab experiments (Python)
├── Assignment/ # SecureImage AES-256-GCM web app
│ ├── index.html
│ ├── script.js
│ ├── style.css
│ └── explanation.md
└── Pratice / # Extra practice scripts (exam prep)
```
| 路径 | 描述 |
|------|-------------|
| `expt1`–`expt12` | Python 核心密码学实验室实验 |
| `Assignment/` | 客户端 **SecureImage** 加密/解密器 |
| `Pratice /` | 用于复习的精简练习代码 |
| `llms.txt` | 供 AI 搜索引擎使用的机器可读摘要 |
## 实验室实验目录
| # | 文件夹 | 标题 | 算法与概念 |
|---|--------|--------|------------------------|
| 1 | [`expt1`](./expt1/) | **算术与整除性** | 基本运算,整除定理 \(a\|b\),\(a\|c\) |
| 2 | [`expt2`](./expt2/) | **欧几里得算法 (GCD)** | 带步骤表的迭代 GCD;可选的 matplotlib 可视化 |
| 3 | [`expt3`](./expt3/) | **线性丢番图方程** | 通过 GCD 以及特解和通解求解 \(ax + by = c\) |
| 4 | [`expt4`](./expt4/) | **线性同余与模逆元** | 扩展欧几里得算法,欧拉函数 \(\varphi(n)\),模逆元 |
| 5 | [`expt5`](./expt5/) | **中国剩余定理 (CRT)** | 同余方程组,两两互素的模数 |
| 6 | [`expt6`](./expt6/) | **伪随机数生成器** | **Blum–Blum–Shub (BBS)**,**线性同余生成器 (LCG)** |
| 7 | [`expt7`](./expt7/) | **素性测试** | 雅可比符号,概率素性测试 |
| 8 | [`expt8`](./expt8/) | **整数分解** | 费马分解及相关因式分解方法 |
| 9 | [`expt9`](./expt9/) | **离散对数 (Pohlig–Hellman)** | 当 \(p-1\) 平滑时的 Pohlig–Hellman 攻击;CRT 重组 |
| 10 | [`expt10`](./expt10/) | **经典密码** | **移位 (Caesar)** 密码,**仿射** 密码加密/解密 |
| 11 | [`expt11`](./expt11/) | **RSA 公钥密码体制** | 使用素数 \(p, q\) 生成密钥、加密、解密 |
| 12 | [`expt12`](./expt12/) | **Diffie–Hellman 密钥交换** | 通过模幂运算从公开值生成共享密钥 |
## SecureImage 作业
**SecureImage** 是 [`Assignment/`](./Assignment/) 中的一个浏览器原生图像加密工具。
| 功能 | 详情 |
|---------|--------|
| 密码算法 | **AES-256-GCM** (认证加密) |
| 密钥派生 | **PBKDF2** + SHA-256,100,000 次迭代 |
| 平台 | Web Crypto API (`crypto.subtle`) — 无后端,无上传 |
| 输出格式 | 可移植文本:`IV:Tag:Ciphertext` (Base64) |
| 文档 | [`Assignment/explanation.md`](./Assignment/explanation.md) |
使用密码短语加密图像,下载 `encrypt.txt`,以后再使用相同的密码短语解密 —— 完全在设备上完成。
**试试看:** [https://cnt-college.vercel.app](https://cnt-college.vercel.app)
## 涵盖主题
用于搜索、课程映射和 AI 发现的关键词:
`cryptography` · `network-security` · `number-theory` · `euclidean-algorithm` · `extended-euclidean` · `gcd` · `linear-diophantine` · `modular-inverse` · `chinese-remainder-theorem` · `crt` · `euler-totient` · `blum-blum-shub` · `linear-congruential-generator` · `primality-test` · `jacobi-symbol` · `fermat-factorization` · `pohlig-hellman` · `caesar-cipher` · `affine-cipher` · `rsa-algorithm` · `diffie-hellman` · `public-key-cryptography` · `aes-256-gcm` · `pbkdf2` · `web-crypto-api` · `python-cryptography-labs` · `cnt-college` · `information-security`
## 如何运行每个实验
大多数脚本都是交互式 CLI。从仓库根目录运行:
```
python3 expt1/main1.py # Arithmetic & divisibility
python3 expt2/main.py # Euclidean GCD table
python3 expt3/main.py # Diophantine equations
python3 expt4/main.py # Linear congruences
python3 expt5/main.py # Chinese Remainder Theorem
python3 expt6/main1.py # BBS & LCG generators
python3 expt7/Primality_test.py
python3 expt8/Factorization.py
python3 expt9/main.py # Pohlig–Hellman
python3 expt10/main.py # Shift & Affine ciphers
python3 expt11/main.py # RSA
python3 expt12/main.py # Diffie–Hellman
```
面向考试的变体(如果存在):位于 `expt4` / `expt5` 中的 `examcode.py`。
## 依赖项
| 包 | 使用者 | 安装 |
|---------|---------|---------|
| Python 3.8+ | 所有实验 | 系统 / [python.org](https://www.python.org/) |
| `prettytable` | GCD / 同余表 | `pip install prettytable` |
| `matplotlib` | 可选的 GCD 可视化 (`expt2`) | `pip install matplotlib` |
| 现代浏览器 | 仅 SecureImage | Chrome, Firefox, Edge, Safari |
核心实验室不需要外部的密码学库 —— 为了学习的清晰性,模算术和算法都是根据基本原理实现的。
## 学习成果
完成这套实验室实验后,你应该能够:
1. 通过手动计算和编写代码应用**整除性**、**GCD** 和**扩展欧几里得算法**
2. 通过**中国剩余定理**求解**线性同余**及其方程组
3. 解释密码学教学中使用的 **PRNG** 设计 (BBS 对比 LCG)
4. 使用经典方法分解小整数并测试素性
5. 使用玩具素数端到端实现 **RSA** 和 **Diffie–Hellman**
6. 在浏览器中使用 **AES-GCM** 和基于密码的密钥加密图像
## 常见问题解答
### 在本仓库中 CNT 代表什么?
这里的 **CNT** 指的是**密码学与网络安全**(大学课程 / 实验室科目),而不是企业产品名称。
### 这是生产级别的密码学吗?
**不是。** 实验室代码使用的是小素数和用于教学目的的实现。**不要**使用这些脚本来保护真实的机密。在生产环境中,请使用经过审计的库(OpenSSL、libsodium、带有适当威胁建模的 Web Crypto 等)。
### 为什么 SecureImage 完全是客户端的?
这样图像和密码短语就永远不会离开浏览器。加密通过 **Web Crypto API** 在本地运行。
### 这适合谁?
正在修读**密码学**、**网络安全**或**信息安全**实验室课程的本科生和大专生;需要可运行演示的导师;任何正在复习基于数论的密码学的人。
### 我可以将其用于作业或教学吗?
可以,用于学习和教学时请注明出处。在提交课程作业之前,请检查您所在机构的学术诚信规定。
## 许可证
教育/学习材料。可免费学习、复刻并改编用于课程作业和教学,但需注明原始仓库:
**https://github.com/jjf2009/cryptography-network-security-lab**
## 项目标识(名称与描述)
| 字段 | 值 |
|-------|--------|
| **仓库名称** | `cryptography-network-security-lab` |
| **显示名称** | Cryptography & Network Security Lab (CNT College) |
| **简短描述** | 用于密码学与网络安全的 Python 实验室实验:RSA、Diffie–Hellman、CRT、模算术、经典密码,以及浏览器中的 AES-256-GCM SecureImage。 |
| **主页** | https://cnt-college.vercel.app |
| **主要语言** | Python · JavaScript (SecureImage) |
你可以运行的密码学 —— 从欧几里得算法到 RSA 和 AES-GCM。
GitHub ·
SecureImage demo ·
llms.txt
标签:AES-256-GCM, Python, Web Crypto API, 多模态安全, 密码学, 手动系统调用, 教学实验, 数据可视化, 数论, 无后门, 网络安全, 逆向工具, 隐私保护