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


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




[192]

short product = 0;/* result of multiplication */

while(b != 0) {/* while multiplier is

non-zero */

if (b & 01)

product a= a;/* add multiplicand if LSB

of b set */

a <<= 1;/* shift multiplicand one place */

if (a >= SIZE)

a a= gen;/* and modulo reduce if needed */

b >>= 1;/* shift multiplier one place */

return(product);

short exp8(base, exponent, gen)

short base;/* base of exponentiation*/

short exponent;/* exponent*/

short gen;/* irreducible polynomial generating Galois Field */

short accum = base;/* superincreasing sequence of base */

short result = 1;/* result of exponentiation*/

if (base == 0)/* if zero base specified then*/

return(0);/* the result is "0" if base = 0 */

while (exponent != 0) {/* repeat while exponent non-zero */

if (( exponent & 0x0001) == 0x0001)/* multiply if

exp 1 */

result = mult8(result, accum, gen); exponent >>= 1;/* shift exponent to next

digit */

accum = mult8(accum, accum, gen);/* & square */

return(result);

void loki key(loki ctx *c, unsigned char *key){ setlokikey(c,key);

void loki enc(loki ctx *c, unsigned char *data, int blocks){ unsigned char *cp; int i;

cp = data;

for(i=0;i<blocks;i++){ enloki(c,cp); cp+=8;

void loki dec(loki ctx *c, unsigned char *data, int blocks){ unsigned char *cp; int i;

cp = data;

for(i=0;i<blocks;i++){ deloki(c,cp); cp+=8;


void main(void){

loki ctx lc;

unsigned long data[10];

unsigned char *cp;

unsigned char key[] = {0,1,2,3,4,5,6,7}; int i;

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

loki key(&lc,key);

cp = (char *)data; loki enc(&lc,cp,5);

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

i/2,data[i],data[i+1]); loki dec(&lc,cp,1); loki dec(&lc,cp+8,4);

for(i=0;i<10;i+=2) printf("Block %01d = %08lx %08lx\n", i/2,data[i],data[i+1]);

typedef unsigned char boolean;/* values are TRUE or FALSE */

typedef unsigned char byte; /* values are 0-255 */

typedef byte *byteptr;/* pointer to byte */

typedef char *string;/* pointer to ASCII character string */

typedef unsigned short word16;/* values are 0-65535 */

typedef unsigned long word32;/* values are 0-4294967295 */

#ifndef TRUE #define FALSE 0

#define TRUE (!FALSE)

#endif /* if TRUE not already defined */

#ifndef min /* if min macro not already defined */ #define min(a,b) ( (a)<(b) ? (a) : (b) ) #define max(a,b) ( (a)>(b) ? (a) : (b) ) #endif /* if min macro not already defined */

#define IDEAKEYSIZE 16

#define IDEABLOCKSIZE 8 #define IDEAROUNDS 8

#define IDEAKEYLEN (6*IDEAROUNDS+4) typedef struct{

word16 ek[IDEAKEYLEN],dk[IDEAKEYLEN];

}idea ctx;

/* End includes for IDEA.C */

#ifdef IDEA32/* Use >16-bit temporaries */

#define low16(x) ((x) & 0xFFFF)

typedef unsigned int uint16;/* at LEAST 16 bits, maybe more */ #else

#define low16(x) (x) /* this is only ever applied to uint16s */ typedef word16 uint16;


#ifdef SMALL CACHE static uint16

mul(register uint16 a, register uint16 b)

register word32 p; p = (word32)a * b;

if (p) {

b = low16(p); a = p>>16;

return (b - a) + (b < a); } else if (a) {

return 1-b; } else {

return 1-a;

} /* mul */

#endif /* SMALL CACHE */

static uint16 mulInv(uint16 x)

uint16 t0, t1;

uint16 q, y;

if (x <= 1)

return x;/* 0 and 1 are self-inverse */

t1 = 0x10001L / x; /* Since x >= 2, this fits into 16 bits */

y = 0x10001L % x; if (y == 1)

return low16(1-t1);

t0 = 1; do {

q = x / y; x = x % y; t0 += q * t1;

if (x == 1)

return t0; q = y / x; y = y % x; t1 += q * t0;

} while (y != 1);

return low16(1-t1); } /* mukInv */

static void

ideaExpandKey(byte const *userkey, word16 *EK)

int i,j;

for (j=0; j<8;{

EK[j] = (userkey[0]<<8) + userkey[1]; userkey += 2;

for (i=0; j < IDEAKEYLEN;{

EK[i+7] = EK[i & 7] << 9 EK[i+1 & 7] >> 7; EK += i & 8;

i &= 7;



[стр.Начало] [стр.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]