--- /dev/null
+#include <stdlib.h>
+#include <stdio.h>
+
+int main(int argc, char **argv) {
+ if (argc != 4) puts("bad invocation"), exit(1);
+ int p = atoi(argv[1]);
+ int a = atoi(argv[2]);
+ int b = atoi(argv[3]);
+
+ int candidate_b = 1;
+ for (int candidate_log = 0; candidate_log < p; candidate_log++) {
+ if (candidate_b == b) {
+ printf("solution: discrete log is %d\n", candidate_log);
+ exit(0);
+ }
+ candidate_b = (candidate_b * a) % p;
+ }
+
+ printf("no hits???\n");
+ return 1;
+}
--- /dev/null
+#include <stdlib.h>
+#include <stdio.h>
+
+int main(int argc, char **argv) {
+ if (argc != 3) puts("invocation: <p> <a>"), exit(1);
+ int p = atoi(argv[1]);
+ int a = atoi(argv[2]);
+
+ int n = a;
+ int order = 1;
+ while (n != 1) {
+ n = (((long long)n) * a) % p;
+ order++;
+ }
+
+ printf("Die Ordnung ist %d.%s\n", order, (order==p-1)?" Primitives Element":"");
+ return 0;
+}
--- /dev/null
+#include <jh.h>
+#include <math.h>
+
+int main(int argc, char **argv) {
+ if (argc != 2) xperror("invocation: round <target>", 0);
+ double target = strtod(argv[1], NULL);
+ char line[128];
+ while (fgets(line, sizeof(line), stdin)) {
+ double n = strtod(line, NULL);
+ double quot = n / target;
+ quot = round(quot);
+ n = quot * target;
+ printf("%f\n", n);
+ }
+ return 0;
+}
--- /dev/null
+#include <jh.h>
+#include <unistd.h>
+
+int main(int argc, char **argv) {
+ if (argc != 3) xperror("invocation: <host> <port>", 0);
+ int s = netopen(argv[1], argv[2], JH_TCP_HINTS);
+ if (s < 0) {
+ fprintf(stderr, "unable to connect: %s\n", gai_strerror(s));
+ exit(1);
+ }
+ while (1) {
+ char buf[4096];
+ fprintf(stderr, "reading...\n");
+ ssize_t count = fail_on_neg(read(0, buf, sizeof(buf)), "read failed", 1);
+ if (count == 0) return 0;
+ fprintf(stderr, "read %zd chars, writing...\n", count);
+ ssize_t wcount = fail_on_neg(write(s, buf, count), "write failed", 1);
+ if (wcount == 0) {
+ fprintf(stderr, "zero write! ending.\n");
+ return 1;
+ }
+ if (wcount != count) {
+ fprintf(stderr, "wrong write size! ending.\n");
+ return 1;
+ }
+ }
+}