-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
122 lines (104 loc) · 5.56 KB
/
main.cpp
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define SALT_SIZE 16
#define MAX_INPUT_SIZE 512
#define OUTPUT_SIZE 32
int getSalt(const char* salt) {
int a = strlen(salt);
for (int i = 0; i < a; i++) {
int b = (int)salt[i];
a += (b % 2 == 0) ? b : -b;
}
return (a < 0) ? -a : a % 10;
}
int main(int argc, char* argv[]) {
char salt[SALT_SIZE] = "";
char text[MAX_INPUT_SIZE] = "";
char* outputHash = (char*)malloc(OUTPUT_SIZE + 1);
if (outputHash == NULL) {
printf("Memory allocation failure\n");
return 1;
}
outputHash[0] = '\0'; // Initialize outputHash as an empty string
char newChar;
int saltInt;
// Banner
printf(" █████ █████ ██████████ █████ \n");
printf(" ░░███ ░░███ ░███░░░░░░█ ░░███ \n");
printf(" ░███ ░███ █ ████████ ██████ ░███ ░ ██████ ████████ █████ ████ ████████ ███████ \n");
printf(" ░███████████░░███░░███ ███░░███░█████████ ███░░███░░███░░███░░███ ░███ ░░███░░███░░░███░ \n");
printf(" ░░░░░░░███░█ ░███ ░░░ ░███████ ░░░░░░░░███ ░███ ░░░ ░███ ░░░ ░███ ░███ ░███ ░███ ░███ \n");
printf(" ░███░ ░███ ░███░░░ ███ ░███ ░███ ███ ░███ ░███ ░███ ░███ ░███ ░███ ███\n");
printf(" █████ █████ ░░██████ ░░████████ ░░██████ █████ ░░███████ ░███████ ░░█████ \n");
printf(" ░░░░░ ░░░░░ ░░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░ ░░░░░███ ░███░░░ ░░░░░ \n");
printf(" ███ ░███ ░███ \n");
printf(" 2024 4re5 group - https://4re5group.github.io ░░██████ █████ \n");
printf(" v1.01 ░░░░░░ ░░░░░ \n");
printf("\n");
// Check for input arguments
if (argc >= 2) {
if (strlen(argv[1]) >= MAX_INPUT_SIZE) {
printf("Input text length is way too big: expected between 1 to %d chars\n", MAX_INPUT_SIZE - 1);
free(outputHash);
return 1;
}
strcpy(text, argv[1]);
if (strlen(text) == 0) {
printf("Please enter a valid text to crypt\n");
free(outputHash);
return 1;
}
printf("-----------------------------------------------------------\n");
// If the salt argument is provided but empty, or if it's not provided, use `text` as the salt
if (argc >= 3 && strlen(argv[2]) > 0) {
if (strlen(argv[2]) >= SALT_SIZE) {
printf("Invalid salt length: expected between 1 to %d characters\n", SALT_SIZE - 1);
free(outputHash);
return 1;
}
strcpy(salt, argv[2]); // Copy provided salt
saltInt = getSalt(salt);
printf("Encrypting '%s' with salt '%s'...\n", text, salt);
} else {
saltInt = getSalt(text); // Use text as salt if salt is empty or not provided
printf("Encrypting '%s' without salt, using text as salt...\n", text);
}
printf(" saltInt => %d\n", saltInt);
printf("-----------------------------------------------------------\n");
char char1, char2;
bool running = true;
while (running) {
for (int i = 0; i < strlen(text) - 1; i += 2) {
char1 = text[i];
if (i + 1 < strlen(text)) {
char2 = text[i + 1];
}
int transformedChar = (i + strlen(outputHash) + (int)char1 + (int)char2) + saltInt;
// Ensure the transformed character is within ASCII 20 to 126
while (transformedChar > 126 || transformedChar <= 32) {
transformedChar -= 106;
}
newChar = (char)transformedChar;
// Append the new character to the outputHash
size_t len = strlen(outputHash);
if (len <= OUTPUT_SIZE - 1) {
outputHash[len] = newChar;
outputHash[len + 1] = '\0';
} else {
running = false;
break;
}
}
}
printf("done: here's your hash:\n%s\n", outputHash);
// Clean up
free(outputHash);
} else {
printf("usage: %s <text> [salt]\n", argv[0]);
free(outputHash);
return 1;
}
return 0;
}