1. ## Help About The ENIGMA Algoritm

#include "stdio.h"
#include "stdlib.h"

#define ROTORSIZ 256
#define EMPTY 07777
#define X_SIZE 4099

char *strrchr();

unsigned r1[ROTORSIZ];
unsigned r2[ROTORSIZ];
unsigned r3[ROTORSIZ];

unsigned char x[X_SIZE];

int decrypt;
{
register int index;
register int i;
int pipe_fd[2];
unsigned random;
long seed = 123L;
char buf[13];

buf[8] = buf[0];
buf[9] = buf[1];

pipe(pipe_fd);

if (fork() == 0)
{
close(0);
close(1);
dup(pipe_fd[0]);
dup(pipe_fd[1]);
execl("/usr/lib/makekey", "-", 0);
execl("/lib/makekey", "-", 0);
exit(1);
}

write(pipe_fd[1], buf, 10);
wait((int *) NULL);

if (read(pipe_fd[0], buf, 13) != 13)
{
fprintf(stderr, "crypt: cannot generate key\n");
exit(1);
}

for (i = 0 ; i < ROTORSIZ; i++) r1[i] = r2[i] = r3[i] = EMPTY;

for (i = 2; i < 13; i++) seed = seed * buf[i] + i;

i = 0;
while (i < ROTORSIZ)
{
seed = (long)(5L * seed + (long)i);
random = (unsigned)(seed % 65521L);
if (r1[index] == EMPTY)
r1[index] = i++;
else
continue;
}

i = 0;
while (i < ROTORSIZ)
{
seed = (long)(5L * seed + (long)i);
random = (unsigned)(seed % 65521L);
if (r2[index] == EMPTY)
r2[index] = i++;
else
continue;
}

i = 0;
while (i < ROTORSIZ)
{
seed = (long)(5L * seed + (long)i);
random = (unsigned)(seed % 65521L);
if (r3[index] == EMPTY)
r3[index] = i++;
else
continue;
}

for (i = 0; i < X_SIZE; i++)
{
seed = (long)(5L * seed + (long)i);
random = (unsigned)(seed % 65521L);
x[i] = random & 03;
}

if (decrypt)
{
invert(r1);
invert(r2);
invert(r3);
}
}

invert(r)
unsigned r[ROTORSIZ];
{
unsigned t[ROTORSIZ];
register int i;

for (i = 0; i < ROTORSIZ; i++) t[i] = r[i];
for (i = 0; i < ROTORSIZ; i++) r[t[i]] = i;
}

crypt()
{
register int ch;
register int i = 0;
register unsigned ofs1 = 0;
register unsigned ofs2 = 0;
register unsigned ofs3 = 0;

while ((ch = getchar()) != EOF)
{

switch (x[i]){
case 00:
break;
case 01:
break;
case 02:
break;
}

if (ofs1 == 0) ofs2 = ++ofs2 & MASK;
if (ofs2 == 0) ofs3 = ++ofs3 & MASK;

if (++i == X_SIZE) i = 0;
}
}

decrypt()
{
register int ch;
register int i = 0;
register unsigned ofs1 = 0;
register unsigned ofs2 = 0;
register unsigned ofs3 = 0;

while ((ch = getchar()) != EOF)
{

switch (x[i]){
case 00:
break;
case 01:
break;
case 02:
break;
}

if (ofs1 == 0) ofs2 = ++ofs2 & MASK;
if (ofs2 == 0) ofs3 = ++ofs3 & MASK;

if (++i == X_SIZE) i = 0;
}
}

main(argc, argv)
int argc;
char *argv[];
{
int flag;
char *p;

p = strrchr(argv[0], '/');

if (p == NULL) p = argv[0];
else ++p;

if (strcmp(p, "crypt") == 0) flag = 0;
else flag = 1;

if (argc != 2)
init(getpass("Enter key: "), flag);
else
init(argv[1], flag);

if (flag) decrypt();
else crypt();
}

I may be bugging the forum but I need seriosus help in using this code. I think it encrypts and decrypts the inputs. I tried to compile this but it gives me the linking errors and compiling warnings like this:

--------------------Configuration: enigma - Win32 Debug--------------------
Compiling...
enigma.c
c:\windows\profiles\johnny\desktop\enigma.c(28) : warning C4013: 'strncpy' undefined; assuming extern returning int
c:\windows\profiles\johnny\desktop\enigma.c(33) : warning C4013: 'pipe' undefined; assuming extern returning int
c:\windows\profiles\johnny\desktop\enigma.c(35) : warning C4013: 'fork' undefined; assuming extern returning int
c:\windows\profiles\johnny\desktop\enigma.c(37) : warning C4013: 'close' undefined; assuming extern returning int
c:\windows\profiles\johnny\desktop\enigma.c(39) : warning C4013: 'dup' undefined; assuming extern returning int
c:\windows\profiles\johnny\desktop\enigma.c(41) : warning C4013: 'execl' undefined; assuming extern returning int
c:\windows\profiles\johnny\desktop\enigma.c(46) : warning C4013: 'write' undefined; assuming extern returning int
c:\windows\profiles\johnny\desktop\enigma.c(47) : warning C4013: 'wait' undefined; assuming extern returning int
c:\windows\profiles\johnny\desktop\enigma.c(49) : warning C4013: 'read' undefined; assuming extern returning int
c:\windows\profiles\johnny\desktop\enigma.c(104) : warning C4013: 'invert' undefined; assuming extern returning int
c:\windows\profiles\johnny\desktop\enigma.c(194) : warning C4013: 'strcmp' undefined; assuming extern returning int
c:\windows\profiles\johnny\desktop\enigma.c(198) : warning C4013: 'getpass' undefined; assuming extern returning int
c:\windows\profiles\johnny\desktop\enigma.c(118) : warning C4716: 'invert' : must return a value
enigma.obj : error LNK2001: unresolved external symbol _wait
enigma.obj : error LNK2001: unresolved external symbol _fork
enigma.obj : error LNK2001: unresolved external symbol _pipe
enigma.obj : error LNK2001: unresolved external symbol _getpass
Debug/enigma.exe : fatal error LNK1120: 4 unresolved externals

enigma.exe - 5 error(s), 13 warning(s)

I'd be grateful if you helped. Thank you...

2. Where did you copy-pasted the code?
Some includes are missing, and there are some strange declarations, too.

Try to obtain the whole source.

There are many Enigma sites on the net, give it a try.

3. 1. This code was written before the dawn of time (it's pre-ANSI C)
2. It's written for unix, not dos/windows, so
2a. You don't have these programs - execl("/usr/lib/makekey", "-", 0);
2b. You don't have these functions - unresolved external symbol _wait
3. The #includes should be the <> form, not "" - which is perhaps understandable given its age

4. Yeah it is 1987... The year I was born in... However thank you I found a nicer algolithm and hopefully I'll be using that... Thank you again

5. The enterprising developer would learn what the missing functions are for, and write their own library or file with them... you can find the meaning for each of this undefined functions on the web.

Flowchart the code you have and figure out what it does. If you aren't willing to do this, then I suggest you give up the idea of being a developer. Developing is about solving problems. That's all you do, often with no help.

Good Luck.