Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

FileMask

🔐 下一代文件隐藏与加密工具

58 种字节级掩码 × 8 种加密算法 = 464 种组合,让你的数据无影无踪

C++17 License: MIT Platform AI-Assisted

English | 中文


中文

📖 项目简介

FileMask 是一款基于 C++17 开发的高性能命令行文件保护工具。它创新性地将 58 种字节级掩码变换8 种经典/现代加密算法 相结合,通过双层防护机制实现文件内容的深度隐藏与加密。

不同于传统加密软件,FileMask 独特的掩码层可以有效改变文件的字节分布特征,使加密后的数据在静态分析中呈现出更强的随机性,从而在需要绕过文件类型检测、内容审计等场景下发挥独特作用。

💡 设计哲学:不是最强的加密,而是最灵活的隐藏。当你需要的是「不被发现」而非「不可破解」时,FileMask 是你的理想选择。

✨ 核心特性

特性 说明
🔢 58 种掩码变换 XOR、按位取反、字节旋转、格雷码、位反转、按位置换、校验流异或、跨字节交换...
🔐 8 种加密算法 AES-128-CBC、3DES-168、RC6-256、ChaCha20、SM4-128-CBC、栅栏密码、列置换密码、Enigma 机
📦 零依赖 纯 C++17 标准库实现,无任何第三方依赖,单文件编译
高性能 掩码处理亚毫秒级,主流算法加密 1MB 数据仅需 1-30ms
🧩 464 种组合 掩码与算法可任意组合,满足不同安全等级需求
三重校验 CRC32 + MD5 + SHA-256 完整性校验,确保数据万无一失
📂 批量处理 支持目录递归扫描,一键加密/解密整个目录树
🔑 密钥恢复 -r 参数支持密钥自动备份与暴力尝试恢复
🕒 时间戳保留 自动保留原文件修改时间,解密后完美还原

🎯 应用场景

  • 📁 文件隐藏与伪装 — 改变文件字节特征,绕过格式检测与内容审计
  • 🔒 数据加密保护 — 敏感文件的多层级加密存储
  • 🛡️ 反静态分析 — 掩码层增加二进制分析难度
  • 📤 安全传输 — 多层加密确保传输过程中的数据安全
  • 🧪 加密算法研究 — 8 种算法的纯 C++ 实现,学习与研究的绝佳素材
  • ⚙️ CTF 工具 — 多种经典密码算法的快速实现

🚀 快速开始

环境要求

  • 编译器: GCC 7+ / Clang 5+ / MSVC 2017+
  • 标准: C++17 或更高
  • 系统: Windows / Linux / macOS

构建编译

# 克隆项目
git clone <repository-url>
cd FileMask

# 使用 GCC 编译
g++ -std=c++17 -O2 -o filemask main.cpp

# 使用 Clang 编译
clang++ -std=c++17 -O2 -o filemask main.cpp

# Windows (MSVC)
cl /EHsc /std:c++17 /O2 main.cpp /Fe:filemask.exe

基本使用

# 加密文件 (默认: 掩码1 + 无加密)
filemask -i secret.txt

# 使用 AES-128 + 掩码12 加密
filemask -i secret.txt -a 0 -m 12

# 加密并自动备份密钥到 recovery.txt
filemask -i secret.txt -a 0 -m 12 -r

# 解密文件
filemask -d -i secret.txt.fm -k k-1a2b3c4d...

# 使用 recovery.txt 自动尝试解密
filemask -d -i secret.txt.fm -r

# 批量加密整个目录
filemask -i ./docs -a 3 -m 40 -o ./encrypted

📊 性能基准 (Benchmark)

测试环境: 50MB 测试文件, Intel Core i7, GCC -O2 优化

掩码性能分级

等级 耗时 (50MB) 掩码编号 类型
⚡ 极快 ~23ms 55 首尾交换
🚀 很快 ~33ms 0, 2, 3, 5, 6, 8, 9, 11, 12, 14, 15, 31, 32, 33, 53, 54, 56 恒等 / 奇偶位XOR / 按位取反 / 格雷码等
🏃 快 ~45ms 1, 4, 7, 10, 13, 37-45, 49, 50, 52, 57 全字节XOR / 旋转 / 校验流XOR等
🚶 中 ~55ms 40, 51 循环左移4位 / SHA256流XOR
🏃‍♂️ 较快 ~100ms 26-30, 36 完全平方位
� 较慢 ~320ms 46-48 位反转 / 按位置换
� 慢 ~420ms 21-25, 35 斐波那契位
🦥 很慢 ~13s 16-20, 34 素数位

加密算法性能分级

等级 算法 编号 耗时 (50MB)
⚡ 极快 列置换密码 6 ~73ms
⚡ 极快 ChaCha20 3 ~82ms
🚀 快 栅栏密码 5 ~177ms
🚶 中 SM4-128-CBC 4 ~860ms
🚶 中 AES-128-CBC 0 ~1.1s
🚶 中 RC6-256 2 ~1.3s
🐢 慢 Enigma Machine 7 ~3.6s
🦥 很慢 3DES-168 1 ~28s

🔧 命令行参数

用法:
  加密: filemask.exe -i <输入路径> -a <算法> -m <掩码> [选项]
  解密: filemask.exe -d -i <输入路径> -k <密钥> [选项]

选项说明:
  -i <路径>     输入文件或目录(必填,目录递归遍历)
  -a <算法>     加密算法,取值 0-7,8=无加密 (默认: 8 无加密)
  -m <类型>     掩码类型,取值 0-57 (默认: 1 全字节XOR 0xFF)
  -d            启用解密模式 (默认: 加密模式)
  -k <密钥>     解密密钥 (k-开头的64字符十六进制,解密必填)
  -o <目录>     输出目录 (默认: .\opt)
  -t <数量>     线程数 (默认: 1)
  -r            密钥恢复模式: 加密时保存密钥到 recovery.txt
                            解密时从 recovery.txt 逐个尝试密钥
  -h            显示完整帮助信息

📁 文件格式

加密后的文件采用自定义 .fm 格式,结构如下:

┌──────────────────────────────────────────────────────────┐
│                     FMHeader (64 字节)                   │
├──────────┬──────────┬───────────┬───────────────────────┤
│  magic   │timestamp │ mask_type │       key_type        │
│  (2B)    │   (4B)   │   (1B)    │         (1B)          │
├──────────┴──────────┴───────────┴───────────────────────┤
│                     crc_before (4B)                      │
├──────────────────────────────────────────────────────────┤
│                      crc_after (4B)                      │
├──────────────────────────────────────────────────────────┤
│                        md5 (16B)                         │
├──────────────────────────────────────────────────────────┤
│                       sha256 (32B)                       │
├──────────────────────────────────────────────────────────┤
│                                                          │
│                    Encrypted Payload                     │
│                    (加密后数据载荷)                      │
│                                                          │
└──────────────────────────────────────────────────────────┘

🧠 技术亮点

  1. 纯手工实现 — 所有加密算法、哈希函数均从零实现,无外部依赖
  2. 链式 IV 设计 — CBC 模式采用密文块链式 IV,无需额外存储
  3. 密钥派生机制 — 独特的 32 字节派生密钥方案,原始密钥与派生密钥分离
  4. 自逆掩码设计 — 多数掩码为自逆操作,加密解密共用同一函数
  5. 时间戳复用 — 文件时间戳既保留元数据,又作为 IV/Nonce 来源

� 贡献指南

欢迎贡献代码!如果你有好的想法或发现了 Bug:

  • 🐛 提交 Issue — 报告问题或提出新功能建议
  • 🔧 提交 Pull Request — 直接贡献代码改进

💡 无论是算法优化、新掩码/新加密算法、文档改进,还是 Bug 修复,所有形式的贡献都非常欢迎!

� 作者信息

📜 许可证

本项目采用 MIT License 开源协议 — 详见 LICENSE 文件。

🤖 声明: 本项目部分代码由 AI 辅助生成,核心架构与算法设计由人工完成。


English

📖 Introduction

