Skip to content

Instantly share code, notes, and snippets.

@iporsut
Created March 8, 2011 12:08
Show Gist options
  • Save iporsut/860200 to your computer and use it in GitHub Desktop.
Save iporsut/860200 to your computer and use it in GitHub Desktop.
cromartie key
#include <stdio.h>
#include <string.h>
#define mid(A,B,C) ((A >= B && A <= C) || (A >= C && A <= B)?A:(((B >= A && B <= C) || (B >= C && B <= A))?B:C))
int main(int argc, char *argv[])
{
char lock_up[80];
char lock_down[80];
char key[80];
int lock_max,key_max;
int i,j;
int mid_code;
fgets(lock_up,80,stdin);
lock_up[strlen(lock_up)-1] = '\0';
fgets(lock_down,80,stdin);
lock_down[strlen(lock_down)-1] = '\0';
fgets(key,80,stdin);
key[strlen(key)-1] = '\0';
lock_max = strlen(lock_up);
key_max = strlen(key);
for(i = -(key_max-1); i < lock_max; ++i) {
for(j = 0; j < key_max; ++j) {
if (((i+j) >= 0 && (i+j) < lock_max)) {
mid_code = mid(lock_down[i+j],lock_up[i+j],key[j]);
key[j] = mid_code;
}
}
}
printf("%s\n",key);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment