From 357757279a9b9a9e0974a4c2258601784f1f6e54 Mon Sep 17 00:00:00 2001 From: pos3ym7vj <1226255226@qq.com> Date: Fri, 16 Dec 2022 11:03:24 +0800 Subject: [PATCH] ADD file via upload --- did_table.h | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 did_table.h diff --git a/did_table.h b/did_table.h new file mode 100644 index 0000000..c09d465 --- /dev/null +++ b/did_table.h @@ -0,0 +1,84 @@ +#ifndef DID_TABLE_H +#define DID_TABLE_H + +#include +#include +#include +#include +#include "const.h" +using namespace std; + +class DidTableSingleSbox { +private: + int index; + vector table[sbox_input_size][sbox_output_size]; + +public: + DidTableSingleSbox() = delete; + DidTableSingleSbox(const int& _index) :index(_index) { + // index: sbox index + for (int i = 0; i < sbox_input_size; i++) { + for (int j = 0; j < sbox_output_size; j++) { + table[i][j].clear(); + } + } + for (int x = 0; x < sbox_input_size; x++) { + for (int y = 0; y < sbox_input_size; y++) { + int in_d = x ^ y; + int out_d = calcSingleSbox(index, x) ^ calcSingleSbox(index, y); + table[in_d][out_d].push_back(x); + // table[in_d][out_d].push_back(y); + } + } + } + void get(int i, int j, vector& ret) { + ret.clear(); + for (unsigned int k = 0; k < table[i][j].size(); k++) { + ret.push_back(table[i][j][k]); + } + } + size_t getSize(int i, int j) { + return table[i][j].size(); + } +}; + +class DidTable { +private: + DidTableSingleSbox* box[sbox_index]; +public: + DidTable() { + for (int i = 0; i < 8; i++) { + box[i] = new DidTableSingleSbox(i); + } + } + ~DidTable() { + for (int i = 0; i < 8; i++) { + delete box[i]; + } + } + //void test(){ + // for (int i=0;i<8;i++){ + // printf("---- Box %d ----\n",i); + // for (int j=0;j<64;j++){ + // for (int k=0;k<16;k++){ + // printf("%d ", (int)box[i]->getSize(j,k)); + // } + // printf("\n"); + // } + // } + //} + //void test(int index){ + // printf("---- Box %d ----\n",index); + // for (int j=0;j<64;j++){ + // for (int k=0;k<16;k++){ + // printf("%d ", (int)box[index]->getSize(j,k)); + // } + // printf("\n"); + // } + //} + void get(int index, int i, int j, vector& ret) { + box[index]->get(i, j, ret); + } +}; + +#endif#pragma once