Created
May 10, 2024 19:52
-
-
Save a11ce/d1490e24ba50425f3a4b9f61ac6ddff0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <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