Sisyboy’s Weblog

Just another WordPress.com weblog

PROGRAM HILLS

#include<stdio.h>
#include<string.h>

main(){
int i,j,k,l,p, m, pilih, a,c, b,d, s1,s2,y1,y2;
char temp, sistem;
char z[40],key[40],hasil[40], A, B;
char huruf[26]={‘A’,’B’,’C’,’D’,’E’,’F’,’G’,’H’,’I’,’J’,’K’,’L’,’M’,
‘N’,’O’,’P’,’Q’,’R’,’S’,’T’,’U’,’V’,’W’,’X’,’Y’,’Z’};

clrscr();

printf(” ==========================================================\n”);
printf(” = PROGRAM HILSS =\n”);
printf(” = =\n”);
printf(” = Neo Fajar Bawana Konta Dewa Danu =\n”);
printf(” = TEKNIK PERSANDIAN =\n”);
printf(” = =\n”);
printf(” ==========================================================\n”);
printf(“\n”);
sleep(2);
clrscr();
printf(” ___________________________________________________________\n”);
printf(“| |\n”);
printf(“| SELAMAT DATANG DI PROGRAM PENYANDIAN HILSS |\n”);
printf(“| 1. ENCRYPTION |\n”);
printf(“| 2. DECRYPTION |\n”);
printf(“| 3. EXIT |\n”);
printf(“|__________________________________________________________|\n”);
printf(“\n”);
printf(” masukkan menu pilihan anda:”);
scanf(“%d”,&pilih);
switch(pilih);
{
case1:
clrscr();
printf(” ====Selamat Datang di Program Digraf Encryption====\n “);
sleep(2);
printf(“\n”);
printf(“A.Sistem KS\n”);
printf(“B.Sistem KCTR\n”);
printf(“Pilih Sistem Sandi Yang Akan digunakan:\n”);
scanf(“%c”, &sistem);
switch(sistem);
{
case’A’:
printf(“ENTER KEY WORD (UPPER CASE LETTER) : “);
scanf(“%s”,key);
l = strlen(key);

for(i=0;i<l;i++)
for(j=i+1;j<l;j++){
if(key[i] == key[j]){
key[j]=’ ‘;
if(j+1<l){
m=j;
for(k=m+1;k<l;k++){
key[m]=key[k];
m++;
}
j–;
}
l-=1;
}
}

for(i=0;i<26;i++)
for(j=0;j<l;j++){
if(huruf[i]==key[j])
huruf[i]=’ ‘;
}

p = l;
for(i=0;i<26;i++){
if(huruf[i]!=’ ‘){
key[p]=huruf[i];
p++;
}
}
clrscr();
printf(“\n\n”);
printf(“HASIL PROSES KS: \n”);
printf(“\n”);

for(i=0;i<26;i++){
printf(“%c”,key[i]);
}

sleep(1);
printf(“\n\n”);
printf(“untuk persamaan y1\n”);
sleep(1);
printf(“masukkan nilai koefisien x1:”);
scanf(“%d”,&a);
printf(“\n”);
printf(“masukkan nilai koefisien x2:”);
scanf(“%d”,&b);
printf(“\n”);
printf(“masukkan nilai konstanta1:”);
scanf(“%d”,&s1);
printf(“\n”);
printf(“untuk persamaan y2”);
sleep(1);
printf(“\n”);
printf(“masukkan nilai koefisien x1:”);
scanf(“%d”,&c);
printf(“\n”);
printf(“masukkan nilai koefisien x2:”);
scanf(“%d”,&d);
printf(“\n”);
printf(“masukkan nilai konstanta2:”);
scanf(“%d”,&s2);
printf(“\n”);

for(i=0,j=i+1;i,j<26;i++,j++)
{
key[i]=key[i+1];
y1=(i*a+j*b+s1)%26;
y2=(i*c+j*d+s2)%26;
printf(“%c%c “, key[y1],key[y2]);}
break;

case’B’:
printf(“copy cepet”);
break;
}

case2:
printf(“maaf saya belum mengerti jadi maaf”);
break;
case3:
break;
}
getch();

}

May 6, 2008 Posted by | Pemrograman Neo | Leave a comment

PROSES LOOPING

PENGULANGAN DENGAN FOR

LOOP FOR

Loop adalah pengulangan perintah-perintah sampai mencapai keadaan tertentu. Turbo C mempunyai 3 jenis loop, yaitu :

  • for

  • while

  • do – while

Bentuk umum Loop For :

for (inisialisasi; syarat; penambahan) pernyataan;

Keterangan :

  • Inisialisasi adalah pernyataan untuk menyatakan keadaan awal dari variabel kontrol.

  • Syarat adalah ekspresi relasional yang menyatakan berhentinya pengulangan.

  • Penambahan menyatakan perubahan variabel kontrol setiap terjadi pengulangan. Setiap bagian harus dipisahkan oleh tanda titik koma.

Contoh :

main()

{

int i;

clrscr();

for (i=1; i <=5 ; i++) printf(“%d \n”,i);

getch();

}

Pada program tersebut :

Inisialisasi : i = 1

Syarat : i <= 5

Penambahan : i++ , artinya ditambah 1

Hasil :

1

2

3

4

5

OPERATOR PENAMBAH DAN PENGURANG

C mempunyai dua operator khusus yaitu penambah (++) dan pengurang (–), contoh :

i ++ sama dengan i = i + 1

i — sama dengan i = i – 1

Operator penambah dan pengurang dapat dituliskan di depan atau dibelakang, tetapi mempunyai arti yang berbeda. Jika operator diletakkan di depan, C akan melakukan penambahan atau pengurangan sebelum memakai nilai operator. Jika diletakkan di belakang, C akan memakai nilai operator lalu menambah atau mengurangi variabel.

Contoh :

x = 10 x = 10

y = ++x y = x++

hasil : 11 hasil : 10

Contoh :

main()

{

int i;

clrscr();

for (i=5; i > 0 ; i–) printf(“%d \n”,i);

getch();

}

Contoh :

#include <math.h>

main()

{

int i, kuadrat, jumlah;

float akar;

char garis[35] = “——————————-“;

clrscr();

printf(“Tabel Kuadrat dan Akar Kuadrat \n”);

printf(“%s\n”,garis);

printf(“Bilangan Kuadrat Akar Kuadrat\n”);

printf(“%s\n”,garis);

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

{

kuadrat = i * i;

akar = sqrt(i);

printf(” %2d %3d %6.4f \n”,i,kuadrat,akar);

}

printf(“%s\n”,garis);

getch();

}

VARIASI LOOP – FOR

Kita dapat memakai beberapa variabel kontrol di dalam loop for,

contoh :

main()

{

int x,y;

clrscr();

for (x=0,y=0; x+y<=20; x++,++y) printf(“%d\n”,x+y);

getch();

}

Program di atas mencetak bilangan 0 sampai 20. Perhatikan pernyataan for di atas.

Inisialisasi : x=0, y=0

Syarat : x+y <= 20

Penambahan : x++, y++

Tanda koma dipakai untuk memisahkan dua pernyataan di dalam sebuah bilangan. Misalnya di bagian inisialisasi ada pernyataan x=0 dan y=0. Tanda koma berarti lakukan ini dan ini.

MENGHILANGKAN SEBUAH BAGIAN LOOP

Variasi lain adalah dengan menghilangkan salah satu bagian dari loop,

contoh :

main()

{

char ch;

clrscr();

printf(“Ketikkan karakter-karakter (z = stop) : \n”);

for (ch=’ ‘; ch!=’z’; ) ch=getche();

}

Pada program di atas, Anda diminta untuk mengetikkan karakter-karakter dan program akan berhenti jika Anda mengetikkan huruf ‘z’.

LOOP TAK HINGGA

Loop tak hingga dibuat dengan menghilangkan bagian syaratnya,

contoh :

main()

{

char ch;

clrscr();

printf(“Ketikkan karakter-karakter : \n”);

for (ch=’ ‘; ; ) ch=getche();

}

Program tersebut meminta Anda mengetikkan sebuah huruf dan tidak akan berhenti. Untuk menghentikannya tekan tombol CTRL + BREAK

LOOP TANPA PERNYATAAN

Loop tanpa pernyataan dipakai untuk menunggu. Semakin banyak pengulangan, semakin lama menunggu.,