FileMask is a high-performance command-line file protection tool developed in C++17. It innovatively combines 58 byte-level mask transformations with 8 classic/modern encryption algorithms, achieving deep file hiding and encryption through a dual-layer protection mechanism.

Unlike traditional encryption software, FileMask's unique mask layer effectively alters the byte distribution characteristics of files, making encrypted data appear more random in static analysis. This makes it particularly useful in scenarios where you need to bypass file type detection, content auditing, and similar checks.

💡 Design Philosophy: Not the strongest encryption, but the most flexible hiding. When what you need is "not being found" rather than "unbreakable", FileMask is your ideal choice.

✨ Key Features

Feature Description
🔢 58 Mask Transformations XOR, bit inversion, byte rotation, Gray code, bit reversal, permutation, checksum stream XOR, cross-byte swap...
🔐 8 Encryption Algorithms AES-128-CBC, 3DES-168, RC6-256, ChaCha20, SM4-128-CBC, Rail Fence, Columnar Transposition, Enigma Machine
📦 Zero Dependencies Pure C++17 standard library implementation, no third-party dependencies, single-file compilation
High Performance Sub-millisecond mask processing, mainstream algorithms encrypt 1MB in 1-30ms
🧩 464 Combinations Masks and algorithms can be freely combined to meet different security level requirements
Triple Verification CRC32 + MD5 + SHA-256 integrity checks ensure data integrity
📂 Batch Processing Supports recursive directory scanning, encrypt/decrypt entire directory trees with one command
🔑 Key Recovery -r flag supports automatic key backup and brute-force attempt recovery
🕒 Timestamp Preservation Automatically preserves original file modification time, perfectly restored after decryption

🎯 Use Cases

  • 📁 File Hiding & Camouflage — Alter file byte signatures to bypass format detection and content auditing
  • 🔒 Data Encryption Protection — Multi-level encryption storage for sensitive files
  • 🛡️ Anti-Static Analysis — Mask layer increases binary analysis difficulty
  • 📤 Secure Transmission — Multi-layer encryption ensures data security during transmission
  • 🧪 Cryptography Research — Pure C++ implementations of 8 algorithms, excellent material for learning and research
  • ⚙️ CTF Toolkit — Quick implementations of various classic cipher algorithms

🚀 Quick Start

Requirements

  • Compiler: GCC 7+ / Clang 5+ / MSVC 2017+
  • Standard: C++17 or higher
  • Platform: Windows / Linux / macOS

Building

# Clone the repository
git clone <repository-url>
cd FileMask

# Compile with GCC
g++ -std=c++17 -O2 -o filemask main.cpp

# Compile with Clang
clang++ -std=c++17 -O2 -o filemask main.cpp

# Windows (MSVC)
cl /EHsc /std:c++17 /O2 main.cpp /Fe:filemask.exe

Basic Usage

# Encrypt a file (default: mask 1 + no encryption)
filemask -i secret.txt

# Encrypt with AES-128 + mask 12
filemask -i secret.txt -a 0 -m 12

# Encrypt and auto-backup key to recovery.txt
filemask -i secret.txt -a 0 -m 12 -r

# Decrypt a file
filemask -d -i secret.txt.fm -k k-1a2b3c4d...

# Auto-attempt decryption using recovery.txt
filemask -d -i secret.txt.fm -r

# Batch encrypt an entire directory
filemask -i ./docs -a 3 -m 40 -o ./encrypted

📊 Performance Benchmark

Test environment: 50MB test file, Intel Core i7, GCC -O2 optimization

Mask Performance Tiers

Tier Latency (50MB) Mask IDs Type
⚡ Blazing ~23ms 55 End swap
🚀 Very Fast ~33ms 0, 2, 3, 5, 6, 8, 9, 11, 12, 14, 15, 31, 32, 33, 53, 54, 56 Identity / Parity XOR / Bitwise NOT / Gray code, etc.
🏃 Fast ~45ms 1, 4, 7, 10, 13, 37-45, 49, 50, 52, 57 Full-byte XOR / Rotation / Checksum stream XOR, etc.
🚶 Medium ~55ms 40, 51 ROL 4 bits / SHA256 stream XOR
🏃‍♂️ Quite Fast ~100ms 26-30, 36 Perfect square positions
� Slower ~320ms 46-48 Bit reversal / Bit permutation
� Slow ~420ms 21-25, 35 Fibonacci positions
🦥 Very Slow ~13s 16-20, 34 Prime positions

