-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRC4.cpp
More file actions
37 lines (32 loc) · 804 Bytes
/
RC4.cpp
File metadata and controls
37 lines (32 loc) · 804 Bytes
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
#include "stdafx.h"
#include "RC4.h"
RC4::RC4() {
for ( int i = 0; i < 256; i++ )
m_table[i] = i;
btShift_1 = 0;
btShift_2 = 0;
}
// RC4 COM PEQUENAS MODIFCAÇÕES DO RC4 USUAL..
void RC4::KSA(std::vector<unsigned char>& key) {
byte Shift = 0;
for (int i = 0; i < 256; i++) {
byte A = key[i % 16];
Shift += (byte)(A + m_table[i]);
byte B = m_table[i];
m_table[i] = m_table[Shift];
m_table[Shift] = B;
}
}
void RC4::PRGA(std::vector<unsigned char>& message) {
for (size_t i = 0; i < message.size(); i++) {
btShift_1++;
byte A = m_table[btShift_1];
btShift_2 += A;
byte B = m_table[btShift_2];
m_table[btShift_2] = A;
m_table[btShift_1] = B;
byte C = (byte)(A + B);
byte D = m_table[C];
message[i] = (byte)(message[i] ^ D);
}
}