From a98d134e89a42909721dcefd426118af38628048 Mon Sep 17 00:00:00 2001 From: EliteTK Date: Thu, 24 Apr 2014 09:06:24 +0100 Subject: Latest random crap. --- foursquare.c | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 foursquare.c (limited to 'foursquare.c') diff --git a/foursquare.c b/foursquare.c new file mode 100644 index 0000000..9552ed4 --- /dev/null +++ b/foursquare.c @@ -0,0 +1,121 @@ +// foursquare.c +#include +#include +#include +#include + +#define Q ('Q'-'A') + +typedef struct vec2 { + int x; + int y; +} Vec2; + +int increinc(int *); +void allupper(char *); +void genkey(char *, char *); +Vec2 *newVec2(const int, const int); + +int main(int argc, char **argv) +{ + int x, y, c=0; + + if(argc!=4){ + printf("Usage: %s ", *argv); + exit(1); + } + + printf("%s, %s ", *(argv+1), *(argv+2)); + + char *trkey = *(argv+1); + allupper(trkey); + char *trfullkey = malloc(26); + genkey(trkey, trfullkey); + + char *blkey = *(argv+2); + allupper(blkey); + char *blfullkey = malloc(26); + genkey(blkey, blfullkey); + + char *cipher = *(argv+3); + allupper(cipher); + + int i=0; + Vec2 *trtable[25]; + for(x=0; x<5; x++) + for(y=0; y<5; y++) + trtable[trfullkey[i++]-'A'] = newVec2(x, y); + free(trfullkey); + + i = 0; + Vec2 *bltable[25]; + for(x=0; x<5; x++) + for(y=0; y<5; y++) + bltable[blfullkey[i++]-'A'] = newVec2(x, y); + free(blfullkey); + + char basetable[5][5]; + for(x=0; x<5; x++) + for(y=0; y<5; y++){ + if(c==Q) + c++; + basetable[x][y] = 'A' + c++; + } + + for(i=0; ix][bltable[c2-'A']->y]); + putchar(basetable[bltable[c2-'A']->x][trtable[c1-'A']->y]); + } + putchar('\n'); + + for(i=0; i++; i<25){ + free(trtable[i]); + free(bltable[i]); + } + + return 0; +} + +int increinc(int *num) +{ + (*num)++; + return (*num)++; +} + +void allupper(char *input) +{ + int i; + for(i=0; ix = x; + v->y = y; + return v; +} -- cgit v1.2.3-54-g00ecf