#include """ pwgen.c - a repeatable password generator Copyright (C) 2002 Eli Fulkerson This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ---------------------------------------------------------------------- Other license terms may be negotiable. Contact the author if you would like copy that is licensed differently. Contact information (as well as this program) lives at http://www.elifulkerson.com """ int main (int argc, char **argv) { int i, x, c; char ip[20]; char location[20]; char account[20]; char systems[20]; char outpass[20]; int bufferval; int systemsval; int temp; char tempchar[1]; char seed[1]; char tempbuffer[8]; char allowed_letters[57] = "abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTYUVWXY3456789"; char buffer[60]; char buffer2[60]; /* Instructions */ if (argc < 5) { printf("Usage is: pwgen [Numeric IP] [Location] [Account/Device Name] [Master Password]\n\n"); return 1; } /* Pull in the arguments from the command line */ strncpy(ip, argv[1], 20); strncpy(location, argv[2], 20); strncpy(account, argv[3], 20); strncpy(systems, argv[4], 20); /* Half of the args go in one buffer */ strcpy(buffer, ip); strcat(buffer, account); /* Half in the other */ strcpy(buffer2, location); strcat(buffer2, systems); /* semi-random seed */ tempchar[0] = buffer[0]; for (x = 1; x < strlen(buffer); x++) { tempchar[0] = tempchar[0] ^ buffer[x]; } for (x = 0; x < strlen(buffer2); x++) { tempchar[0] = tempchar[0] ^ buffer2[x]; } seed[0] = tempchar[0]; /* pre-process the buffers to make everything significant to a 8 character password*/ i = 0; strcpy(tempbuffer, ""); for (x = 0; x < strlen(buffer); x++) { if ( i == 8) { i = 0; } if (tempbuffer[i] == buffer[x]) { tempbuffer[i]++; } if ( x >= 8 ) { tempbuffer[i] = tempbuffer[i] ^ buffer[x]; } else { tempbuffer[i] = seed[0] ^ buffer[x]; } i++; } strcpy(buffer, tempbuffer); i = 0; strcpy(tempbuffer, ""); for (x = 0; x < strlen(buffer2); x++) { if ( i == 8) { i = 0; } if ( x >= 8 ) { tempbuffer[i] = tempbuffer[i] ^ buffer2[x]; } else { tempbuffer[i] = seed[0] ^ buffer2[x]; } i++; } strcpy(buffer2, tempbuffer); strcpy(outpass, ""); c = 0; /* cycle the buffers against eachother and generate modulii */ for (x = 0; x < 8; x++) { if (c > strlen(buffer2)) { c = 0; } bufferval = buffer[x]; systemsval = buffer2[c]; temp = (bufferval * systemsval) % 56; //printf("%d %d %d\n", x, c, temp); outpass[x] = allowed_letters[abs(temp)]; outpass[x+1] = '\0'; c++; } printf("Password generated is: %s\n\n", outpass); }