Rabu, 29 Juli 2009

SOURCE CODE NdSayF-2

kalo kemarin gw sempet posting tentang Algoritma NdSayF-2,, nah sekarang source codenya yang gw posting,,.
hmmpphh,,kalo pake turbo C biasa kayanya g bisa,,,coba dengan menggunakan MinGW developer studio ya,,pasti bisa kalo pake itu,,ok
semoga bisa bermanfaat^^


#include



unsigned char p[8],c[8],k[16],pl[4],pr[4],pla[4],plb[4],pra[4],prb[4],k1[4],k2[4],k3[4],k4[4],k5[4],k6[4],k7[4],k8[4],bc[64];

int i,a,b,x,tsb1,tsb2,tsb3,tsb4,tsb5,tsb6,tsb7,tsb8;

unsigned short int bink1[16],bink2[16],bink3[16],bink4[16],bink5[16],bink6[16],bink7[16],bink8[16],

plbin[16],prbin[16],prbin2[16],addbin[16];

long int prd,bink1d,bink2d,bink3d,bink4d,bink5d,bink6d,bink7d,bink8d,add;

short int sb1[16] = {14, 4, 13, 1, 2, 15, 11, 9, 5, 10, 6, 12, 3, 8, 0, 7 };

short int sb2[16] = {15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10 };

short int sb3[16] = {10, 0, 9, 6, 14, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8 };

short int sb4[16] = { 7, 13, 14, 3, 0, 6, 9, 10, 11, 2, 8, 5, 1, 12, 4, 15 };

short int sb5[16] = { 2, 12, 4, 11, 7, 10, 1, 6, 8, 5, 3, 15, 13, 0, 14, 9 };

short int sb6[16] = {12, 5, 10, 15, 9, 2, 6, 8, 0, 3, 13, 4, 14, 7, 1, 11 };

short int sb7[16] = { 4, 11, 2, 9, 15, 0, 8, 13, 3, 12, 14, 7, 5, 10, 6, 1 };

short int sb8[16] = {13, 2, 15, 0, 3, 8, 5, 1, 10, 9, 6, 14, 7, 4, 12, 11 };

int pc1[32]={31,23,15,7,30,22,14,6,29,21,13,5,28,20,12,4,27,19,11,3,26,18,10,2,25,17,9,1,24,16,8,0};



main()

{

printf("\n N d S a y F A l g o r i t h m ");

printf("\n\n");

printf("\n #********TUGAS DESAIN BLOCK CIPHER********# ");

printf("\n #************INDRA ADI PUTRA**************# ");



printf("\n #**********MUHAMMAD NUR FAJRI*************# ");

printf("\n #*************SAYEKTI BUDIANI*************# ");

printf("\n #*********TINGKAT II RANCANG BANGUN*******# ");

printf("\n #***********TINGKAT II MANAJEMEN**********# ");

printf("\n #****************JUNI 2009****************# ");



printf("\n\nMasukkan TEKS TERANG YAH (8 karakter) = ");

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

p[i]=getch();

printf("%c",p[i]);}

printf("\n * <-Berhenti ");

printf("\n powered by NdSayF ");

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

printf("\nMasukkan KUNCI nya juga (16 karakter) = ");

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

k[i]=getch();

printf("%c",k[i]);}

/* bagi 2 plaintext menjadi pl dan pr*/

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

pl[i]=p[i];

pr[i]=p[i+4];

}

a=0;b=0;

/* bagi 2 plaintext menjadi pl dan pr*/

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

pla[i]=pl[i];

plb[i]=pl[i+4];

pra[i]=pr[i];

prb[i]=pr[i+4];

}

a=0;b=0;

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

if(i!=0&&i%8==0){a+=1;b=0;}

plbin[i]=(pl[a]>>7-b)&1;

prbin[i]=(pr[a]>>7-b)&1;

b++;}



/* membagi 8 kunci */

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

k1[i]=k[i];

k2[i]=k[i+4];

k3[i]=k[i+8];

k4[i]=k[i+12];

k5[i]=k[i+16];

k6[i]=k[i+20];

k7[i]=k[i+24];

k8[i]=k[i+28];}



/* ubah jadi biner semua kunci */



a=0;b=0;

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

if(i!=0&&i%8==0){a+=1;b=0;}

bink1[i]=(k1[a]>>7-b)&1;

bink2[i]=(k2[a]>>7-b)&1;

bink3[i]=(k3[a]>>7-b)&1;

bink4[i]=(k4[a]>>7-b)&1;

bink5[i]=(k5[a]>>7-b)&1;

bink6[i]=(k6[a]>>7-b)&1;

bink7[i]=(k7[a]>>7-b)&1;

bink8[i]=(k8[a]>>7-b)&1;

b++;

}



/* mulai round */

x=1;

