Ремонт принтеров, сканнеров, факсов и остальной офисной техники


назад Оглавление вперед




[197]

data = (data << 8) key[j]; j = j + 1;

if (j >= keybytes) {

c->P[i] = c->P[i] л data; }

datal = 0x00000000; datar = 0x00000000;

for (i = 0; i < N + 2; i += 2) {

Blowfish encipher(c,&datal, &datar);

c->P[i] = datal;

c->P[i + 1]= datar;

for (i = 0; i < 4;{

for (j = 0;j < 256; j += 2) {

Blowfish encipher(c,&datal, &datar);

c->S[i][j] = datal; c->S[i][j + 1] = datar;

void blf key(blf ctx *c, char *k, int len){ InitializeBlowfish(c,k,len);

void blf enc(blf ctx *c, unsigned long *data, int blocks){ unsigned long *d; int i;

d = data;

for(i=0;i<blocks;i++){

Blowfish encipher(c,d,d+1); d += 2;

void blf dec(blf ctx *c, unsigned long *data, int blocks){ unsigned long *d; int i;

d = data;

for(i=0;i<blocks;i++){

Blowfish decipher(c,d,d+1); d += 2;

void main(void){

blf ctx c;

char key[]="AAAAA";

unsigned long data[10]; int i;


for(i=0;i<10;i++) data[i] = i;

blf key(&c,key,5); blf enc(&c,data,5); blf dec(&c,data,1); blf dec(&c,data+2,4);

for(i=0;i<10;i+=2) printf("Block %01d decrypts to: %08lx %08lx.\n",

i/2,data[i],data[i+1]);

#define STRT E 0x0b0b /* round constant of first encryption round */ #define STRT D 0xb1b1 /* round constant of first decryption round */ #defineNMBR11 /* number of rounds is 11*/

typedef unsigned long int word32 ;

/* the program only works correctly if long = 32bits */ typedef unsigned long u4; typedef unsigned char u1;

typedef struct {

u4 k[3],ki[3], ercon[NMBR+1],drcon[NMBR+1]; } twy ctx;

/* Note: encrypt and decrypt expect full blocks--padding blocks is callers responsibility. All bulk encryption is done in ECB mode by these calls. Other modes may be added easily enough.*/

/* destroy: Context. */

/* Scrub context of all sensitive data. */ void twy destroy(twy ctx *);

/* encrypt: Context, ptr to data block, # of blocks. */ void twy enc(twy ctx *, u4 *, int);

/* decrypt: Context, ptr to data block, # of blocks. */ void twy dec(twy ctx *, u4 *, int);

/* key: Context, ptr to key data. */ void twy key(twy ctx *, u4 *);

/* ACCODE----------------------------------------------------------- */

/* End of AC code prototypes and structures.*/

/* */

void mu(word32 *a)/* inverts the order of the bits of a */

int i ; word32 b[3] ;

b[0] = b[1] = b[2] = 0 ;

for( i=0 ; i<32 ; i++ ) {

b[0] <<= 1 ; b[1] <<= 1 ; b[2] <<= 1 ; if(a[0]&1) b[2] = 1 ; if(a[1]&1) b[1] = 1 ;


if(a[2]&1) b[0] = 1 ;

a[0] >>= 1 ; a[1] >>= 1 ; a[2] >>= 1 ;

a[0] = b[0] ; a[1] = b[1] ; a[2] = b[2] ; }

voidgamma(word32 *a) /* the nonlinear step */

word32b[3];

b[0]=a[0]л (a[1](~a[2])) ;

b[1]=a[1]л (a[2](~a[0])) ;

b[2]=a[2]л (a[0](~a[1])) ;

a[0]=b[0]; a[1] = b[1] ; a[2] = b[2] ; }

void theta(word32 *a) /* the linear step */

word32 b[3];

b[0] = a[0] л (a[0]>>16)л(a[1]<<16)л(a[1]>>16)л(a[2]<<16)л

(a[1]>>24)л(a[2]<<8)л(a[2]>>8)л(a[0]<<24)л

(a[2]>>16)л(a[0]<<16)л(a[2]>>24)л(a[0]<<8);

b[1] = a[1] л (a[1]>>16)л(a[2]<<16)л(a[2]>>16)л(a[0]<<16)л

(a[2]>>24)л(a[0]<<8)л(a[0]>>8)л(a[1]<<24)л

(a[0]>>16)л(a[1]<<16)л(a[0]>>24)л(a[1]<<8);

b[2] = a[2] л (a[2]>>16)л(a[0]<<16)л(a[0]>>16)л(a[1]<<16)л

(a[0]>>24)л(a[1]<<8)л(a[1]>>8)л(a[2]<<24)л

(a[1]>>16)л(a[2]<<16)л(a[1]>>24)л(a[2]<<8);

a[0] = b[0] ; a[1] = b[1] ; a[2] = b[2] ; }

void pi 1(word32 *a)

a[0] = (a[0]>>10) л (a[0]<<22); a[2] = (a[2]<<1) л (a[2]>>31);

void pi 2(word32 *a)

a[0] = (a[0]<<1) л (a[0]>>31); a[2] = (a[2]>>10) л (a[2]<<22);

void rho(word32 *a) /* the round function*/

theta(a) ; pi 1(a) ; gamma(a) ; pi 2(a) ;

void rndcon gen(word32 strt,word32 *rtab)

{/* generates the round constants */

int i ;

for(i=0 ; i<=NMBR ; i++ )



[стр.Начало] [стр.1] [стр.2] [стр.3] [стр.4] [стр.5] [стр.6] [стр.7] [стр.8] [стр.9] [стр.10] [стр.11] [стр.12] [стр.13] [стр.14] [стр.15] [стр.16] [стр.17] [стр.18] [стр.19] [стр.20] [стр.21] [стр.22] [стр.23] [стр.24] [стр.25] [стр.26] [стр.27] [стр.28] [стр.29] [стр.30] [стр.31] [стр.32] [стр.33] [стр.34] [стр.35] [стр.36] [стр.37] [стр.38] [стр.39] [стр.40] [стр.41] [стр.42] [стр.43] [стр.44] [стр.45] [стр.46] [стр.47] [стр.48] [стр.49] [стр.50] [стр.51] [стр.52] [стр.53] [стр.54] [стр.55] [стр.56] [стр.57] [стр.58] [стр.59] [стр.60] [стр.61] [стр.62] [стр.63] [стр.64] [стр.65] [стр.66] [стр.67] [стр.68] [стр.69] [стр.70] [стр.71] [стр.72] [стр.73] [стр.74] [стр.75] [стр.76] [стр.77] [стр.78] [стр.79] [стр.80] [стр.81] [стр.82] [стр.83] [стр.84] [стр.85] [стр.86] [стр.87] [стр.88] [стр.89] [стр.90] [стр.91] [стр.92] [стр.93] [стр.94] [стр.95] [стр.96] [стр.97] [стр.98] [стр.99] [стр.100] [стр.101] [стр.102] [стр.103] [стр.104] [стр.105] [стр.106] [стр.107] [стр.108] [стр.109] [стр.110] [стр.111] [стр.112] [стр.113] [стр.114] [стр.115] [стр.116] [стр.117] [стр.118] [стр.119] [стр.120] [стр.121] [стр.122] [стр.123] [стр.124] [стр.125] [стр.126] [стр.127] [стр.128] [стр.129] [стр.130] [стр.131] [стр.132] [стр.133] [стр.134] [стр.135] [стр.136] [стр.137] [стр.138] [стр.139] [стр.140] [стр.141] [стр.142] [стр.143] [стр.144] [стр.145] [стр.146] [стр.147] [стр.148] [стр.149] [стр.150] [стр.151] [стр.152] [стр.153] [стр.154] [стр.155] [стр.156] [стр.157] [стр.158] [стр.159] [стр.160] [стр.161] [стр.162] [стр.163] [стр.164] [стр.165] [стр.166] [стр.167] [стр.168] [стр.169] [стр.170] [стр.171] [стр.172] [стр.173] [стр.174] [стр.175] [стр.176] [стр.177] [стр.178] [стр.179] [стр.180] [стр.181] [стр.182] [стр.183] [стр.184] [стр.185] [стр.186] [стр.187] [стр.188] [стр.189] [стр.190] [стр.191] [стр.192] [стр.193] [стр.194] [стр.195] [стр.196] [стр.197] [стр.198] [стр.199] [стр.200] [стр.201] [стр.202] [стр.203]