kgen.c

来自「3DES加解密C源码」· C语言 代码 · 共 51 行

C
51
字号
/* Crypto stream generator * Reads 16 bytes from stdin. The first 8 are the DES key, the second 8 * are the initialization vector. The IV is * fed to DES in the encrypt mode (no IP, IP-1). The ciphertext * is then written to stdout, most significant byte first. The IV * register is then incremented by one and the process is repeated, * ad infinitum. */#include <stdio.h>main(argc,argv)int argc;char *argv[];{	char ks[16][8];	/* Key schedule */	char iv[8];	/* Initial vector */	char out[8];	/* Output buffer */	int i,j;		desinit(1);	fread(iv,1,8,stdin);	setkey(ks,iv);	fread(iv,1,8,stdin);	while(1){		memcpy(out,iv,8);		endes(ks,out);		for(i=0;i<8;i++)			putc(out[i],stdout);		/* Increment register */		iv[7]++;		for(i=7;i != 0;i--){			if(iv[i] == 0)				iv[i-1]++;	/* Propagate carry */		}	}}inthtoi(c)char c;{	if(c >= '0' && c <= '9')		return c - '0';	if(c >= 'a' && c <= 'f')		return c - 'a' + 10;	if(c >= 'A' && c <= 'F')		return c - 'A' + 10;	return -1;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?