Files
hacklab/2/Basics3/test.c
2025-12-15 13:31:12 +01:00

54 lines
1.4 KiB
C

#include <stdint.h>
#include <stdio.h>
#include <sys/types.h>
char test[] = "hacklab{ ";
unsigned int start_key=2723;
//paste flag.enc here (add ", 0x")
char text[] = {0x2c, 0x1d, 0x5d, 0xb1, 0x67, 0x85, 0x0f, 0x52, 0x69, 0x93, 0x1c, 0x2d, 0x79, 0xf0, 0x4b, 0xc2, 0x64, 0xbd, 0x0f, 0xda, 0x95, 0x88, 0x16, 0x0c, 0x2f, 0x5e, 0x9e, 0x68, 0xee, 0xf4, 0x1e, 0xb6, 0xb8, 0xa7, 0x7d, 0x43, 0xa8, 0x00, 0x51, 0xc4, 0xfe, 0x54, 0x10, 0x26, 0xf1, 0xd3, 0x2b};
typedef uint8_t byte;
byte scramble_key(unsigned int *key_input){
*key_input = (*key_input * 0x41c64e6d + 0x3039) % 0x80000000;
return *(byte *)((long)key_input + 3) ^
(byte)*key_input ^ *(byte *)((long)key_input + 1) ^ *(byte *)((long)key_input + 2);
}
void encrypt(uint32_t key,char *text,ulong len)
{
byte bVar1;
uint32_t local_1c [4];
int i;
local_1c[0] = key;
for (i = 0; (ulong)(long)i < len; i = i + 1) {
bVar1 = scramble_key(local_1c);
text[i] = bVar1 ^ text[i];
text[i] = text[i] + 'O';
}
return;
}
void decrypt(uint32_t key,char *text,ulong len)
{
byte bVar1;
uint32_t local_1c [4];
int i;
local_1c[0] = key;
for (i = 0; (ulong)(long)i < len; i = i + 1) {
bVar1 = scramble_key(local_1c);
text[i] = text[i] - 'O';
text[i] = bVar1 ^ text[i];
}
return;
}
int main(int argc, char** args){
decrypt(start_key, text, sizeof(text));
for(uint8_t i=0; i<sizeof(text); i++)
printf("%c", text[i]);
}