You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# include <string>
# pragma once
using namespace std ;
class cDESUtils
{
public :
cDESUtils ( void ) ;
~ cDESUtils ( void ) ;
private :
/**
*最终置换函数 64位->64位
*函数说明: s为完成最后一轮循环得到的64为数据
*返回值为密文或明文
*/
string final_permutation ( string s ) ;
/**
*P盒置换函数 32位->32位
*函数说明: s为S盒的输出
*/
string P_box ( string s ) ;
/**
*S盒置换函数 48位->32位
*函数说明: s为48位数据
*返回值为32位
*/
string S_box ( string s ) ;
/**
*异或运算函数
*要求位数相同
*/
string XOR ( string s1 , string s2 ) ;
/**
*数据扩展函数 32->48
*函数说明: s为数据的右半部分 32位
*扩展成48位的输出
*/
string plaintext_righthalf_extended_permutation ( string s ) ;
/**
*密钥压缩置换函数 56位->48位
*函数说明: s为56为的密钥
*输出为48位的子密钥
*/
string secret_key_compression_replacement ( string s ) ;
/**
*密钥循环左移函数 56位->56位
*函数说明: k为左移位数 s为密钥
*返回值位数不变
*/
string secret_ket_left_move ( int k , string s ) ; //密钥循环左移k位
/**
*密钥初始置换函数 64位->58位
*函数说明: s为64位的初始密钥
*返回值为58位
*/
string secret_key_initial_permutation ( string s ) ;
/**
*明文初始置换函数 64位->64位
*函数说明: s为初始明文 64位
*返回值为6位
*/
string plaintext_initial_permutation ( string s ) ; //明文初始置换
/**
*封装函数f
*函数说明: 接收32位数据和48位的子密钥 产生一个32位的输出
*str1:32位数据 str2:48位的子密钥
*返回值32位
*/
string foldFunc ( string str1 , string str2 ) ;
string Keys [ 20 ] ;
public :
/**
*16进制转2进制函数
*函数说明: s为16进制字符串
*返回为2进制字符串
*/
string H ( string s ) ;
/**
*2进制转16进制函数
*str为2进制字符串
*返回值为16进制字符串
*/
string G ( string str ) ;
/**
*子密钥生成函数
*函数说明: s为给定的密钥
*生成16个子密钥
*/
void generateKeys ( string s ) ;
/**
*DES加密函数 64位->64位
*函数说明: str1为64位的给定明文
*返回值为64位的密文
*/
string encrypt ( string str1 ) ;
/**
*解密函数
*str为密文
*输出明文
*/
string decrypt ( string str ) ;
} ;