contoh :

main()

{

int t,x;

clrscr();

printf(“Berapa kali loop Anda akan menunggu : \n”); scanf(“%d”,&x);

for (t=0 ; t<x ; t++ ) ;

}

LOOP BERSARANG

Perhatikan contoh program berikut :

main()

{

int i,j;

clrscr();

for (i=1 ; i <= 3 ; i++)

{

for (j=1 ; j <= 5 ; j++ ) printf(“*”);

printf(” \n”);

}

getch();

}

Dari contoh tersebut dapat kita simpulkan bahwa variabel i menyatakan baris dan variabel j menyatakan kolom.

PENGULANGAN DENGAN WHILE DAN DO-WHILE

LOOP WHILE

Bentuk umum :

while (syarat) pernyataan;

Pernyataan pada loop while dapat berupa sebuah pernyataan atau blok pernyataan atau pernyataan kosong. Pernyataan akan diulang selama syarat benar,

contoh :

main()

{

int i;

clrscr();

i=1;

while (i <= 5)

{

printf(“STI&K\n”);

i=i+1;

}

getch();

}

Loop while menyatakan bahwa pengulangan akan dilakukan terus selama syarat terpenuhi.

LOOP DO WHILE

Loop for dan while akan mengecek syarat pengulangan pada awal loop. Loop do-while mngecek syaratnya pada akhir pengulangan. Loop do-while akan selalu dikerjakan minimal sekali. Loop do-while menyatakan bahwa pengulangan akan dilakukan selama syarat terpenuhi.

Bentuk umum :

do

{

statemen;

statemen;

} while (syarat)

Bentuk umum untuk loop do-while adalah pada rutin pemilihan menu, sebab menu selalu dikerjakan minimal sekali,

contoh :

main()

{

int no_menu;

do

{

clrscr();

printf(“\n Menu Hari Ini “);

printf(“\n ——————“);

printf(“\n 1. Nasi Goreng “);

printf(“\n 2. Nasi Soto Ayam “);

printf(“\n 3. Gado-Gado “);

printf(“\n 4. Bubur Ayam “);

printf(“\n\n Masukkan pilihan Anda…! (0 = Selesai) “);

scanf(“%d”,&no_menu);

switch (no_menu)

{

case 1 :

printf(“\n Nasi Goreng Rp. 5000,-“);

break;

case 2 :

printf(“\n Nasi Soto Ayam Rp. 6000,-“);

break;

case 3 :

printf(“\n Gado-Gado Rp. 4000,-“);

break;

case 4 :

printf(“\n Bubur Ayam Rp. 3500,-“);

break;

case 0 :

printf(“\n Selesai.. Terima kasih..!”);

break;

default :

printf(“\n\n Pilihan Anda Salah…!”);

}

getch();

}while (no_menu != 0);

}

May 6, 2008 Posted by | Pemrograman Neo | Leave a comment

TUGAS STRUKTUR DATA “RC4”

#include<stdio.h>
#include<conio.h>
#include<ctype.h>
#include<string.h>
#include<alloc.h>
#include<dos.h>

#define ENTER ‘\r’

int xbox_pertama[256];
int xbox_kedua[256];
int initialkey[11];
unsigned char plaintext[7], ciphertext[7], kosong, key;
int a,b,c,d,i;

void sbox_pertama(void)
{
for(i=0;i<=255;i++)
xbox_pertama[i]=i;
}

void sbox_kedua(void)
{

printf(” Masukkan initial Key Anda : “);
gets(initialkey);

b=strlen(initialkey);
for(i=0;i<=255;i++)
{
xbox_kedua[i]=initialkey[i%b];
}
}

void kunci(void)
{
char OLD[7];
FILE *pf1;

printf(“\n\n Nama File untuk menyimpan xbox_pertama : “);
gets(OLD);

pf1=fopen(OLD,”a+”);

b=0;
for(a=0;a<=255;a++)
{
b=(b+xbox_pertama[a]+xbox_kedua[a])%256;
kosong=xbox_pertama[a];
xbox_pertama[a]=xbox_pertama[b];
xbox_pertama[b]=kosong;
}

for(a=0;a<=255;a++)
{
putc(xbox_pertama[a],pf1);
putc(‘ ‘,pf1);
}

for(a=0;a<256;a++)
{
printf(“%4d”,xbox_pertama[a]);
if((a+1)%16==0) {printf(“\n”);}
}

fclose(pf1);

}

