Enigma

  • Uploaded by: Joel
  • 0
  • 0
  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Enigma as PDF for free.

More details

  • Words: 384
  • Pages: 3
C:\Documents and Settings\Administrator\My Documents\DLS\enigma.c

/* * * * * * * * */

Monday, November 30, 2009 5:00 PM

"enigma.c" is in file cbw.tar from anonymous FTP host watmsg.waterloo.edu: pub/crypt/cbw.tar.Z A one-rotor machine designed along the lines of Enigma but considerably trivialized. A public-domain replacement for the UNIX "crypt" command.

#define ECHO 010 #include <stdio.h> #define ROTORSZ 256 #define MASK 0377 char t1[ROTORSZ]; char t2[ROTORSZ]; char t3[ROTORSZ]; char deck[ROTORSZ]; char *getpass(); char buf[13]; setup(pw) char *pw; { int ic, i, k, temp, pf[2]; unsigned random; long seed; strncpy(buf, pw, 8); while (*pw) *pw++ = '\0'; buf[8] = buf[0]; buf[9] = buf[1]; pipe(pf); if (fork()==0) { close(0); close(1); dup(pf[0]); dup(pf[1]); execl("/usr/lib/makekey", "-", 0); execl("/lib/makekey", "-", 0); exit(1); } write(pf[1], buf, 10); wait((int *)NULL); if (read(pf[0], buf, 13) != 13) { fprintf(stderr, "crypt: cannot generate key\n"); exit(1); } seed = 123; for (i=0; i<13; i++) seed = seed*buf[i] + i; for(i=0;i
C:\Documents and Settings\Administrator\My Documents\DLS\enigma.c

Monday, November 30, 2009 5:00 PM

t1[i] = i; deck[i] = i; } for(i=0;i>= 8; temp = t1[k]; t1[k] = t1[ic]; t1[ic] = temp; if(t3[k]!=0) continue; ic = (random&MASK) % k; while(t3[ic]!=0) ic = (ic+1) % k; t3[k] = ic; t3[ic] = k; } for(i=0;i 1 && argv[1][0] == '-' && argv[1][1] == 's') { argc--; argv++; secureflg = 1; } if (argc != 2){ setup(getpass("Enter key:")); } else setup(argv[1]); n1 = 0; n2 = 0; nr2 = 0; while((i=getchar()) >=0) { if (secureflg) { nr1 = deck[n1]&MASK; nr2 = deck[nr1]&MASK; } else { nr1 = n1; } i = t2[(t3[(t1[(i+nr1)&MASK]+nr2)&MASK]-nr2)&MASK]-nr1; putchar(i); n1++; if(n1==ROTORSZ) { -2-

C:\Documents and Settings\Administrator\My Documents\DLS\enigma.c

Monday, November 30, 2009 5:00 PM

n1 = 0; n2++; if(n2==ROTORSZ) n2 = 0; if (secureflg) { shuffle(deck); } else { nr2 = n2; } } } } shuffle(deck) char deck[]; { int i, ic, k, temp; unsigned random; static long seed = 123; for(i=0;i
-3-

Related Documents

Enigma
May 2020 23
Enigma
June 2020 28
Enigma
November 2019 25
Enigma Otiliei
May 2020 10
Enigma Arbres
June 2020 10
Enigma Otiliei.pdf
June 2020 23

More Documents from "Adina Gojnea"

June 2020 3
Spring Class Grid 2009
December 2019 22
June 2020 11
Dfi.docx
May 2020 12
Btinstall.txt
June 2020 14