diff options
author | Jakob Kaivo <jkk@ung.org> | 2019-07-19 13:16:11 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2019-07-19 13:16:11 -0400 |
commit | f45683191003e30a27afe4644e85a6c637f16809 (patch) | |
tree | 2b902c6a94bc03a411e91a51ebc28af1a76c42a0 |
initial commit
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | Makefile | 8 | ||||
-rw-r--r-- | leet.c | 54 |
3 files changed, 64 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f772093 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.o +leet diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c99e546 --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +.POSIX: + +CFLAGS=-Wall -Wextra -Werror -Wpedantic + +leet: leet.c + +clean: + rm -f *.o leet @@ -0,0 +1,54 @@ +#define _XOPEN_SOURCE 500 +#include <ctype.h> +#include <inttypes.h> +#include <limits.h> +#include <stdio.h> +#include <stdlib.h> +#include <time.h> +#include <unistd.h> + +#define COLOR(_n) (31 + (_n % 9)) + +#define BUFSIZE 16 + +void hexdump(uintmax_t address, size_t n, unsigned char buf[static n]) +{ + if (n > BUFSIZE) { + n = BUFSIZE; + } + + printf("\033[1m\r%015jx ", address); + for (size_t i = 0; i < n; i++) { + printf("\033[%hhdm%02hhx\033[0m ", COLOR(buf[i]), buf[i]); + usleep(100 * buf[i]); + } + for (size_t i = n; i < BUFSIZE; i++) { + printf("-- "); + } + + for (size_t i = 0; i < n; i++) { + printf("\033[%hhdm%c\033[0m", COLOR(buf[i]), isprint(buf[i]) ? buf[i] : '.'); + usleep(100 * buf[i]); + } + for (size_t i = n; i < 16; i++) { + printf("."); + } +} + +int main(void) +{ + setvbuf(stdout, NULL, _IONBF, 0); + + unsigned char buf[BUFSIZE]; + uintmax_t address = 0; + srand(time(NULL)); + + for (;;) { + for (size_t i = 0; i <= sizeof(buf); i++) { + buf[i] = rand(); + hexdump(address, i, buf); + } + printf("\n"); + address += sizeof(buf); + } +} |