@@ -27,23 +27,27 @@ class Cape {
27
27
public:
28
28
unsigned char salt; // Salt used for encryption (exchange encrypted)
29
29
/* Instantiate Cape passing a key, its length (max 65535) and salt: */
30
- Cape (char *key, uint16_t length, uint8_t s = 0 ) {
30
+ Cape (unsigned char *key, uint16_t length, uint8_t s = 0 ) {
31
31
salt = s;
32
32
_key = key;
33
33
_key_length = length;
34
34
compute_reduced_key (key, length);
35
35
};
36
36
37
37
/* Compute a 1 byte version of the encryption key */
38
- void compute_reduced_key (char *key, uint16_t length) {
38
+ void compute_reduced_key (unsigned char *key, uint16_t length) {
39
39
_reduced_key = 0 ;
40
40
// Reduced key computation
41
41
for (uint16_t i = 0 ; i < length; i++)
42
42
_reduced_key ^= (key[i] << (i % 8 ));
43
43
};
44
44
45
45
/* Decrypt data: (max length 65535 characters) */
46
- void decrypt (char *source, char *destination, uint16_t length) {
46
+ void decrypt (
47
+ unsigned char *source,
48
+ unsigned char *destination,
49
+ uint16_t length
50
+ ) {
47
51
uint16_t index = length - 1 ;
48
52
// 1 Compute salty reduced key or srk
49
53
unsigned char srk = salt ^ _reduced_key;
@@ -57,8 +61,8 @@ class Cape {
57
61
/* Stream cipher, private key, initialization vector based encryption
58
62
algorithm (max length 65534 characters): */
59
63
void encrypt (
60
- char *source,
61
- char *destination,
64
+ unsigned char *source,
65
+ unsigned char *destination,
62
66
uint16_t length,
63
67
uint8_t iv
64
68
) {
@@ -73,7 +77,7 @@ class Cape {
73
77
74
78
/* Symmetric cipher using private key and salty reduced key:
75
79
(max 65535 characters) */
76
- void hash (char *source, char *destination, uint16_t length) {
80
+ void hash (unsigned char *source, unsigned char *destination, uint16_t length) {
77
81
// 1 Compute salty reduced key or srk
78
82
unsigned char srk = salt ^ _reduced_key;
79
83
// 2 Hash data
@@ -84,14 +88,14 @@ class Cape {
84
88
};
85
89
86
90
/* Set or Change encryption key (max 65534 characters): */
87
- void set_key (char *key, uint16_t length) {
91
+ void set_key (unsigned char *key, uint16_t length) {
88
92
_key = key;
89
93
_key_length = length;
90
94
compute_reduced_key (key, length);
91
95
};
92
96
93
97
private:
94
- char * _key; // Keep private and safe
98
+ unsigned char * _key; // Keep private and safe
95
99
uint16_t _key_length; // Keep private and safe
96
100
unsigned char _reduced_key; // Keep private and safe
97
101
};
0 commit comments