📄 desks.c
字号:
extern unsigned long bit[]; /* defined in DES */
typedef struct IMMENSE {unsigned long l,r;} immense;
typedef struct GREAT {unsigned short l,c,r;} great;
unsigned long getbit(source,bitno,nbits)
immense source;
int bitno,nbits;
{
if (bitno <= nbits)
return bit[bitno] & source.r ? 1L : 0L;
else
return bit[bitno-nbits] & source.l ? 1L : 0L;
}
void ks(key,n,kn)
immense key;
great *kn;
int n;
{
static immense icd;
static char ipc1[57]={0,57,49,41,33,25,17,9,1,58,50,
42,34,26,18,10,2,59,51,43,35,27,19,11,3,60,
52,44,36,63,55,47,39,31,23,15,7,62,54,46,38,
30,22,14,6,61,53,45,37,29,21,13,5,28,20,12,4};
static char ipc2[49]={0,14,17,11,24,1,5,3,28,15,6,21,
10,23,19,12,4,26,8,16,7,27,20,13,2,41,52,31,
37,47,55,30,40,51,45,33,48,44,49,39,56,34,
53,46,42,50,36,29,32};
int it,i,j,k,l;
if (n == 1) {
icd.r=icd.l=0L;
for(j=28,k=56;j>=1;j--,k--) {
icd.r = (icd.r <<= 1) | getbit(key,ipc1[j],32);
icd.l = (icd.l <<= 1) | getbit(key,ipc1[k],32);
}
}
if (n == 1 || n == 2 || n == 9 || n == 16) it=1;
else it=2;
for(i=1;i<=it;i++) {
icd.r = (icd.r | ((icd.r & 1L) << 28)) >> 1;
icd.l = (icd.l | ((icd.l & 1L) << 28)) >> 1;
}
(*kn).r=(*kn).c=(*kn).l=0;
for(j=16,k=32,l=48;j>=1;j--,k--,l--) {
(*kn).r=((*kn).r <<= 1) | (unsigned short)
getbit(icd,ipc2[j],28);
(*kn).c=((*kn).c <<= 1) | (unsigned short)
getbit(icd,ipc2[k],28);
(*kn).l=((*kn).l <<= 1) | (unsigned short)
getbit(icd,ipc2[l],28);
}
}
void cyfun(ir,k,iout)
unsigned long ir,*iout;
great k;
{
static char iet[49]={0,32,1,2,3,4,5,4,5,6,7,8,9,8,9,
10,11,12,13,12,13,14,15,16,17,16,17,18,19,
20,21,20,21,22,23,24,25,24,25,26,27,28,29,
28,29,30,31,32,1};
static char ipp[33]={0,16,7,20,21,29,12,28,17,1,15,
23,26,5,18,31,10,2,8,24,14,32,27,3,9,19,13,
30,6,22,11,4,25};
static char is[16][4][9]={
0,14,15,10,7,2,12,4,13,0,0,3,13,13,14,10,13,1,
0,4,0,13,10,4,9,1,7,0,15,13,1,3,11,4,6,2,
0,4,1,0,13,12,1,11,2,0,15,13,7,8,11,15,0,15,
0,1,14,6,6,2,14,4,11,0,12,8,10,15,8,3,11,1,
0,13,8,9,14,4,10,2,8,0,7,4,0,11,2,4,11,13,
0,14,7,4,9,1,15,11,4,0,8,10,13,0,12,2,13,14,
0,1,14,14,3,1,15,14,4,0,4,7,9,5,12,2,7,8,
0,8,11,9,0,11,5,13,1,0,2,1,0,6,7,12,8,7,
0,2,6,6,0,7,9,15,6,0,14,15,3,6,4,7,4,10,
0,13,10,8,12,10,2,12,9,0,4,3,6,10,1,9,1,4,
0,15,11,3,6,10,2,0,15,0,2,2,4,15,7,12,9,3,
0,6,4,15,11,13,8,3,12,0,9,15,9,1,14,5,4,10,
0,11,3,15,9,11,6,8,11,0,13,8,6,0,13,9,1,7,
0,2,13,3,7,7,12,7,14,0,1,4,8,13,2,15,10,8,
0,8,4,5,10,6,8,13,1,0,1,14,10,3,1,5,10,4,
0,11,1,0,13,8,3,14,2,0,7,2,7,8,13,10,7,13,
0,3,9,1,1,8,0,3,10,0,10,12,2,4,5,6,14,12,
0,15,5,11,15,15,7,10,0,0,5,11,4,9,6,11,9,15,
0,10,7,13,2,5,13,12,9,0,6,0,8,7,0,1,3,5,
0,12,8,1,1,9,0,15,6,0,11,6,15,4,15,14,5,12,
0,6,2,12,8,3,3,9,3,0,12,1,5,2,15,13,5,6,
0,9,12,2,3,12,4,6,10,0,3,7,14,5,0,1,0,9,
0,12,13,7,5,15,4,7,14,0,11,10,14,12,10,14,12,11,
0,7,6,12,14,5,10,8,13,0,14,12,3,11,9,7,15,0,
0,5,12,11,11,13,14,5,5,0,9,6,12,1,3,0,2,0,
0,3,9,5,5,6,1,0,15,0,10,0,11,12,10,6,14,3,
0,9,0,4,12,0,7,10,0,0,5,9,11,10,9,11,15,14,
0,10,3,10,2,3,13,5,3,0,0,5,5,7,4,0,2,5,
0,0,5,2,4,14,5,6,12,0,3,11,15,14,8,3,8,9,
0,5,2,14,8,0,11,9,5,0,6,14,2,2,5,8,3,6,
0,7,10,8,15,9,11,1,7,0,8,5,1,9,6,8,6,2,
0,0,15,7,4,14,6,2,8,0,13,9,12,14,3,13,12,11};
static char ibin[16]={0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15};
great ie;
unsigned long itmp,ietmp1,ietmp2;
char iec[9];
int jj,irow,icol,iss,j,l,m;
ie.r=ie.c=ie.l=0;
for(j=16,l=32,m=48;j>=1;j--,l--,m--) {
ie.r = (ie.r <<= 1) | (bit[iet[j]] & ir ? 1 : 0);
ie.c = (ie.c <<= 1) | (bit[iet[l]] & ir ? 1 : 0);
ie.l = (ie.l <<= 1) | (bit[iet[m]] & ir ? 1 : 0);
}
ie.r ^= k.r;
ie.c ^= k.c;
ie.l ^= k.l;
ietmp1=((unsigned long) ie.c << 16)+(unsigned long) ie.r;
ietmp2=((unsigned long) ie.l << 8)+((unsigned long) ie.c >> 8);
for(j=1,m=5;j<=4;j++,m++) {
iec[j]=ietmp1 & 0x3fL;
iec[m]=ietmp2 & 0x3fL;
ietmp1 >>= 6;
ietmp2 >>= 6;
}
itmp=0L;
for(jj=8;jj>=1;jj--) {
j=iec[jj];
irow=((j & 0x1) << 1)+((j & 0x20) >> 5);
icol=((j & 0x2) << 2)+(j & 0x4)
+((j & 0x8) >> 2)+((j & 0x10) >> 4);
iss=is[icol][irow][jj];
itmp = (itmp <<= 4) | ibin[iss];
}
*iout=0L;
for(j=32;j>=1;j--)
*iout = (*iout <<= 1) | (bit[ipp[j]] & itmp ? 1 : 0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -