-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCdcrypt.c
51 lines (44 loc) · 1.06 KB
/
Cdcrypt.c
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
#include "Version.h"
#if defined(MYDCRYPT_S)
#warning("using my dcrypt.S")
#elif !defined(MYDCRYPT_C)
#warning("using solution decrypt")
#else
#warning("using my Cdcrypt.c")
// version 1.1 05/08/2024
#include <stdio.h>
#include "cipher.h"
/*
* dcrypt:
* descrypts in inbuf with the bookbuf, reverse of encrypt
* Arguments:
* inbuf:
* pointer to the inbuf string to descrypt
* bookbuf:
* pointer to the bookbuf string to xor with
* cnt:
* number of bytes in both strings
* Returns:
* number of bytes descrypted
*/
// decrypts inbuf with bookbuf; updating inbuf
int
dcrypt(unsigned char *inbuf, unsigned char *bookbuf, int cnt)
{
if (cnt <= 0)
return 0;
// your code here
unsigned char reversed;
for (int index = 0; index < cnt; index++){
*inbuf = *inbuf ^ *bookbuf;
reversed = 0;
for (int i = 0; i < 8; i++){
reversed |= ((*inbuf >> i) & 1) << (7 - i);
}
*inbuf = reversed;
inbuf++;
bookbuf++;
}
return cnt;
}
#endif