void process(void)
{
a=0;
b=0;

printf(“\n\n Masukkan plaintext : “);
gets(“plaintext”);

for(c=0;c<6;c++)
{
a=(a+1)%256;
b=(b+xbox_pertama[a])%256;
kosong=xbox_pertama[a];
xbox_pertama[a]=xbox_pertama[b];
xbox_pertama[b]=kosong;
d=(xbox_pertama[a]+xbox_pertama[b])%256;
key=xbox_pertama[d];
ciphertext[c]=plaintext[c]^key;
printf(“\n %c -> %c”,plaintext[c],ciphertext[c]);
}

printf(“\n\n ciphertext : “);
for(a=0;a<6;a++)
{
printf(“%c “,ciphertext [a]);
}

}

main()
{
int x,y,i,j,k,pilops;
char c,kar,password[10],p[9]=”linklist”;

clrscr();

puts(“”);
puts(” *************************************”);
puts(” * *”);
puts(” * PROGRAM OPERASI PADA LINK LIST *”);
puts(” * TUGAS MATA KULIAH STRUKTUR DATA *”);
puts(” * OLEH : NEO *”);
puts(” * *”);
puts(” *************************************”);
printf(“\n\n”);

c=’\xFE’;
awal:
printf(” LOGIN :\n\n”);
printf(” MASUKKAN PASSWORD : “);
for(i=0;i<10;i++)
{
password[i]=getch();
putchar(‘*’);
if(password[i]==ENTER)
{password[i]=”; break;}
}

if(strcmp(p,password)==0) {printf(“\n\n\n LOADING\n\n “);
printf(” “);
for(i=0;i<3;i++)
{
sleep(1);
printf(“%c”,c);
}
clrscr();
printf(“\n\n”);
goto proses;
}

else {printf(“\n\n Password Anda Salah!!!\n”);
printf(“\n Ulangi LOGIN ? ( Y / T) “); kar=getche();
if(kar==’Y’||kar==’y’) {printf(“\n\n\n”); goto awal;}
if(kar==’T’||kar==’t’) goto selesai;
}

proses:
sbox_pertama();
sbox_kedua();
kunci();
process();

printf(“\n Ulangi Operasi LINK LIST ? ( Y / T) “); kar=getche();

if(kar==’Y’||kar==’y’) {printf(“\n\n\n”); goto proses;}
else goto selesai;

selesai:
getch();
}

May 5, 2008 Posted by | Pemrograman Neo | Leave a comment

DEKRIPSI AES

#include<stdio.h>
#define Nb 4

int Nr=0;
int Nk=0;

unsigned char in[16], out[16], state[4][4];
unsigned char RoundKey[240];
unsigned char Key[32];

int getSBoxInvert(int num)
{
int rsbox[256] =
{ 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb
, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb
, 0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e
, 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25
, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16, 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92
, 0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84
, 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06
, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02, 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b
, 0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73
, 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e
, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89, 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b
, 0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4
, 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f
, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d, 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef
, 0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61
, 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d };

return rsbox[num];
}

int getSBoxValue(int num)
{
int sbox[256] = {

0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16 };
return sbox[num];
}

int Rcon[255] = {
0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a,
0x2f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, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04,
0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63,
0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb };

