分工已完成,今天可以开始Coding了,距离成功又近了一步。
具体说下S盒的原理:
S盒会将48位的输入重新变为32为,所以P是一个从32位到32位的置换,其具体置换规则如下图所示:
DES算法的核心部分就是S盒,其结构如下图所示:
48位的输入分为8组,每组6位输入到一个小S盒(S(i))中,每个S(i)将8位输入压缩变换为4位,8个S(i)的输出形成32位的S盒输出。
每个S(i)的变换方法为(此处考虑S(1)):设S(1)的输入为b1b2b3b4b5b6,用b1b6对应的10进制数作为行号,用b2b3b4b5对应的10进制数作为列号查找下表,得到的数对应的二进制就是S(1)的输出结果。
现将代码贴下,稚嫩的代码。
// Shorten.cpp : Defines the entry point for the console application.
//
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
using namespace std;
const int nSboxOutput = 32;
const int nBlocklength = 6;
char *arrnS1[][16] = {
{"1110","0100","1101","0001","0010","1111","1011","1000","0011","1010","0110","1100","0101","1001","0000","0111"},
};
char *arrnS2[][16] = {
{"1111","0001","1000","1110","0110","1011","0011","0100","1001","0111","0010","1101","1100","0000","0101","1010"},
};
char *arrnS3[][16] = {
{"1010","0000","1001","1110","0110","0011",