/********************************************************************** my_crypt.c ********************************************************************** my_crypt - Clone of the UNIX crypt (1) utility. Copyright ©2001, Stewart Adcock The latest version of this program should be available at: http://www.stewart-adcock.co.uk/ 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. Alternatively, if your project is incompatable with the GPL, I will probably agree to requests for permission to use the terms of any other license. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY WHATSOEVER. A full copy of the GNU General Public License should be in the file "COPYING" provided with this distribution; if not, see: http://www.gnu.org/ ********************************************************************** synopsis: Dodgy clone of the dodgy UNIX crypt utility. compilation: try typing something like this with the GNU compiler: gcc my_crypt.c -o crypt -lcrypt -Wall -O2 usage: crypt [-s] passkey < file > encrypted_file crypt [-s] passkey < encrypted_file > file Warning: This _IS_ _NOT_ designed to be cryptographically secure. It was solely written as a means to decrypt files which were encrypted using the legacy UNIX crypt utility. Last Updated: 28 May 2003 SAA Fixed a bug - thanks to Dr A J Bartlett for pointing this out. 11/06/01 SAA Clone of UNIX crypt utility. **********************************************************************/ #define _XOPEN_SOURCE /* For crypt() */ #define _ISO99_SOURCE /* For int32_t */ #include #include /* Comment out this line for MIPSpro compiler on IRIX, and possibly others. */ #include #include #define NUM_ROTORS 256 #define MASK 0377 char t1[NUM_ROTORS]; char t2[NUM_ROTORS]; char t3[NUM_ROTORS]; char deck[NUM_ROTORS]; char *init(char *key) { int ic, i, j, temp; unsigned int random; int32_t seed=123; char *password; password = (char *)crypt(key, key); for (i=0; i<13; i++) seed = seed*password[i] + i; for(i=0;i>= 8; temp = t1[ic]; t1[ic] = t1[j]; t1[j] = temp; if (t3[j]==0) { ic = (random&MASK) % j; while (t3[ic]!=0) ic = (ic+1) % j; t3[ic] = j; t3[j] = ic; } } for(i=0;i 1 && argv[1][0] == '-' && argv[1][1] == 's') { argc--; argv++; soption = 1; } password = init(argv[1]); if (soption) { while((i=getchar())>=0) { nr1 = deck[n1]&MASK; nr2 = deck[nr1]&MASK; i = t2[(t3[(t1[(i+nr1)&MASK]+nr2)&MASK]-nr2)&MASK]-nr1; putchar(i); n1++; if (n1==NUM_ROTORS) { n1 = 0; n2++; if(n2==NUM_ROTORS) n2 = 0; shuffle(deck, password); } } } else { while((i=getchar())>=0) { nr1 = n1; i = t2[(t3[(t1[(i+nr1)&MASK]+nr2)&MASK]-nr2)&MASK]-nr1; putchar(i); n1++; if (n1==NUM_ROTORS) { n1 = 0; n2++; if(n2==NUM_ROTORS) n2 = 0; nr2 = n2; } } } exit(0); }