void KeyExpansion()
{
int i,j;
unsigned char temp[4],k;

for(i=0;i<Nk;i++)
{
RoundKey[i*4]=Key[i*4];
RoundKey[i*4+1]=Key[i*4+1];
RoundKey[i*4+2]=Key[i*4+2];
RoundKey[i*4+3]=Key[i*4+3];
}

while (i < (Nb * (Nr+1)))
{
for(j=0;j<4;j++)
{
temp[j]=RoundKey[(i-1) * 4 + j];
}
if (i % Nk == 0)
{

{
k = temp[0];
temp[0] = temp[1];
temp[1] = temp[2];
temp[2] = temp[3];
temp[3] = k;
}

{
temp[0]=getSBoxValue(temp[0]);
temp[1]=getSBoxValue(temp[1]);
temp[2]=getSBoxValue(temp[2]);
temp[3]=getSBoxValue(temp[3]);
}

temp[0] = temp[0] ^ Rcon[i/Nk];
}
else if (Nk > 6 && i % Nk == 4)
{

{
temp[0]=getSBoxValue(temp[0]);
temp[1]=getSBoxValue(temp[1]);
temp[2]=getSBoxValue(temp[2]);
temp[3]=getSBoxValue(temp[3]);
}
}
RoundKey[i*4+0] = RoundKey[(i-Nk)*4+0] ^ temp[0];
RoundKey[i*4+1] = RoundKey[(i-Nk)*4+1] ^ temp[1];
RoundKey[i*4+2] = RoundKey[(i-Nk)*4+2] ^ temp[2];
RoundKey[i*4+3] = RoundKey[(i-Nk)*4+3] ^ temp[3];
i++;
}
}

void AddRoundKey(int round)
{
int i,j;
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
state[j][i] ^= RoundKey[round * Nb * 4 + i * Nb + j];
}
}
}

void InvSubBytes()
{
int i,j;
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
state[i][j] = getSBoxInvert(state[i][j]);

}
}
}

void InvShiftRows()
{
unsigned char temp;

temp=state[1][3];
state[1][3]=state[1][2];
state[1][2]=state[1][1];
state[1][1]=state[1][0];
state[1][0]=temp;

temp=state[2][0];
state[2][0]=state[2][2];
state[2][2]=temp;

temp=state[2][1];
state[2][1]=state[2][3];
state[2][3]=temp;

temp=state[3][0];
state[3][0]=state[3][1];
state[3][1]=state[3][2];
state[3][2]=state[3][3];
state[3][3]=temp;
}

#define xtime(x) ((x<<1) ^ (((x>>7) & 1) * 0x1b))
#define Multiply(x,y) (((y & 1) * x) ^ ((y>>1 & 1) * xtime(x)) ^ ((y>>2 & 1) * xtime(xtime(x))) ^ ((y>>3 & 1) * xtime(xtime(xtime(x)))) ^ ((y>>4 & 1) * xtime(xtime(xtime(xtime(x))))))

void InvMixColumns()
{
int i;
unsigned char a,b,c,d;
for(i=0;i<4;i++)
{

a = state[0][i];
b = state[1][i];
c = state[2][i];
d = state[3][i];

state[0][i] = Multiply(a, 0x0e) ^ Multiply(b, 0x0b) ^ Multiply(c, 0x0d) ^ Multiply(d, 0x09);
state[1][i] = Multiply(a, 0x09) ^ Multiply(b, 0x0e) ^ Multiply(c, 0x0b) ^ Multiply(d, 0x0d);
state[2][i] = Multiply(a, 0x0d) ^ Multiply(b, 0x09) ^ Multiply(c, 0x0e) ^ Multiply(d, 0x0b);
state[3][i] = Multiply(a, 0x0b) ^ Multiply(b, 0x0d) ^ Multiply(c, 0x09) ^ Multiply(d, 0x0e);
}
}

void InvCipher()
{
int i,j,round=0;

for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
state[j][i] = in[i*4 + j];
}
}

AddRoundKey(Nr);

for(round=Nr-1;round>0;round–)
{
InvShiftRows();
InvSubBytes();
AddRoundKey(round);
InvMixColumns();
}

InvShiftRows();
InvSubBytes();
AddRoundKey(0);

