Created
December 26, 2023 17:35
-
-
Save sharpicx/ca0889b1f5b2e6e81126f3c0445a1447 to your computer and use it in GitHub Desktop.
DevilGod - Hacktrace (Part 2)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ctype.h> | |
#include <stdint.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <ctype.h> | |
void *encrypt(char *str, int32_t key) { | |
uint32_t length = strlen(str); | |
void* result = malloc(length + 1); | |
char* ptr = (char*)result; | |
for (int i = 0; i < length; i++) { | |
char new_char; | |
if (str[i] >= 'A' && str[i] <= 'Z') { | |
new_char = ((str[i] - 'A' + key) % 26) + 'A'; | |
} else if (str[i] >= 'a' && str[i] <= 'z') { | |
new_char = ((str[i] - 'a' + key) % 26) + 'a'; | |
} else { | |
new_char = str[i]; | |
} | |
ptr[i] = new_char; | |
} | |
ptr[length] = '\0'; | |
return result; | |
} | |
void* decrypt(char* str, int32_t key) { | |
uint32_t length = strlen(str); | |
void* result = malloc(length + 1); | |
char* ptr = (char*)result; | |
for (int i = 0; i < length; i++) { | |
char new_char; | |
if (str[i] >= 'A' && str[i] <= 'Z') { | |
new_char = ((str[i] - 'A' - key + 26) % 26) + 'A'; | |
} else if (str[i] >= 'a' && str[i] <= 'z') { | |
new_char = ((str[i] - 'a' - key + 26) % 26) + 'a'; | |
} else { | |
new_char = str[i]; | |
} | |
ptr[i] = new_char; | |
} | |
ptr[length] = '\0'; | |
return result; | |
} | |
int32_t _Mod(int32_t dividend, int32_t divisor) | |
{ | |
int32_t quotient = dividend / divisor; | |
return dividend - (quotient * divisor); | |
} | |
void* _decrypt2(char* arg1, char* arg2) { | |
uint32_t len = strlen(arg2); | |
void* result = malloc(strlen(arg1) + 1); | |
int32_t var_14_1 = 0; | |
for (int32_t i = 0; arg1[i] != '\0'; i++) { | |
if (!isalpha(arg1[i])) { | |
*((char*)result + i) = arg1[i]; | |
var_14_1++; | |
} else { | |
int32_t is_upper = isupper(arg1[i]) != 0; | |
char base_char = is_upper ? 'A' : 'a'; | |
int32_t temp1_1 = (i - var_14_1) % len; | |
int32_t converted_char = is_upper ? toupper(arg2[temp1_1]) : tolower(arg2[temp1_1]); | |
*((char*)result + i) = base_char + _Mod(arg1[i] - base_char - (converted_char - base_char) + 26, 26); | |
} | |
} | |
*((char*)result + strlen(arg1)) = '\0'; | |
return result; | |
} | |
void* _encrypt2(char* arg1, char* arg2) { | |
uint32_t len = strlen(arg2); | |
void* result = malloc(strlen(arg1) + 1); | |
int32_t var_14_1 = 0; | |
for (int32_t i = 0; arg1[i] != '\0'; i++) { | |
if (!isalpha(arg1[i])) { | |
*((char*)result + i) = arg1[i]; | |
var_14_1++; | |
} else { | |
int32_t is_upper = isupper(arg1[i]) != 0; | |
char base_char = is_upper ? 'A' : 'a'; | |
int32_t temp1_1 = _Mod(arg1[i] - base_char + var_14_1, len); | |
int32_t converted_char = is_upper ? toupper(arg2[temp1_1]) : tolower(arg2[temp1_1]); | |
*((char*)result + i) = base_char + _Mod(converted_char - base_char, 26); | |
} | |
} | |
*((char*)result + strlen(arg1)) = '\0'; | |
return result; | |
} | |
int main() { | |
void *encrypted = decrypt(_decrypt2("ZnimoFwlkMhyyn", "REVOLT"), 5); | |
printf("%s", (char *)encrypted); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment