-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncoderDecoder.h
More file actions
135 lines (120 loc) · 2.13 KB
/
EncoderDecoder.h
File metadata and controls
135 lines (120 loc) · 2.13 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#pragma once
char topleft[16][16];
char topright[16][16];
char bottomleft[16][16];
char bottomright[16][16];
void filltopleft()
{
char letter = 0;
for (int r = 0; r < 16; r++)
{
for (int c = 0; c < 16; c++)
{
topleft[r][c] = letter;
letter++;
}
}
}
void filltopright()
{
HANDLE fileIN;
int Bin;
fileIN = CreateFile("table1.txt",
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
for (int r = 0; r < 16; r++)
{
for (int c = 0; c < 16; c++)
{
ReadFile(fileIN, &(topright[r][c]), 1, &Bin, NULL);
}
}
}
void fillbottomleft()
{
HANDLE fileIN;
int Bin;
fileIN = CreateFile("table2.txt",
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
for (int r = 0; r < 16; r++)
{
for (int c = 0; c < 16; c++)
{
ReadFile(fileIN, &(bottomleft[r][c]), 1, &Bin, NULL);
}
}
}
void fillbottomright()
{
char letter = 0;
for (int r = 0; r < 16; r++)
{
for (int c = 0; c < 16; c++)
{
bottomright[r][c] = letter;
letter++;
}
}
}
void Encrypt(char data[2])
{
char first = data[0];
char second = data[1];
int TRow, TCol;
int BRow, BCol;
Sleep(1);
for (int r = 0; r < 16; r++)
{
for (int c = 0; c < 16; c++)
{
if (topleft[r][c] == first)
{
TRow = r;
TCol = c;
}
if (bottomright[r][c] == second)
{
BRow = r;
BCol = c;
}
}
}
data[0] = topright[TRow][BCol];
data[1] = bottomleft[BRow][TCol];
}
void Decrypt(char data[3])
{
Sleep(1);
char first = data[0];
char second = data[1];
int TRow, TCol;
int BRow, BCol;
for (int r = 0; r < 16; r++)
{
for (int c = 0; c < 16; c++)
{
if (topright[r][c] == first)
{
TRow = r;
TCol = c;
}
if (bottomleft[r][c] == second)
{
BRow = r;
BCol = c;
}
}
}
data[0] = topleft[TRow][BCol];
data[1] = bottomright[BRow][TCol];
}
InitializeEncoderDecoder()
{
filltopleft();
filltopright();
fillbottomleft();
fillbottomright();
}