#crypt.c
Language:
CWritten by
doug on 2008-01-31 23:07:24
#include <stdio.h>
#include <unistd.h>
int main(int argc, char * argv[]) {
char c = 0, salt[13], encode[201];
char * ptr = salt;
int i = 0, max = 2, cmax = 2;
if (argc > 1) {
if (strncmp(argv[1], "--md5", 5)==0) {
max = 11;
cmax = 8;
salt[0] = '$';
salt[1] = '1';
salt[2] = '$';
i = 3;
} else if (strncmp(argv[1], "--help", 6) == 0) {
puts("usage: crypt [OPTIONS]");
puts("\t--md5 crypt using MD5");
puts("");
return 1;
}
}
printf("Enter a %d character (max) salt: ", cmax); fflush(stdout);
c = getc(stdin);
while(!(c == '\n' || c == '\r') && (i < max)) {
salt[i] = c;
c = getc(stdin);
i++;
}
if (cmax == 8) {
salt[i] = '$';
i++;
}
salt[i] = 0;
printf("salt: '%s'\n", salt);
i = 0;
max = cmax = 200;
printf("Plaintext: "); fflush(stdout);
c = getc(stdin);
while(!(c == '\n' || c == '\r') && (i < max)) {
encode[i] = c;
c = getc(stdin);
i++;
}
encode[i] = 0;
printf("crypt()'d: %s\n", crypt(encode, salt));
}