-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheaders.hpp
More file actions
90 lines (83 loc) · 2.31 KB
/
headers.hpp
File metadata and controls
90 lines (83 loc) · 2.31 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <bits/stdc++.h>
using namespace std;
class Byte
{
private:
unsigned char value;
public:
Byte();
Byte(string hex_val);
Byte(unsigned char val);
unsigned char getValue();
string getString();
Byte byteShift(int shift);
Byte byteROR(int bits, int shift);
Byte byteROL(int bits, int shift);
Byte operator|(const Byte &byte);
Byte operator&(const Byte &byte);
Byte operator^(const Byte &byte);
Byte operator+(const Byte &byte);
Byte operator*(const Byte &byte);
bool operator>(const Byte &byte);
bool operator>=(const Byte &byte);
bool operator==(const Byte &byte);
Byte& operator=(const Byte &byte);
Byte GFMult(Byte B, unsigned int modulus);
bool getBit(unsigned int pos);
void printBits();
friend ostream& operator<<(ostream &os, const Byte &byte);
};
class ByteStream
{
private:
vector<Byte> values;
unsigned int num_bytes;
public:
ByteStream();
ByteStream(vector<Byte> bs);
ByteStream(unsigned int bs);
ByteStream(string bs);
unsigned int getValue();
string getString();
ByteStream byteStreamShift(int shift);
ByteStream byteStreamROR(int shift);
ByteStream byteStreamROL(int shift);
ByteStream operator|(const ByteStream &bs);
ByteStream operator&(const ByteStream &bs);
ByteStream operator^(const ByteStream &bs);
ByteStream& operator=(const ByteStream &bs);
unsigned int getNumBytes();
vector<Byte> getValues();
ByteStream getBytes(unsigned int start, unsigned int end);
Byte getByte(unsigned int index);
void setBytes(unsigned int start, ByteStream bs);
bool getBit(unsigned int pos);
void printBits();
friend ostream& operator<<(ostream &os, const ByteStream &bs);
};
class TwoFish
{
private:
ByteStream M;
vector<ByteStream> K;
vector<ByteStream> S;
vector<vector<Byte>>RS;
vector<vector<Byte>>MDS;
Byte q(Byte x, vector<vector<Byte>>&T);
Byte q0(Byte x);
Byte q1(Byte x);
ByteStream h(ByteStream x, vector<ByteStream>L);
ByteStream g(ByteStream x);
ByteStream f(ByteStream R0, ByteStream R1, unsigned int r);
ByteStream round(ByteStream x, unsigned int r, char type);
ByteStream swap(ByteStream x);
void generateKeys();
public:
TwoFish(string KEY);
vector<ByteStream> getKeys();
ByteStream inputPreprocessing(string x);
ByteStream inputWhitening(ByteStream x);
ByteStream outputWhitening(ByteStream x);
ByteStream encrypt(string plaintext);
ByteStream decrypt(string ciphertext);
};