for(x=1;x<=32;x++){



/* pr (plain kanan) dan k1 dijadiin desimal ASCII lalu di-add */



prd=NULL;

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

prd=(prd)^(prbin[i]<<31-i);}



bink1d=bink2d=bink3d=bink4d=bink5d=bink6d=bink7d=bink8d=NULL;

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

bink1d=(bink1d)^(bink1[i]<<31-i);

bink3d=(bink3d)^(bink3[i]<<31-i);

bink5d=(bink5d)^(bink5[i]<<31-i);

bink7d=(bink7d)^(bink7[i]<<31-i);}

if(x==1|x==5|x==9|x==13|x==17|x==21|x==25|x==29)

add=(prd+bink1d)%2147483649;

if(x==2|x==6|x==10|x==14|x==18|x==22|x==26|x==30)

add=(prd+bink3d)%2147483649;

if(x==3|x==7|x==11|x==15|x==19|x==23|x==27|x==31)

add=(prd+bink5d)%2147483649;

if(x==4|x==8|x==12|x==16|x==20|x==24|x==28|x==32)

add=(prd+bink7d)%2147483649;



/* ubah hasil add jadi biner */

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

addbin[i]=(add>>31-i)&1;}



tsb1=(addbin[0]<<3)^(addbin[1]<<2)^(addbin[2]<<1)^addbin[3];

tsb2=(addbin[4]<<3)^(addbin[5]<<2)^(addbin[6]<<1)^addbin[7];

tsb3=(addbin[8]<<3)^(addbin[9]<<2)^(addbin[10]<<1)^addbin[11];

tsb4=(addbin[12]<<3)^(addbin[13]<<2)^(addbin[14]<<1)^addbin[15];

tsb5=(addbin[16]<<3)^(addbin[17]<<2)^(addbin[18]<<1)^addbin[19];

tsb6=(addbin[20]<<3)^(addbin[21]<<2)^(addbin[22]<<1)^addbin[23];

tsb7=(addbin[24]<<3)^(addbin[25]<<2)^(addbin[26]<<1)^addbin[27];

tsb8=(addbin[28]<<3)^(addbin[29]<<2)^(addbin[30]<<1)^addbin[31];



tsb1=sb1[tsb1];

tsb2=sb2[tsb2];

tsb3=sb3[tsb3];

tsb4=sb4[tsb4];

tsb5=sb5[tsb5];

tsb6=sb6[tsb6];

tsb7=sb7[tsb7];

tsb8=sb8[tsb8];



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

prbin2[i]=(tsb1>>3-i)&1;

prbin2[i+4]=(tsb2>>3-i)&1;

prbin2[i+8]=(tsb3>>3-i)&1;

prbin2[i+12]=(tsb4>>3-i)&1;

prbin2[i+16]=(tsb5>>3-i)&1;

prbin2[i+20]=(tsb6>>3-i)&1;

prbin2[i+24]=(tsb7>>3-i)&1;

prbin2[i+28]=(tsb8>>3-i)&1;}



/* permutasikan ke pc1 */

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

prbin2[i]=prbin2[pc1[i]];}



/* untuk cipher kiri,prd masih ASCII geser kekiri 4, jadiin biner lagi */

prd=(prd<<4 | prd>>(32-4));

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

prbin[i]=(prd>>31-i)&1;}



/* hasil 1 round cipher kiri dan kanan */

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

if(x==1|x==5|x==9|x==13|x==17|x==21|x==25|x==29)

plbin[i]=prbin[i]^bink2[i];

if(x==2|x==6|x==10|x==14|x==18|x==22|x==26|x==30)

plbin[i]=prbin[i]^bink4[i];

if(x==3|x==7|x==11|x==15|x==19|x==23|x==27|x==31)

plbin[i]=prbin[i]^bink6[i];

if(x==4|x==8|x==12|x==16|x==20|x==24|x==28|x==32)

plbin[i]=prbin[i]^bink8[i];

prbin[i]=prbin2[i]^plbin[i];

}



}



printf("\nbit kiri = ");

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

printf("%d",plbin[i]);}

printf("\nbit kanan = ");

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

printf("%d",prbin[i]);}





/* ubah jadi ASCII lagi */

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

bc[i]=plbin[i];

bc[i+32]=prbin[i];}



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

bc[i]=(bc[i*8]*128+bc[(i*8)+1]*64+bc[(i*8)+2]*32+bc[(i*8)+3]*16+bc[(i*8)+4]*8+bc[(i*8)+5]*4+bc[(i*8)+6]*2+bc[(i*8)+7]);



printf("\n\nTeks Sandinya adalah = ");

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

printf("%c",bc[i]);

printf("\n indraadi, M nur Fajri, Sayekti Budiani");



getch();

}

Tidak ada komentar:

Posting Komentar

terima kasi yah
madridista89

Daftar Blog Saya

Entri Populer