Jerrytriple8/string-entropy

GitHub: Jerrytriple8/string-entropy

一个零依赖的纯 Bash Shannon 熵计算器,用于评估字符串和文件的随机性与可预测性。

Stars: 0 | Forks: 0

# string-entropy 计算字符串和文件的 [Shannon 熵](https://en.wikipedia.org/wiki/Entropy_(information_theory))。纯 bash 实现,零依赖。 ## 什么是 Shannon 熵? 衡量数据中的随机性/不可预测性。熵越高 = 越随机。 | 熵值范围 | 含义 | |---|---| | 0.0 - 2.0 | 极低(英文文本,结构化数据) | | 2.0 - 4.0 | 中低(混合内容) | | 4.0 - 6.0 | 中等(多样化字符集) | | 6.0 - 8.0 | 高(压缩/编码数据) | | 8.0 | 最大(完全随机的字节) | ## 安装 ``` git clone https://github.com/Jerrytriple8/string-entropy.git cd string-entropy chmod +x entropy.sh sudo ln -s $(pwd)/entropy.sh /usr/local/bin/entropy ``` ## 用法 ``` # String entropy entropy "hello world" # → 2.845 # From stdin echo "password123" | entropy # → 2.866 # File entropy entropy -f /bin/ls # → 5.923 # Per-line analysis entropy -l file.txt # Verbose (显示字符分布) entropy -v "test string" # Bits of entropy (非每字符) entropy -b "longer string here" # 比较多个字符串 entropy "foo" "bar" "baz" ``` ## 使用场景 - **密码强度**:熵越高 = 越难猜测 - **恶意软件分析**:加壳/加密部分具有高熵值 - **数据分类**:检测加密文件与纯文本文件 - **压缩评估**:低熵值数据压缩效果好 - **随机性测试**:验证 RNG 输出 ## 示例 ``` # 检查文件是否可能被加密 entropy -f suspicious_file.dat # → 7.998 ← 几乎最大,可能已加密/压缩 # 比较密码强度 entropy "password" "P@ssw0rd!" "x7$kL9#mQ2&" # → 2.408 3.000 3.584 # 查找日志中的高 entropy 行 entropy -l access.log | sort -t: -k2 -rn | head ``` ## License MIT
标签:Cutter, DAST, Shell脚本, 代码示例, 信息熵, 密码强度检测, 应用安全, 恶意软件分析, 数据分析