Encryption Algorithm Performance Tiers

Tier Algorithm ID Latency (50MB)
⚡ Blazing Columnar Transposition 6 ~73ms
⚡ Blazing ChaCha20 3 ~82ms
🚀 Fast Rail Fence Cipher 5 ~177ms
🚶 Medium SM4-128-CBC 4 ~860ms
🚶 Medium AES-128-CBC 0 ~1.1s
🚶 Medium RC6-256 2 ~1.3s
🐢 Slow Enigma Machine 7 ~3.6s
🦥 Very Slow 3DES-168 1 ~28s

🔧 Command Line Options

Usage:
  Encrypt: filemask.exe -i <input> -a <algo> -m <mask> [options]
  Decrypt: filemask.exe -d -i <input> -k <key> [options]

Options:
  -i <path>     Input file or directory (required, recursive for directories)
  -a <algo>     Encryption algorithm, 0-7, 8=no encryption (default: 8)
  -m <type>     Mask type, 0-57 (default: 1 full-byte XOR 0xFF)
  -d            Enable decrypt mode (default: encrypt mode)
  -k <key>      Decryption key (k- prefixed 64-char hex, required for decryption)
  -o <dir>      Output directory (default: .\opt)
  -t <num>      Thread count (default: 1)
  -r            Recovery mode: save key to recovery.txt on encrypt
                              try all keys from recovery.txt on decrypt
  -h            Show full help information

📁 File Format

Encrypted files use the custom .fm format with the following structure:

┌──────────────────────────────────────────────────────────┐
│                     FMHeader (64 bytes)                  │
├──────────┬──────────┬───────────┬───────────────────────┤
│  magic   │timestamp │ mask_type │       key_type        │
│  (2B)    │   (4B)   │   (1B)    │         (1B)          │
├──────────┴──────────┴───────────┴───────────────────────┤
│                     crc_before (4B)                      │
├──────────────────────────────────────────────────────────┤
│                      crc_after (4B)                      │
├──────────────────────────────────────────────────────────┤
│                        md5 (16B)                         │
├──────────────────────────────────────────────────────────┤
│                       sha256 (32B)                       │
├──────────────────────────────────────────────────────────┤
│                                                          │
│                    Encrypted Payload                     │
│                                                          │
└──────────────────────────────────────────────────────────┘

🧠 Technical Highlights

  1. Hand-crafted Implementations — All encryption algorithms and hash functions are implemented from scratch, no external dependencies
  2. Chained IV Design — CBC mode uses ciphertext block chaining IV, no extra storage required
  3. Key Derivation Mechanism — Unique 32-byte derived key scheme, separating raw and derived keys
  4. Self-inverse Mask Design — Most masks are self-inverse operations, same function for encryption and decryption
  5. Timestamp Reuse — File timestamp both preserves metadata and serves as IV/Nonce source

👥 Contributing

Contributions are welcome! If you have ideas or found a bug:

  • 🐛 Open an Issue — report problems or suggest new features
  • 🔧 Submit a Pull Request — contribute code improvements directly

💡 Whether it's algorithm optimization, new masks/encryption algorithms, documentation improvements, or bug fixes, all forms of contribution are greatly appreciated!

👤 Author

📜 License

This project is licensed under the MIT License — see the LICENSE file for details.

🤖 Disclaimer: Portions of this project's code were generated with AI assistance. Core architecture and algorithm design are human-authored.


Made with ❤️ by murasakii

If you find this project useful, please give it a star! ⭐

Issues and Pull Requests are always welcome! 🤝

About

一种通过字节掩码+加密实现数据保护和隐藏的工具;A tool for data protection and concealment achieved through byte masking and encryption;

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors