9 个版本
| 0.2.6 | 2022年9月18日 | 
|---|---|
| 0.2.5 | 2020年2月11日 | 
| 0.2.4 | 2019年11月25日 | 
| 0.2.2 | 2019年10月27日 | 
| 0.1.1 | 2019年9月8日 | 
#1444 in 命令行实用工具
每月下载 42 次
43KB
680 行
bishop.rs
| +----[drunken]----+ |..+.. oo+o. | | *.* o +.o. | |= = o * .E+ | |+. ..+ = +.. | |o ...+ S.o | | .o .....= . | |.. o .+ + | |. = + | | ..= | +----[bishop]-----+ | 
用于使用 Rust 中实现的 Drunken Bishop 算法可视化数据的库和 CLI 应用程序
Drunken Bishop 是 OpenSSH 的
ssh-keygen中用于可视化生成密钥的算法
目录
Crates
| Crates | 描述 | 版本 | 
|---|---|---|
| bishop | 库 | |
| bishop-cli (源代码) | 命令行应用程序 | 
安装
Rust 库 在 crates.io 上
命令行应用程序
| 平台 | 包 | 
|---|---|
| Arch Linux | |
| Linux 的预构建 | Github 发布 | 
示例
作为命令行应用程序使用
some_data=$(printf foobar | sha256sum | cut -d' ' -f1)
# we are using cut here to crop the filename from sha256sum output
printf $some_data | bishop -sI hex
# `-s` tells bishop to take data from stdin
#
# `-I hex` tells bishop that input data will be in HEX format.
# As an alternative, you might use xxd to turn hex data into binary:
printf $some_data | xxd -r -p | bishop -s
# `-I bin` is implied by default
bishop -i <(printf $some_data) -I hex
# `-i` tells bishop to take data from specified file.
# We are using bash command substitution here, but
# any valid path is allowed, like `bishop -i ~/some.file`
bishop $some_data
# Without `-i` or `-s` bishop expects HEX encoded input in the first argument.
# Note that `-I` is not supported if data is provided as argument
printf foobar | bishop -sI hash
# `-I hash` tells bishop to hash all of its input
# using sha256 before making a randomart.
# Since maximum effective size of input data for random art with default size (17x9)
# is somwhere around 64-128 bytes, this option is extremely useful for large inputs  
所有这些 bishop 调用都会将此艺术打印到控制台
Fingerprint of:
c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2
+-----------------+
|    .     .      |
| . + .   +       |
|o + + + = .      |
| * + + O =       |
|  E o.o S        |
| . +.=.o.=       |
|  o.B.=...       |
|   +.+.*  o      |
|    o.o.o. .     |
+-----------------+
请注意,只有当提供数据作为参数或使用 -I hash 时,输入才会被回显。可以使用 -q 选项禁用此行为。
您可以在 此处 读取 CLI 应用程序的完整用法(也可通过 --help 选项获得)
字符列表说明
您可以使用 -c 选项提供自定义字符列表。这是一个用于指纹(表示为字符串)的字符向量。
每个字符都按以下方式处理
| 索引 | 描述 | 默认值 | 
|---|---|---|
| 0 | 字段背景 |   | 
| 1..n | 用于绘图的字符 | .o+=*BOX@%&#/^ | 
| n+1 | 起始位置的字符 | S | 
| n+2 | 结束位置的字符 | E | 
每个非背景字符表示 bishop 在此位置出现过的次数。
起始和结束字符将覆盖实际值。
字符列表至少为 4 个字符长,但安全的字符列表至少为 18 个字符长,并且只由明显可区分的符号组成。
作为库使用
Cargo.toml
bishop = "0.2.0"
使用载货徽章上说明的最新版本(见上方)
对于 AsRef<u8> (切片、向量)
extern crate bishop;
use bishop::*;
fn main() {
    let data1 = [0u8; 16];
    let data2 = vec![0u8; 16];
    let mut art = BishopArt::new();
    art.input(&data1);
    art.input(&data2);
    println!("{}", art.draw());
    // Using chaining:
    let drawn_art: String = BishopArt::new()
        .chain(&data1)
        .chain(&data2)
        .draw();
    println!("{}", drawn_art);
}
绘图选项和结果的重用
use bishop::*;
fn random_art(data: &[u8]) {
    let opts1 = DrawingOptions { top_text: "pass 1".to_string(), ..Default::default() };
    let opts2 = DrawingOptions { bottom_text: "pass 2".to_string(), ..Default::default() };
    // compute field once
    let field = BishopArt::new().chain(data).result();
    // then draw it multiple times with different options
    println!("{}", field.draw_with_opts(&opts1));
    println!("{}", field.draw_with_opts(&opts2));
}
对于 Read (文件、stdin 等)
use bishop::*;
use std::io::{self, Read};
fn main() {
    // BishopArt implements Write trait
    let mut art = BishopArt::new();
    io::copy(&mut io::stdin(), &mut art);
    println!("{}", art.draw());
}
完整的API文档可在docs.rs上找到
许可证
根据您的选择,许可协议可以是以下之一
- Apache License,版本2.0(LICENSE-APACHE 或 https://apache.ac.cn/licenses/LICENSE-2.0)
- MIT许可协议(LICENSE-MIT 或 https://open-source.org.cn/licenses/MIT)
(任选其一)。
贡献
除非您明确说明,否则根据Apache-2.0许可协议定义的,您有意提交以包含在该作品中的任何贡献,都将根据上述方式双许可,不附加任何额外条款或条件。
依赖项
约3.5MB
约65K SLoC