本文旨在讲诉最基本的DES入门算法原理.
1. 变量及函数的定义
变量/函数名 | 类 型 | 说 明 |
encryption(String plain, String orginKey) | String
| DES的字符串加密,plain为明文,orginKey为8位密钥字符串 |
decryption(String cipher, String orginKey) | String | DES的字符串解密,cipher为密文,originkey为8位密钥字符串 |
fun(BitSet R, BitSet k) | BitSet | 轮结构的f函数, 32位的数据R,48位的子密钥k,返回最后经过P置换的32位输出 |
createKeys(BitSet orginKey) | Void | 根据64位密钥生成16轮子密钥subKeys16[]。orginKey为64bit位的密钥 |
left_shift(BitSet k, int shift) | BitSet | 密钥产生过程的C、D的循环左移,shift为左移位数 |
checkLength(String checked) | String | 检查字符串是否是8的整数倍,返回由0填充的整数倍字符串 |
stringToBitSet(String str) | BitSet | 字符串str转为64位的bitset类型,用于加、解密中两者的转化 |
BitSetToString(BitSet bt) | String | 返回Bitset对应的字符串,用于加、解密中两者的转化 |
subKeys16 | BitSet[] | 16轮子密钥 |
count | Int | 补零个数 |
S_BOX | int[][][] | S盒 |
desTxtDecryption(String cipherTxt, String key, String plainTxt) | Void | 对文本文档cipherTxt进行解密,将结果写入plainTxt中,plainTxt为明文文本文档文件路径,cipherTxt 密文文档文件路径,key 加密密钥 |
desTxtEncryption(String plainTxt, String key, String cipherTxt) | Void | 对文本文档plainTxt进行加密,将结果写入cipherTxt中,plainTxt为明文文本文档文件路径,cipherTxt 密文文档文件路径,key 加密密钥 |
2. 算法流程图
![des](https://img-blog.csdnimg.cn/20181215210759664.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2NhbnRmdV9seHg=,size_16,color_FFFFFF,t_70)
3.代码
github:https://github.com/cantfu/cryptography/tree/master/des