請一C語言高手幫忙

2021-08-04 11:22:42 字數 5387 閱讀 2574

1樓:匿名使用者

#include "stdio.h"

typedef unsigned char u1byte;

typedef unsigned long u4byte;

#define large_table

u1byte pow_tab[256];

u1byte log_tab[256];

u1byte sbx_tab[256];

u1byte isb_tab[256];

u4byte rco_tab[10];

u4byte ft_tab[4][256];

u4byte it_tab[4][256];

#ifdef large_table

u4byte fl_tab[4][256];

u4byte il_tab[4][256];

#endif

u4byte tab_gen=0;

u4byte k_len;

u4byte e_key[60];

u4byte d_key[60];

#define ff_mult(a,b) (a && b ? pow_tab[(log_tab[a]+log_tab[b])%255]:0)

#define byte(x,n) ((u1byte)((x)>>(8*n)))

#define f_rn(bo,bi,n,k) \

bo[n]=ft_tab[0][byte(bi[n],0)]^ \

#define i_rn(bo,bi,n,k) \

bo[n]=it_tab[0][byte(bi[n],0)]^ \

#define rotr(x,n) (((x)>>((int)(n))) | ((x)<<(32-(int)(n))))

#define rotl(x,n) (((x)<<((int)(n))) | ((x)>>(32-(int)(n))))

#ifdef large_tables

#define ls_box(x) \

(fl_tab[0][byte(x,0)]^fl_tab[1][byte(x,1)]^ \

fl_tab[2][byte(x,2)]^fl_tab[3][byte(x,3)])

#define f_rl(bo,bi,n,k) \

bo[n]=fl_tab[0][byte(bi[n],0)]^ \

#define i_rn(bo,bi,n,k) \

bo[n]=il_tab[0][byte(bi[n],0)]^ \

#else

#define ls_box(x) \

((u4byte)sbx_tab[byte(x,0)]<<0)^((u4byte)sbx_tab[byte(x,1)]<<8)^ \

((u4byte)sbx_tab[byte(x,2)]<<16)^((u4byte)sbx_tab[byte(x,3)]<<24)

#define f_rl(bo,bi,n,k) \

bo[n]=(u4byte)sbx_tab[byte(bi[n],0)] ^ \

#define i_rl(bo,bi,n,k) \

bo[n]=(u4byte)isb_tab[byte(bi[n],0)] ^ \

#endif

void gen_tabs(void)

log_tab[1]=0; p=1;

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

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

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

tab_gen=1;

}#define star_x(x) (((x)& 0x7f7f7f7f)<<1)^((((x) & 0x80808080)>>7)*0x1b)

#define imix_col(y,x) \

u=star_x(x); v=star_x(u); w=star_x(v);\

t=w^(x); (y)=u^v^w; (y)^=rotr(u^t,8)^rotr(v^t,16)^rotr(t,24)

#define loop6(i) \

#define loop8(i) \

void set_key(const u4byte in_key, const u4byte key_len)

;break;

case 6: e_key[4]=in_key[4]; t=e_key[5]=in_key[5];

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

loop6(i);

break;

case 8: e_key[4]=in_key[4]; e_key[5]=in_key[5];

e_key[6]=in_key[6]; t=e_key[7]=in_key[7];

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

loop8(i);

break;

}d_key[0]=e_key[0]; d_key[1]=e_key[1];

d_key[2]=e_key[2]; d_key[3]=e_key[3];

for(i=4; i<4*k_len+24; ++i)

}#define f_nround(bo, bi, k) \

f_rn(bo, bi, 0, k); f_rn(bo, bi, 1, k); \

f_rn(bo, bi, 2, k); f_rn(bo, bi, 3, k); k+=4

#define f_lround(bo, bi, k) \

f_rl(bo, bi, 0, k); f_rl(bo, bi, 1, k); f_rl(bo, bi, 2, k); f_rl(bo, bi, 3, k)

void encrypt(const u4byte in_blk[4], u4byte out_blk[4])

if(k_len>4)

f_nround(b1, b0, kp);

f_nround(b0, b1, kp);

f_nround(b1, b0, kp); f_nround(b0, b1, kp);

f_nround(b1, b0, kp); f_nround(b0, b1, kp);

f_nround(b1, b0, kp); f_nround(b0, b1, kp);

f_nround(b1, b0, kp);

f_lround(b0, b1, kp);

out_blk[0]=b0[0]; out_blk[1]=b0[1];

out_blk[2]=b0[2]; out_blk[3]=b0[3];

}#define i_nround(bo, bi, k) \

i_rn(bo, bi, 0, k); i_rn(bo, bi, 1, k); \

i_rn(bo, bi, 2, k); i_rn(bo, bi, 3, k); k-=4

#define i_lround(bo, bi, k) \

i_rl(bo, bi, 0, k); i_rl(bo, bi, 1, k); i_rl(bo, bi, 2, k); i_rl(bo, bi, 3, k)

void decrypt(const u4byte in_blk[4], u4byte out_blk[4])

if(k_len>4)

i_nround(b1, b0, kp);

i_nround(b0, b1, kp);

i_nround(b1, b0, kp); i_nround(b0, b1, kp);

i_nround(b1, b0, kp); i_nround(b0, b1, kp);

i_nround(b1, b0, kp); i_nround(b0, b1, kp);

i_nround(b1, b0, kp);

i_lround(b0, b1, kp);

out_blk[0]=b0[0]; out_blk[1]=b0[1];

out_blk[2]=b0[2]; out_blk[3]=b0[3];

}void main()

; const u4byte plain_block[4]=;

printf("----------------------\n");

set_key(in_key, 128);

encrypt(plain_block, cipher_block);

printf("jiami =\n");

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

printf("%x ", cipher_block[i]);

decrypt(cipher_block, out_block);

printf("jiemi =\n");

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

printf("%x ", out_block[i]);

printf("end\n");}

c語言程式設計題,高手請幫忙,急,c語言程式設計題,高手請幫忙,急

直接用strcmp 就行了 排序演算法很多的,下面有幾個c 寫的字串排序函式。c裡面不能直接用 那些的比較字串,將大於 小於 符號換成strcmp 函式就行了。其實跟c差不多,因為沒有用類那些的複雜結構,稍微改改就是c了。include include include using namespace...

c語言程式,請高手幫忙看一下錯誤

include stdio.h include stdlib.h 巨集定義 define ok 1 define error 0 define overflow 2 define sksize 20 typedef struct sqstack 初始化棧 int initstack sqstack ...

一道c語言方面的問題,請各位高手幫忙解答一下

勉強著用吧,除錯已經通過.include include include include define max 100 void main char strcp max int n 0 int m printf input string scanf s str for int i 0 str i 0...