-
Notifications
You must be signed in to change notification settings - Fork 0
/
enc_dec.cpp
41 lines (32 loc) · 950 Bytes
/
enc_dec.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "main.hpp"
#include "support.hpp"
#include <iostream>
using namespace std;
// Шифрование
unsigned int* encryption(unsigned int* input, unsigned int** keys, int t, int c) {
unsigned int* output = new unsigned int[c * row];
mascpy(output, input, c * row);
add_rkey(output, keys[0], c);
for(int i = 1; i < t + 1; i++) {
s_block(output, c);
s_row(output, c);
m_col(output, c);
if(i != t) { xor_rkey(output, keys[i], c); }
else { add_rkey(output, keys[i], c); }
}
return output;
}
// Дешифрование
unsigned int* decryption(unsigned int* input, unsigned int** keys, int t, int c) {
unsigned int* output = new unsigned int[c * row];
mascpy(output, input, c * row);
for(int i = t; i > 0; i--) {
if(i == t) { sub_rkey(output, keys[i], c); }
else { xor_rkey(output, keys[i], c); }
_m_col(output, c);
_s_row(output, c);
_s_block(output, c);
}
sub_rkey(output, keys[0], c);
return output;
}