-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecrypt.cpp
More file actions
48 lines (41 loc) · 1.2 KB
/
decrypt.cpp
File metadata and controls
48 lines (41 loc) · 1.2 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
#include <stdio.h>
#include <string.h>
void decryptFunc(unsigned char *cipherBytes, const char *key, int byteCount)
{
int keyLen = strlen(key);
for (int i = 0; i < byteCount; i++)
{
cipherBytes[i] ^= key[i % keyLen];
}
}
void receiverfuncMain()
{
char key[100];
unsigned char cipher[500];
int byteCount = 0;
char hexInput[2000];
printf("\n*----DISPLAY SECTION----*\n""\nENTER YOUR ALPHANUMERIC PASSWORD:\n-->");
fgets(key, sizeof(key), stdin);
key[strcspn(key, "\n")] = '\0';
printf("\nENTER YOUR HEX CIPHER TEXT [SPACE-SEPERATED |--> 09 07 0F 0F 0D <--|]:\n-->");
fgets(hexInput, sizeof(hexInput), stdin);
hexInput[strcspn(hexInput, "\n")] = '\0';
char *ptr = strtok(hexInput, " ");
while (ptr != NULL)
{
unsigned int value;
if (sscanf(ptr, "%x", &value) == 1)
{
cipher[byteCount++] = (unsigned char)value;
}
ptr = strtok(NULL, " ");
}
decryptFunc(cipher, key, byteCount);
printf("[DEBUG] PARSED CIPHER LENGTH --> %d bytes\n", byteCount);
printf("\nDECRYPTED MESSAGE --> ");
for (int i = 0; i < byteCount; i++)
{
printf("%c", cipher[i]);
}
printf("\n");
}