#加密解密 #解密 #加密 #cli #终端 #目录递归

app xor

CLI应用程序,实现基本的XOR加密/解密

13个稳定版本

使用旧的Rust 2015

1.4.5 2017年8月18日
1.4.4 2017年7月27日
1.3.0 2017年6月27日
1.2.2 2017年5月21日
0.2.0 2017年4月9日

#1766 in 密码学

45 每月下载次数

MIT 许可证

24KB
409 代码行

xor

使用Rust编写的命令行应用程序,实现基本的XOR加密。

可以从stdin、文件或递归地加密目录的所有内容(包括重命名文件)。

安装

如果您尚未安装,请安装rust: https://www.rust-lang.net.cn/

然后使用cargo安装:

$ cargo install xor

帮助

$ xor --help
xor 1.4.4
Gavyn Riebau

XOR encrypt files or directories using a supplied key.

In it's simplest form, reads input from stdin, encrypts it against a key and writes the result to stdout.
The "key" option can be either a path to a file or a string of characters.

When the "recursive" option is used, files under a given directory are recursively encrypted.
Files are renamed by XORing the original name against the provided key, then hexifying the result.
To decrypt you must use the "decrypt" flag, files are then renamed by unhexifying then XORing.

USAGE:
    xor [FLAGS] [OPTIONS] --key <KEY>

FLAGS:
    -d, --decrypt    Decrypt directory names rather than encrypting them.
                     Applies when using the "recursive" option to encrypt a directory.
                     When set, directory names are decrypted by unhexifying then XORing.
                     When not set, directory names are encrypted by XORing then hexifying.
    -f, --force      Don't show warning prompt if the key size is too small and key bytes will have to be re-used.
                     Re-using key bytes makes the encryption vulnerable to being decrypted.
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -i, --input <FILE>             The file from which input data will be read, if omitted, and the "recursive" option isn't used, input will be read from stdin.
    -k, --key <KEY>                The file containing the key data, or a provided string, against which input will be XOR'd.
                                   This should be larger than the given input data or will need to be repeated to encode the input data.
    -o, --output <FILE>            The file to which encoded data will be written, if omitted output will be written to stdout.
                                   It's recommended to write output to a file for cases where the encoded data contains non-unicode characters which would otherwise not be printed to the console.
    -r, --recursive <DIRECTORY>    Recursively encrypt / decrypt files and subfolders starting at the given directory.
                                   Files and directory names will be encrypted / decrypted according to the "mode" argument.
                                   Names are xor encrypted then converted to a hex string.

示例用法

以下是一个示例,说明如何使用相同的密钥加密一些数据,然后再解密它

加密单个文件

原始数据。

$ cat lorem_ipsum.txt
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

使用密钥"12345"加密数据。

$ xor -k "12345" -i lorem_ipsum.txt -o lorem_ipsum.enc
$ cat lorem_ipsum.enc
}]AQX[CG@\W[Y^@G\ERYPEWZ_AVWATFFFPVZD\BQZZRW_]A@QQV\PXG@YZUGQXA]A\_QZP\UG]@DFXTS]AQTFPZ]]AQ\STZTS_]DDS`EVZ\\RP\[]]XDVZ\P_DD[@[^AGF@UVLPCQZ@TE[\ZD^_UXR]XTS]A]F\ZG\GGT][BA\AVLTSWZ\_\PZQ\ZFTCFUAwA\BRAATZF@CWPZ]]A\_AQECW[Q[UWA]A[]C^^FDAPFVCT^Z@TA@QR[_X@\W[Y^@VPDUARXSG[D^_UASA]TEGAtJPQEEWFFB[]@^QPUPRSGVDBZPTESG[^\DG^[WQ[EG@_F][QFXEPBA\]UR\R[RQTAVF@_FYZ]^Z@P\ZYXVQFE_UW^@FY;

使用之前相同的密钥解密加密数据。

$ xor -k "12345" -i lorem_ipsum.enc -o lorem_ipsum.dec
$ cat lorem_ipsum.dec
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

递归加密目录内容

列出目录

$ ls -R
directory_one
directory_two
example

./directory_one:
child_directory
file_one

./directory_one/child_directory:
file_three

./directory_two:
file_two

递归加密所有文件和子目录。

$ xor -k "12345" -r .
$ ls -R
555B415156455D414D6A5E5C56
555B415156455D414D6A45455C

./555B415156455D414D6A5E5C56:
525A5A58516E565A465052465C464C
575B5F516A5E5C56

./555B415156455D414D6A5E5C56/525A5A58516E565A465052465C464C:
575B5F516A455A415150

./555B415156455D414D6A45455C:
575B5F516A45455C

递归解密所有文件和子目录。

$ xor -k "12345" -r . -d
$ ls -R
directory_one
directory_two
example

./directory_one:
child_directory
file_one

./directory_one/child_directory:
file_three

./directory_two:
file_two

依赖关系

~5MB
~92K SLoC