Skip to content

Instantly share code, notes, and snippets.

@a11ce
Created May 10, 2024 19:52
Show Gist options
  • Save a11ce/d1490e24ba50425f3a4b9f61ac6ddff0 to your computer and use it in GitHub Desktop.
Save a11ce/d1490e24ba50425f3a4b9f61ac6ddff0 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// included bc i use clang, remove if gcc.
// taken from
// https://github.com/lattera/glibc/blob/master/string/memfrob.c
void *memfrob(void *s, size_t n) {
char *p = (char *)s;
while (n-- > 0)
*p++ ^= 42;
return s;
}
int main(int argc, char *argv[]) {
if (argc < 2) {
printf("USAGE: %s string-to-frob\n", argv[0]);
exit(27);
}
char *toFrob = argv[1];
memfrob(toFrob, strlen(toFrob));
printf("unsigned char frobbedString[%ld] = {", strlen(toFrob) + 1);
do {
printf("%d, ", *toFrob);
} while (*(++toFrob));
printf("42};\n"); // frobs to null
return 0;
}
// example:
// > ./frob meow
// unsigned char frobbedString[5] = {71, 79, 69, 93, 42};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment