Dans l’ordre:
1)Trame cryptée
2) PreSSE
3) RSA
4) Post SE 5) Signature
6) De-SE
日期:2023年7月2日
tables hash
/* tableau 9x T1 France */
static unsigned char T19x[256] = {
0x7F,0xEF,0xFD,0x2B,0x2D,0x58,0x38,0xA6,0xA8,0x55,0x2C,0xC4,0xBD,0xA7,0x6F,0x40,
0x60,0x1E,0x03,0xED,0xDB,0xF9,0x64,0xD8,0xB5,0xFF,0xBF,0x5C,0x75,0x94,0x3D,0x8E,0x76,0xE6,0x11,0x4A,0x69,0x4C,0xD0,0x0A,0x00,0x44,0xA3,0x14,0xE5,0x09,0x97
, 0xA2 0xBB 0x9B 0x5E 0x32 0xDF 0xC9 0x8F 0x86 0x90 0x6E 0xFA 0x68 0x0E 0xEE 0x47 0xAD 0x1F 0xB6 0xCC 0x20 0x29 0x74 0xA1 0xC0 0x71 0xFC 0x10 0x45
,0x65,0x4E,0xA5,0x2F,0x13,0x36,0xF7,0xE2,0xE7,0x83,0xC5,0xE4,0xAF,0x9D,0xEC,0x78,0x23,0x04,0x92,0x4B,0x34,0x7B,0xAE,0x7E,0xF8,0x84,0xF4,0x0C
, 0x77,0xCE,0x8C,0xD9,0xBE,0xD5,0xDE,0xCB,0x48,0xE8,0x6C,0xC7,0xBA,0x2E,0xFB,0xC2,0x35,0xD4,0x85,0x50,0x3E,0xD7,0x54,0x62
,
0xB8,0x82,0x22,0xF2,0x73,0x37,0x26,0xA4,0x5A,0x33,0x9C,0x30,0x5D,0x66,0x1B,0x08,0x12,0x07,0x01,0xB2,0xB4,0xE9,0x24,0x52,0x7A,0x0F,0xBC,0x43,0xD6,0xAC,0x89
, 0x15 0xEB 0x46 0xAA 0x99 0x1A 0x06 0x79 0x80 0x96 0x25 0x8B 0xC6 0xD2 0x98 0xC1 0xA0 0x42 0xFE 0x27 0x88 0xF6 0x4D 0x51 0x31 0x53 0xD1 0xB7
, 0x7C 0xA9 0x5F 0xC8 0xCD 0x3F 0x56 0xE3 0xE0 0x02 0xC3 0x05 0x59 0x4F 0x72 0xB1 0x3A 0xEA 0x6D 0x93 0x0D
,
0xDD,0x1C,0x41,0x61,0x81,0x91,0x6A,0x1D,0xB0,0x9A,0xD3,0xF1,0x5B,0xCA,0x70,0xDA,0x3B,0xB3,0x39,0x95,0x87,0x2A,0x3C,0x18,0xAB,0x28,0x63,0xF3,0xCF,0x57
, 0x67,0x49,0x8A,0x9E,0x0B,0xF0,0xF5,0x16,0x19,0x7D,0xE1,0x17,0xDC,0x21,0x9F,0x6B,0xB9,0x8D
};
/* tableau 9x T2 France */
static unsigned char T29x[256] = {
0x77,0x9F,0x52,0xF1,0x24,0xC1,0x87,0xB7,0xAE,0xFC,0xE6,0x82,0x62,0xBF,0xA0,0x9C,
0xCA,0xD7,0x8B,0x95,0x00,0x75,0x7B,0x39,0xAA,0x06,0x9B,0x92,0xF9,0x7D,0xBB,0x8A,0xB3,0x4A,0xDE,0x21,0x3D,0x86,0x5C,0x2D,0xA1,0x7E,0xD5,0xE0,0xCB,0xF4,0x90
, 0x58 0xB1 0x0F 0xB2 0xB4 0x89 0x30 0x79 0x34 0x0B 0xB0 0xE1 0xED 0xDA 0xCE 0x6D 0x12 0xD6 0xCD 0x6A 0xD3 0x1B 0xA3 0x68 0xA5 0xFD 0x85 0x64 0x1A
,0xC5,0x83,0x54,0x88,0xAC,0xBC,0xA7,0x70,0x4C,0x57,0x2C,0xEE,0x8F,0x49,0x0A,0xE3,0xEB,0x76,0xFF,0xC9,0x19,0x5B,0x7C,0x4F,0xBD,0x9E,0xDF,0xAF
, 0xD8,0xC3,0x5F,0x14,0xF5,0x38,0xB9,0x0C,0x9D,0x27,0x74,0xDD,0xFE,0x32,0xF6,0x63,0x2E,0x55,0xF3,0xDB,0xF2,0x78,0x45,0x5D
,
0x47,0x20,0x18,0x93,0x7A,0x2F,0x3E,0xE4,0x8E,0x46,0xD9,0x98,0xFA,0x13,0x60,0x36,0x84,0x51,0x6F,0x3A,0xAD,0xB5,0xC6,0x07,0x0D,0xA2,0x01,0xB8,0x40,0xEF,0xDC
, 0x11,0x4E,0xA6,0x56,0x1E,0xFB,0x10,0x72,0xB6,0x6C,0x1F,0x8D,0x65,0xF7,0x08,0xA4,0x2B,0x80,0x42,0x91,0x1C,0x35,0x53,0xF0,0xAB,0x9A,0x97,0xE8
, 0xA8,0x71,0x23,0xD1,0x03,0xCC,0x96,0x44,0x28,0xBE,0x33,0x29,0x4B,0x05,0xE2,0x3C,0x25,0x8C,0x48,0x2A,0x73
,
0x02,0x43,0x7F,0xA9,0x31,0xF8,0x04,0xEA,0x16,0xC0,0x5E,0x67,0x15,0xBA,0x50,0x94,0x4D,0xCF,0x3B,0xC2,0xD0,0x5A,0x61,0xE9,0x37,0xC8,0x09,0x6B,0xD2,0xE7
, 0x59 0x26 0x66 0x6E 0x41 0x81 0x99 0xE5 0x22 0x0E 0xC7 0xEC 0x17 0xD4 0x69 0x3F 0x1D 0xC4
};
file system c++
#include « filesystem.h »
#include < sstream>
#include <fstream>#include <vector>
#include <iostream>
Utilisation de l’espace de noms std ;
bool File_System::load_file(string file_location) {
fichier(file_location) ifstream; Charger le fichier
si(!file.good() || !file.is_open()) renvoie false; Si le fichier est introuvable ou n’a pas pu s’ouvrir
// Obtenir la taille du
fichier file.seekg(0, ios::end);
int length = file.tellg();
file.seekg(0, ios::beg);
if(length <= 0) renvoie false; Erreur lors du chargement du fichier
Charger le fichier dans data data.reserve
(length);
copie(istreambuf_iterator<char>(fichier), istreambuf_iterator<char>(), back_inserter(données));
reset();
return true;
}
bool File_System::save_file(string file_location, unsigned int max_size) {
if(data.size() > max_size) renvoie false; Juste au cas où il y aurait une erreur afin que nous n’enregistrions pas un fichier volumineux
Ouvrir le fichier
ofstream;
fichier.ouvre(file_location);
if(!file.is_open() || !file) renvoie false; Si le fichier ne s’ouvre pas
Enregistrer les données dans une chaîne de fichier
str = « »;
for(unsigned int i=0; i < data.size(); i++) str += données[i];
fichier << str;
fichier.close();
return true;
}
void File_System::reset() {
pointer = 0;
eof = faux;
ovr = faux;
}
bool File_System::read_bit() {
if(eof) return 0; Si la fin du fichier ne lit pas les octets indésirables
if(pointer+1 >= data.size()*8) eof = true; Définir la fin du fichier sur true si à la fin du fichier
Read bit
bool val = (data[(pointeur / 8)] >> (pointeur % 8)) & 0x01;
pointeur++;
retour val;
}
unsigned char File_System::read_nibble() {if(eof) return 0; Si la fin du fichier ne lit pas les octets indésirables
// Read each bit 1 by 1
unsigned char val = 0x0;
for(unsigned char i=0; i < 4; i++) {
if(read_bit()) { // If bit is set set bit in return byte
val |= (char)(1 << (3 – i));
}
}
return val;
}
unsigned char File_System::read_char() {
if(eof) return 0; // If end of file don’t read junk bytes
if(pointer % 8 == 0) { // Fast read, we can just read the byte if pointer is byte aligned
if(pointer+8 >= data.size()*8) eof = true;
unsigned char val = data[(pointer) / 8];
pointer += 8;
return val;
}
// Slow read, read each bit 1 by 1
unsigned char val = 0x00;
for(unsigned char i=0; i < 8; i++) {
if(read_bit()) { // If bit is set set bit in return byte
val |= (char)(1 << (7 – i));
}
}
return val;
}
unsigned short File_System::read_short() {
if(eof) return 0;
// Read 2 bytes and combine to short
return ((unsigned short)read_char() << 8) | (unsigned short)read_char();
}
string File_System::read_string(unsigned int bytes) {
string val = “”;
for(unsigned int i=0; i < bytes && !eof; i++) {
val += read_char();
}
return val;
}
string File_System::data_string() {
string str = “”;
for(unsigned int i=0; i < data.size(); i++) {
str += data[i];
}
return str;
}
void File_System::write_bit(bool val) {
unsigned int ind = pointer / 8;
unsigned char shift = pointer % 8;
if(ind >= data.size()) { // Add another byte to the end of the data if it’s at the data limit
data.push_back(0x00);
ovr = true; // And update this flag accordingly
}
if(inc) pointer++; // Increment pointer if inc flag is set
// Toggle bit if bit doesn’t equal value
if((bool)((data[ind] >> shift) & 0x01) != val) data[ind] ^= 0x01 << shift;
}
void File_System::write_nibble(unsigned char val) {
for(unsigned char i=0; i < 4; i++) { // We can just write 4 bits
write_bit(((val & (1 << i)) != 0));
}
}
void File_System::write_char(unsigned char val) {
if(pointer % 8 == 0) { // Fast write, we can just set the byte if pointer is byte aligned
if(pointer >= data.size()*8) { // Add the val to the end of the data if it’s at the data limit
data.push_back(val);
ovr = true; // And update this flag accordingly
} else {
data[pointer / 8] = val;
}
if(inc) pointer += 8;
return;
}
for(unsigned char i=0; i < 8; i++) { // We can just write 8 bits
write_bit(((val & (1 << i)) != 0));
}
}
void File_System::write_short(unsigned short val) {
write_char(val); // Just split the value into 2 bytes then write those
write_char(val >> 8);
}
void File_System::write_string(string val) {
for(unsigned int i=0; i < val.length(); i++) {
write_char(val[i]);
}
}
unsigned char File_System::pop() {
unsigned char val = data[data.size()-1];
data.pop_back();
return val;
}
unsigned char File_System::align() {
unsigned char dist = pointer % 8;
pointer -= dist;
return dist;
}
本文为原创文章,转载请注明出处!