for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
out[i*4+j]=state[j][i];
}
}
}
void main()
{
int i;
unsigned char temp[32] = {0x00 ,0x01 ,0x02 ,0x03 ,0x04 ,0x05 ,0x06 ,0x07 ,0x08 ,0x09 ,0x0a ,0x0b ,0x0c ,0x0d ,0x0e ,0x0f};
unsigned char temp2[16]= {0x69 ,0xc4 ,0xe0 ,0xd8 ,0x6a ,0x7b ,0x04 ,0x30 ,0xd8 ,0xcd ,0xb7 ,0x80 ,0x70 ,0xb4 ,0xc5 ,0x5a};
printf(“********************************************************************************\n\n”);
printf(” WELCOME\n”);
printf(” ANDA TELAH MEMASUKI PROGRAM ADVANCE ENCRYPTION STANDARD\n”);
printf(” PROGRAM DEKRIPSI\n”);
printf(” KARYA : NEO FAJAR BAWANA KONTA DEWA DANU\n\n”);
printf(“********************************************************************************\n\n”);

while(Nr!=128 && Nr!=192 && Nr!=256)
{
printf(“Masukan Panjang Kunci (128, 192 or 256 only): “);
scanf(“%d”,&Nr);
}
Nk = Nr / 32;
Nr = Nk + 6;

for(i=0;i<Nk*4;i++)
{
Key[i]=temp[i];
in[i]=temp2[i];
}

flushall();

printf(“Masukan Kunci dalam Heksadesimal: “);
for(i=0;i<Nk*4;i++)
{
scanf(“%x”,&Key[i]);
}

printf(“Masukan Ciphertext dalam Heksadesimal: “);
for(i=0;i<Nb*4;i++)
{
scanf(“%x”,&in[i]);
}

KeyExpansion();
InvCipher();
printf(“\nTeks Dekripsi:\n”);
for(i=0;i<Nb*4;i++)
{
printf(“%02x “,out[i]);
}
printf(“\n\n”);
getch();
}

NOTE :

Program ini masih memiliki banyak kekurangan,,

Mohon jika memasuki Blog ini untuk memberikan komentar dan mengoreksi program ini…thx!!

May 5, 2008 Posted by | Pemrograman Neo | Leave a comment

ENKRIPSI AES

#include<stdio.h>
#define Nb 4

int Nr=0;
int Nk=0;

unsigned char in[16], out[16], state[4][4];
unsigned char RoundKey[240];
unsigned char Key[32];

int getSBoxValue(int num)
{
int sbox[256] = {

0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
0xe7, 0xc8, 0x37, 0x6d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x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b,
0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3,
0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20,
0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35,
0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04,
0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63,
0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb };

void KeyExpansion()
{
int i,j;
unsigned char temp[4],k;

for(i=0;i<Nk;i++)
{
RoundKey[i*4]=Key[i*4];
RoundKey[i*4+1]=Key[i*4+1];
RoundKey[i*4+2]=Key[i*4+2];
RoundKey[i*4+3]=Key[i*4+3];
}

while (i < (Nb * (Nr+1)))
{
for(j=0;j<4;j++)
{
temp[j]=RoundKey[(i-1) * 4 + j];
}
if (i % Nk == 0)
{
{
k = temp[0];
temp[0] = temp[1];
temp[1] = temp[2];
temp[2] = temp[3];
temp[3] = k;
}

{
temp[0]=getSBoxValue(temp[0]);
temp[1]=getSBoxValue(temp[1]);
temp[2]=getSBoxValue(temp[2]);
temp[3]=getSBoxValue(temp[3]);
}

temp[0] = temp[0] ^ Rcon[i/Nk];
}
else if (Nk > 6 && i % Nk == 4)
{

{
temp[0]=getSBoxValue(temp[0]);
temp[1]=getSBoxValue(temp[1]);
temp[2]=getSBoxValue(temp[2]);
temp[3]=getSBoxValue(temp[3]);
}
}
RoundKey[i*4+0] = RoundKey[(i-Nk)*4+0] ^ temp[0];
RoundKey[i*4+1] = RoundKey[(i-Nk)*4+1] ^ temp[1];
RoundKey[i*4+2] = RoundKey[(i-Nk)*4+2] ^ temp[2];
RoundKey[i*4+3] = RoundKey[(i-Nk)*4+3] ^ temp[3];
i++;
}
}

void AddRoundKey(int round)
{
int i,j;
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
state[j][i] ^= RoundKey[round * Nb * 4 + i * Nb + j];
}
}
}

void SubBytes()
{
int i,j;
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
state[i][j] = getSBoxValue(state[i][j]);

}
}
}

void ShiftRows()
{
unsigned char temp;
temp=state[1][0];
state[1][0]=state[1][1];
state[1][1]=state[1][2];
state[1][2]=state[1][3];
state[1][3]=temp;

temp=state[2][0];
state[2][0]=state[2][2];
state[2][2]=temp;

temp=state[2][1];
state[2][1]=state[2][3];
state[2][3]=temp;

temp=state[3][0];
state[3][0]=state[3][3];
state[3][3]=state[3][2];
state[3][2]=state[3][1];
state[3][1]=temp;
}

