示例#1
0
void enigma_rev(ENIGMA ep,char *buf,int len)
{
int i;
char *p;
	if(!buf||len<=0) return;
	enigma_encrypt(ep,buf,len);
	b_revers(buf,len);
	len--;
	p=buf;
	for(i=0;i<len;i++) {
		p[1]^=*p; p++;
	}
}
示例#2
0
void enigma2_init(ENIGMA2 *ep,const char *bin_key,int len)
{
char rk[ROTORSZ];

	if(!ep||!bin_key) return;
	if(len<=0) len=strlen(bin_key);
	enigma_init(ep->t,bin_key,len);
	if(len>ROTORSZ) len=ROTORSZ;
	memcpy(rk,bin_key,len);
	b_revers(rk,len);
	enigma_encrypt(ep->t,rk,len);
	enigma_init(ep->r,rk,len);
	ep->crc=0X7FFFFFFF & ssh_crc32((unsigned char *)ep->t,sizeof(ep->t)<<1);
//ShowLog(5,"%s:crc=%d,len=%d",__FUNCTION__,ep->crc,len);
	return;
}
示例#3
0
static int pack_encode(char *string,int length,T_Connect *conn)
{
	switch(conn->CryptFlg & DO_CRYPT) {
	case 1:
		enigma(conn->t.t,string,length);
		break;
	case 2:
		enigma_encrypt(conn->t.r,string,length);
		break;
	case 3:
		enigma2_encrypt(&conn->t,string,length);
		break;
	default:
		break;
	}
	return 0;
}
示例#4
0
void main(){
    stdout = rs232_out;
    stdin = rs232_in;

    unsigned i;
    char key;

    rotor_l = &rotor_i[0];
    rotor_m = &rotor_ii[0];
    rotor_r = &rotor_iii[0];
    reflector = &reflector_b[0];
    ring_setting_l = 'A';
    ring_setting_m = 'A';
    ring_setting_r = 'A';
    l = 'A';
    m = 'A';
    r = 'A';
    initialise();

    puts("Enigma Machine\n");
    puts("==============\n\n");
    puts("1. Wheel settings (Walzenlage) (1->5) left, middle, right e.g. 123\n");
    puts("2. Reflector (a->c) e.g. b\n");
    puts("3. Ring settings (Ringstellung) (a->z) left, middle, right e.g. aaa\n");
    puts("4. Rotor positions (a->z) left, middle, right e.g. aaa\n");
    puts("ready ...\n");

    i=0;
    while(1){
        key = getc();
        if (isalpha(key)) {
            if(i==0){
              putc('A' + theenigma.l); 
              putc('A' + theenigma.m); 
              putc('A' + theenigma.r); 
              puts(": ");
            }
            putc(enigma_encrypt(&theenigma, toupper(key)));
            if(i==70) {
                i=0;
                putc('\n');
            } else {
                i++;
            }
        } else if (isdigit(key)) {
            if (key == '1') {
               puts("\n>\n");
               rotor_l = select_rotor();
               rotor_m = select_rotor();
               rotor_r = select_rotor();
               initialise();
               i=0;
            } else if (key == '2') {
               puts("\n>\n");
               reflector = select_reflector();
               initialise();
               i=0;
            } else if (key == '3') {
               puts("\n>\n");
               ring_setting_l = get_key();
               ring_setting_m = get_key();
               ring_setting_r = get_key();
               initialise();
               i=0;
            } else if (key == '4') {
               puts("\n>\n");
               l = get_key();
               m = get_key();
               r = get_key();
               initialise();
               i=0;
            }
        }
    }
}
示例#5
0
int main(int ac,char *av[])
{
char buf[131702];
int len,i,len1;
ENIGMA t;
ENIGMA2 egm;
struct timeval beg,end;

	enigma_init(t,"abcdefg",0);
	printf("t1:");
	for(i=0;i<256;i++) {
		if(!(i&7)) putchar('\n');
		printf("%3d:%02X\t",i,255&t[0][i]);
	}
	printf("\nt3:");
	for(i=0;i<256;i++) {
		if(!(i&7)) putchar('\n');
		printf("%3d:%02X\t",i,255&t[2][i]);
	}
	putchar('\n');

	enigma2_init(&egm,"abcdefg",0);
	printf("\ncrc=%d\n",egm.crc);
//	enigma2_init(&egm,"\x01\xff\x35\xf8\xef\x97\x22\x14\x80\x7f\t\b\r\n\377\177\225",17);
	memset(buf,'B',sizeof(buf));
	buf[sizeof(buf)-1]=0;
#ifndef TEST_SPEED
	while(!ferror(stdin)) {
		fgets(buf,sizeof(buf),stdin);
		if(feof(stdin)) break;
		TRIM(buf);
#endif
		len=strlen(buf);
		gettimeofday(&beg,0);
		enigma(t,buf,len);
		gettimeofday(&end,0);
		len1=len>32?32:len;
		printf("enigma encode    :");
		for(i=0;i<len1;i++) printf("%02X ",buf[i]&255);
		printf("\nenigma encode 64K:");
		for(i=0;i<len1;i++) printf("%02X ",buf[i+65536]&255);
		printf("\ntimeval=%ld\n",interval(&beg,&end));
		enigma(t,buf,len);
		printf("enigma decode:\n%.100s\n",buf);
//test frenz
		gettimeofday(&beg,0);
		enigma_encrypt(t,buf,len);
		gettimeofday(&end,0);
		printf("\nencrypt         :");
		for(i=0;i<len1;i++) printf("%02X ",buf[i]&255);
		printf("\nencrypt   64K:");
		for(i=0;i<len1;i++) printf("%02X ",buf[i+65536]&255);
		printf("\ntimeval=%ld\n",interval(&beg,&end));
		enigma_decrypt(t,buf,len);
		printf("decrypt    :\n%.100s\n",buf);
//test enigma2
		gettimeofday(&beg,0);
		enigma2_encrypt(&egm,buf,len);
		gettimeofday(&end,0);
		printf("enigma2 encode    :");
		for(i=0;i<len1;i++) printf("%02X ",buf[i]&255);
		printf("\nenigma2 encode 64K:");
		for(i=0;i<len1;i++) printf("%02X ",buf[i+65536]&255);
		printf("\ntimeval=%ld\n",interval(&beg,&end));
		enigma2_decrypt(&egm,buf,len);
		printf("enigma2 decode:\n%.100s\n",buf);
#ifndef TEST_SPEED
	}
#endif
	return 0;
}