You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
960 B
C
52 lines
960 B
C
#include <time.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#define _GNU_SOURCE
|
|
#include <string.h>
|
|
|
|
|
|
unsigned int MakeChecksum(unsigned char *buffer, int len)
|
|
{
|
|
unsigned int result;
|
|
|
|
result = 0;
|
|
for (int i = 0; i < len; i = i + 1) {
|
|
result = (result << 3 | result >> 0x1d) ^ buffer[i];
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
|
|
unsigned char *make_message(const unsigned char* s) {
|
|
int len = strlen(s);
|
|
unsigned char* message = (char*) calloc(1, len + 11);
|
|
|
|
message[8] = len + 7;
|
|
message[10] = len;
|
|
|
|
message[9] = 0x2A;
|
|
|
|
memcpy(message + 11, s, len);
|
|
|
|
*((unsigned int*)message + 1) = time(0LL);
|
|
|
|
*(unsigned int*) message = MakeChecksum(message + 4, len + 7);
|
|
|
|
return message;
|
|
}
|
|
|
|
int main() {
|
|
unsigned char message[] = "g1mm3_th3_k3y";
|
|
|
|
size_t len = strlen(message);
|
|
|
|
for (int i = 0; i < len; i++) {
|
|
message[i] ^= 42;
|
|
}
|
|
|
|
fwrite(make_message(message), 1, strlen(message) + 11, stdout);
|
|
|
|
return 0;
|
|
}
|