#define xtime(x) ((x<<1) ^ (((x>>7) & 1) * 0x1b))

void MixColumns()
{
int i;
unsigned char Tmp,Tm,t;
for(i=0;i<4;i++)
{
t=state[0][i];
Tmp = state[0][i] ^ state[1][i] ^ state[2][i] ^ state[3][i] ;
Tm = state[0][i] ^ state[1][i] ; Tm = xtime(Tm); state[0][i] ^= Tm ^ Tmp ;
Tm = state[1][i] ^ state[2][i] ; Tm = xtime(Tm); state[1][i] ^= Tm ^ Tmp ;
Tm = state[2][i] ^ state[3][i] ; Tm = xtime(Tm); state[2][i] ^= Tm ^ Tmp ;
Tm = state[3][i] ^ t ; Tm = xtime(Tm); state[3][i] ^= Tm ^ Tmp ;
}
}

void Cipher()
{
int i,j,round=0;

for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
state[j][i] = in[i*4 + j];
}
}

AddRoundKey(0);
for(round=1;round<Nr;round++)
{
SubBytes();
ShiftRows();
MixColumns();
AddRoundKey(round);
}

SubBytes();
ShiftRows();
AddRoundKey(Nr);

for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
out[i*4+j]=state[j][i];
}
}
}
void main()
{
int i;
unsigned char temp[16] = {0x00 ,0x01 ,0x02 ,0x03 ,0x04 ,0x05 ,0x06 ,0x07 ,0x08 ,0x09 ,0x0a ,0x0b ,0x0c ,0x0d ,0x0e ,0x0f};
unsigned char temp2[16]= {0x00 ,0x11 ,0x22 ,0x33 ,0x44 ,0x55 ,0x66 ,0x77 ,0x88 ,0x99 ,0xaa ,0xbb ,0xcc ,0xdd ,0xee ,0xff};

printf(“********************************************************************************\n\n”);
printf(” WELCOME\n”);
printf(” ANDA TELAH MEMASUKI PROGRAM ADVANCE ENCRYPTION STANDARD\n”);
printf(” PROGRAM ENKRIPSI\n”);
printf(” KARYA : NEO FAJAR BAWANA KONTA DEWA DANU\n\n”);
printf(“********************************************************************************\n\n”);

while(Nr!=128 && Nr!=192 && Nr!=256)
{
printf(“Masukan Panjang Kunci (128, 192 or 256 only): “);
scanf(“%d”,&Nr);
}

Nk = Nr / 32;
Nr = Nk + 6;

for(i=0;i<Nk*4;i++)
{
Key[i]=temp[i];
in[i]=temp2[i];
}

printf(“Masukan Kunci dalam Heksadesimal: “);
for(i=0;i<Nk*4;i++)
{
scanf(“%x”,&Key[i]);
}

printf(“Masukan Plaintext dalam Heksadesimal: “);
for(i=0;i<Nb*4;i++)
{
scanf(“%x”,&in[i]);
}

KeyExpansion();
Cipher();
printf(“\nTeks enkripsi:\n”);
for(i=0;i<Nk*4;i++)
{
printf(“%02x “,out[i]);
}
printf(“\n\n”);
getch();
}

NOTE :

program ini masih banyak kekurangan,,

Mohon jika memasuki Blog ini untuk memberikan komentar dan memperbaiki program ini…thx!!

May 5, 2008 Posted by | Pemrograman Neo | Leave a comment

Bentuk Kriptosistem DES

DES

January 27, 2008 Posted by | Kriptografi | 2 Comments

The Beauty Of Number

Number

January 26, 2008 Posted by | Diskrit | Leave a comment

PigeonHole

Pigeonhole

January 26, 2008 Posted by | Diskrit | Leave a comment

Kuliah Diskrit

Pendahuluan

January 26, 2008 Posted by | Diskrit | Leave a comment

Source Code ElGamal

Source Code ElGamal

January 26, 2008 Posted by | Kriptografi | 1 Comment