z = ptr Next z
dec = decSt End Function
3.2 Implementasi Algoritma Triple DES
Implementasi Algoritma Triple DES dirancang dengan menggunakan bahasa pemograman visual basic 6.0 berikut flowchart dari skema global algoritma Triple DES.
16 Kali
Start
Plain text
Initial Permutation Bagi dua plaintext
Enchipering
End
Gambar 3.1 Skema Dasar Algoritma Triple DES
Penjelasan dari flowchart diatas adalah sebagai berikut : 1.
Blok plainteks dipermutasi dengan matriks permutasi awal initial permutation atau IP.
Universitas Sumatera Utara
2. Hasil permutasi awal kemudian dienciphering- sebanyak 16 kali 16 putaran.Setiap
putaran menggunakan kunci internal yang berbeda. 3.
Hasil enciphering kemudian dipermutasi dengan matriks permutasi balikan invers initial permutation atau IP-1 menjadi blok cipherteks.
Pada flowchart diatas dapat disimpulkan bahwa Triple DES menggunakan skema dasar pada algoritma DES. Perbedaannya adalah dalam algoritma Triple DES dilakukan 3
kali. Bentuk Triple DES yang digunakan dalam penelitian ini adalah mode EEE dengan bentuk sebagai berikut :
Enkripsi: C = EK3EK2EK1 P Dekripsi: P = DK1DK2 DK3 C
Sehingga kunci yang digunakan adalah 168 bit 56 x 3. Sehingga dapat digambarkan dalam flowchart sebagai berikut
Start
Plain text
Enkripsi dengan K
1
End Enkripsi dengan K
2
Enkripsi dengan K
3
Chiper Text Start
Chiper text Dekripsi dengan K
3
End Dekripsi dengan K
2
Dekripsi dengan K
1
Chiper Text
P = DK1DK2 DK3 C C=EK3EK2EK1 P
a b
Gambar 3.2 Skema Algoritma Triple DES
Universitas Sumatera Utara
3.2.1 Proses Enkripsi
Algoritma Triple DES menggunakan skema dasar proses enkripsi pada algoritma DES. Pada tahap pertama dilakukan pembentukan sub kunci Triple DES K
1,
K
2,
K
3.
Langkah selanjutnya adalah melakukan proses algoritma DES dengan kunci yang sudah di tentukan di
atas.
Berikut algoritma yang digunakan dalam proses enkripsi: 1. Proses subtitusi plaintext dengan permutasi IP. Plaintext sebesar 64 bit 8 byte akan dibagi
dua masing-masing 32 bit sekaligus disubtitusi dengan m_IP. m_IP merupakan blok bilangan dari inisial permutasi IP. algoritmanya adalah sebagai berikut:
1. Panggil Byte2BinBlockData, 8, BinBlock
2. For a=0 to 31
La=BinBlockm_IPa Ra=BinBlockm_IPa+32
3. Next
Fungsi Byte2Bin akan mengubah byte menjadi bit, algoritmanya sebagai berikut:
1. Panggil CopyMemBinarryArray0, m_EmptyArray0, ByteLen8
2. BinLength=0
3. Selama a=0 hingga a=ByteLen-1 lakukan perulangan
4. ByteValue=ByteArray a
5. Jika ByteValue and 128 maka BinaryArrayBinLength=1
6. Jika ByteValue and 64 maka BinaryArrayBinLength + 1=1
7. Jika ByteValue and 32 maka BinaryArrayBinLength + 2=1
8. Jika ByteValue and 16 maka BinaryArrayBinLength + 3=1
9. Jika ByteValue and 8 maka BinaryArrayBinLength + 4=1
10. Jika ByteValue and 4 maka BinaryArrayBinLength + 5=1
11. Jika ByteValue and 2 maka BinaryArrayBinLength + 6=1
12. Jika ByteValue and 1 maka BinaryArrayBinLength + 7=1
13. BinLength = BinLength + 8
Universitas Sumatera Utara
14. Akhir perulangan
Setelah operasi di atas, selanjutnya data disebelah kanan akan diekspansi menjadi 48 bit 6 byte yang urutan bitnya sesuai dengan bit E, sekaligus di Xor-kan dengan hasil kunci
di atas. Algoritmanya adalah sebagai berikut i = 1 sampai 16: 1.
ErxorK0 = r31 Xor m_Key0, i 2.
ErxorK1 = r0 Xor m_Key1, i 3.
ErxorK2 = r1 Xor m_Key2, i 4.
ErxorK3 = r2 Xor m_Key3, i 5.
ErxorK4 = r3 Xor m_Key4, i 6.
ErxorK5 = r4 Xor m_Key5, i 7.
ErxorK6 = r3 Xor m_Key6, i 8.
ErxorK7 = r4 Xor m_Key7, i 9.
ErxorK8 = r5 Xor m_Key8, i 10.
ErxorK9 = r6 Xor m_Key9, i 11.
ErxorK10 = r7 Xor m_Key10, i 12.
ErxorK11 = r8 Xor m_Key11, i 13.
ErxorK12 = r7 Xor m_Key12, i 14.
ErxorK13 = r8 Xor m_Key13, i 15.
ErxorK14 = r9 Xor m_Key14, i 16.
ErxorK15 = r10 Xor m_Key15, i 17.
ErxorK16 = r11 Xor m_Key16, i 18.
ErxorK17 = r12 Xor m_Key17, i 19.
ErxorK18 = r11 Xor m_Key18, i 20.
ErxorK19 = r12 Xor m_Key19, i 21.
ErxorK20 = r13 Xor m_Key20, i 22.
ErxorK21 = r14 Xor m_Key21, i 23.
ErxorK22 = r15 Xor m_Key22, i 24.
ErxorK23 = r16 Xor m_Key23, i 25.
ErxorK24 = r15 Xor m_Key24, i 26.
ErxorK25 = r16 Xor m_Key25, i 27.
ErxorK26 = r17 Xor m_Key26, i 28.
ErxorK27 = r18 Xor m_Key27, i 29.
ErxorK28 = r19 Xor m_Key28, i
Universitas Sumatera Utara
30. ErxorK29 = r20 Xor m_Key29, i
31. ErxorK30 = r19 Xor m_Key30, i
32. ErxorK31 = r20 Xor m_Key31, i
33. ErxorK32 = r21 Xor m_Key32, i
34. ErxorK33 = r22 Xor m_Key33, i
35. ErxorK34 = r23 Xor m_Key34, i
36. ErxorK35 = r24 Xor m_Key35, i
37. ErxorK36 = r23 Xor m_Key36, i
38. ErxorK37 = r24 Xor m_Key37, i
39. ErxorK38 = r25 Xor m_Key38, i
40. ErxorK39 = r26 Xor m_Key39, i
41. ErxorK40 = r27 Xor m_Key40, i
42. ErxorK41 = r28 Xor m_Key41, i
43. ErxorK42 = r27 Xor m_Key42, i
44. ErxorK43 = r28 Xor m_Key43, i
45. ErxorK44 = r29 Xor m_Key44, i
46. ErxorK45 = r30 Xor m_Key45, i
47. ErxorK46 = r31\ Xor m_Key46, i
48. ErxorK47 = r0 Xor m_Key47, i
Kemudian hasil di atas akan disubtitusikan dengan m_sBox blok Sbox DES sebanyak 6 bit yang menghasilkan keluaran 4 bit ditampung dalam array sBox sebanyak 32
bit. Algoritmanya sebagai berikut:
1. Panggil CopyMemsBox0,m_sBox0, ErxorK0,
ERxorK1, ERxorK2, ERxorK3, ERxorK4, ERxorK5,4 2.
Panggil CopyMemsBox4,m_sBox1, ErxorK6, ERxorK7, ERxorK8, ERxorK9, ERxorK10, ERxorK11,4
3. Panggil CopyMemsBox8,m_sBox2, ErxorK12,
ERxorK13, ERxorK14, ERxorK15, ERxorK16, ERxorK17,4 4.
Panggil CopyMemsBox12,m_sBox3, ErxorK18, ERxorK19, ERxorK20, ERxorK21, ERxorK22, ERxorK23,4
5. Panggil CopyMemsBox16,m_sBox4, ErxorK24,
ERxorK25, ERxorK26, ERxorK27, ERxorK28, ERxorK29,4
Universitas Sumatera Utara
6. Panggil CopyMemsBox20,m_sBox5, ErxorK30,
ERxorK31, ERxorK32, ERxorK33, ERxorK34, ERxorK35,4 7.
Panggil CopyMemsBox24,m_sBox6, ErxorK36, ERxorK37, ERxorK38, ERxorK39, ERxorK40, ERxorK41,4
8. Panggil CopyMemsBox28,m_sBox7, ErxorK42,
ERxorK43, ERxorK44, ERxorK45, ERxorK46, ERxorK47,4
Setelah sBox dihasilkan, kemudian hasilnya akan di Xor-kan dengan data sebelah kiri dengan urutan bit sesuai dengan m_P Permutasi dari blok P dan hasilnya akan ditampung
dalam array LiRi sebanyak 32 bit. Algoritmanya sebagai berikut:
1. LiRi0 = L0 Xor sBox15
2. LiRi1 = L1 Xor sBox6
3. LiRi2 = L2 Xor sBox19
4. LiRi3 = L3 Xor sBox20
5. LiRi4 = L4 Xor sBox28
6. LiRi5 = L5 Xor sBox11
7. LiRi6 = L6 Xor sBox27
8. LiRi7 = L7 Xor sBox16
9. LiRi8 = L8 Xor sBox0
10. LiRi9 = L9 Xor sBox14
11. LiRi10 = L10 Xor sBox22
12. LiRi11 = L11 Xor sBox25
13. LiRi12 = L12 Xor sBox4
14. LiRi13 = L13 Xor sBox17
15. LiRi14 = L14 Xor sBox30
16. LiRi15 = L15 Xor sBox9
17. LiRi16 = L16 Xor sBox1
18. LiRi17 = L17 Xor sBox7
19. LiRi18 = L18 Xor sBox23
20. LiRi19 = L19 Xor sBox13
21. LiRi20 = L20 Xor sBox31
22. LiRi21 = L21 Xor sBox36
23. LiRi22 = L22 Xor sBox2
Universitas Sumatera Utara
24. LiRi23 = L23 Xor sBox8
25. LiRi24 = L24 Xor sBox18
26. LiRi25 = L25 Xor sBox12
27. LiRi26 = L26 Xor sBox29
28. LiRi27 = L27 Xor sBox5
29. LiRi28 = L28 Xor sBox21
30. LiRi29 = L29 Xor sBox10
31. LiRi30 = L30 Xor sBox3
32. LiRi31 = L31 Xor sBox24
Hasil data diatas akan dijadikan data sebelah kanan, data kiri diisi dengan data kanan sebelumnya lalu keduanya disatukan kembali menjadi data 64 bit kembali sekaligus
disubtitusi dengan m_IP dan 64 bit tersebut dijadikan 8 byte kembali. m_IP merupakan blok bilangan dari invers permutasi pada DES. Algoritmanya sebagai berikut:
1. Panggil CopyMemRL0, r0, 32
2. Panggil CopyMemRL32, L0, 32
3. Selama a=0 hingga a=63 lakukan perulangan
BinBlocka=RLm_IPInva 4.
Akhir perulangan 5.
Panggil Bin2ByteBinBlock, 8, BlockData Fungsi Bin2Byte akan mengubah bin menjadi byte, algoritmanya sebagai berikut:
1. BinLength=0
2. Selama a=0 hingga a=ByteLen – 1 lakukan perulangan
3. ByteValue=0
4. Jika BinarryArrayBinLength=1maka ByteValue=ByteValue+128
5. Jika BinarryArrayBinLength+1=1maka ByteValue=ByteValue+64
6. Jika BinarryArrayBinLength+2=1maka ByteValue=ByteValue+32
7. Jika BinarryArrayBinLength+3=1maka ByteValue=ByteValue+16
8. Jika BinarryArrayBinLength+4=1maka ByteValue=ByteValue+8
9. Jika BinarryArrayBinLength+5=1maka ByteValue=ByteValue+4
10. Jika BinarryArrayBinLength+6=1maka ByteValue=ByteValue+2
11. Jika BinarryArrayBinLength+7=1maka ByteValue=ByteValue+1
Universitas Sumatera Utara
12. ByteArraya=ByteValue
13. BinLength=BinLength + 8
14. Akhir perulangan
3.2.2 Proses Dekripsi
Proses ini merupakan kebalikan dari proses enkripsi yaitu proses mengembalikan data yang terenkripsi menjadi data yang sebenarnya. Pada proses dekripsi ini juga dilakukan tahapan-
tahapan yang sama seperti tahapan enkripsi. Algoritmanya adalah sebagai berikut i = 16 sampai 1:
For i = 16 To 1 Step -1 1.
ER[i] xor K[i] 2.
ERxorK0 = R31 Xor m_Key0, i 3.
ERxorK1 = R0 Xor m_Key1, i 4.
ERxorK2 = R1 Xor m_Key2, i 5.
ERxorK3 = R2 Xor m_Key3, i 6.
ERxorK4 = R3 Xor m_Key4, i 7.
ERxorK5 = R4 Xor m_Key5, i 8.
ERxorK6 = R3 Xor m_Key6, i 9.
ERxorK7 = R4 Xor m_Key7, i 10.
ERxorK8 = R5 Xor m_Key8, i 11.
ERxorK9 = R6 Xor m_Key9, i 12.
ERxorK10 = R7 Xor m_Key10, i 13.
ERxorK11 = R8 Xor m_Key11, i 14.
ERxorK12 = R7 Xor m_Key12, i 15.
ERxorK13 = R8 Xor m_Key13, i 16.
ERxorK14 = R9 Xor m_Key14, i 17.
ERxorK15 = R10 Xor m_Key15, i 18.
ERxorK16 = R11 Xor m_Key16, i 19.
ERxorK17 = R12 Xor m_Key17, i
Universitas Sumatera Utara
20. ERxorK18 = R11 Xor m_Key18, i
21. ERxorK19 = R12 Xor m_Key19, i
22. ERxorK20 = R13 Xor m_Key20, i
23. ERxorK21 = R14 Xor m_Key21, i
24. ERxorK22 = R15 Xor m_Key22, i
25. ERxorK23 = R16 Xor m_Key23, i
26. ERxorK24 = R15 Xor m_Key24, i
27. ERxorK25 = R16 Xor m_Key25, i
28. ERxorK26 = R17 Xor m_Key26, i
29. ERxorK27 = R18 Xor m_Key27, i
30. ERxorK28 = R19 Xor m_Key28, i
31. ERxorK29 = R20 Xor m_Key29, i
32. ERxorK30 = R19 Xor m_Key30, i
33. ERxorK31 = R20 Xor m_Key31, i
34. ERxorK32 = R21 Xor m_Key32, i
35. ERxorK33 = R22 Xor m_Key33, i
36. ERxorK34 = R23 Xor m_Key34, i
37. ERxorK35 = R24 Xor m_Key35, i
38. ERxorK36 = R23 Xor m_Key36, i
39. ERxorK37 = R24 Xor m_Key37, i
40. ERxorK38 = R25 Xor m_Key38, i
41. ERxorK39 = R26 Xor m_Key39, i
42. ERxorK40 = R27 Xor m_Key40, i
43. ERxorK41 = R28 Xor m_Key41, i
44. ERxorK42 = R27 Xor m_Key42, i
45. ERxorK43 = R28 Xor m_Key43, i
46. ERxorK44 = R29 Xor m_Key44, i
47. ERxorK45 = R30 Xor m_Key45, i
48. ERxorK46 = R31 Xor m_Key46, i
49. ERxorK47 = R0 Xor m_Key47, i
Kemudian hasil di atas akan disubtitusikan dengan m_sBox. Algoritmanya sebagai berikut:
Universitas Sumatera Utara
1. Call CopyMemsBox0, m_sBox0, ERxorK0, ERxorK1, ERxorK2,
ERxorK3, ERxorK4, ERxorK5, 4 2.
Call CopyMemsBox4, m_sBox1, ERxorK6, ERxorK7, ERxorK8, ERxorK9, ERxorK10, ERxorK11, 4
3. Call CopyMemsBox8, m_sBox2, ERxorK12, ERxorK13, ERxorK14,
ERxorK15, ERxorK16, ERxorK17, 4 4.
Call CopyMemsBox12, m_sBox3, ERxorK18, ERxorK19, ERxorK20, ERxorK21, ERxorK22, ERxorK23, 4
5. Call CopyMemsBox16, m_sBox4, ERxorK24, ERxorK25, ERxorK26,
ERxorK27, ERxorK28, ERxorK29, 4 6.
Call CopyMemsBox20, m_sBox5, ERxorK30, ERxorK31, ERxorK32, ERxorK33, ERxorK34, ERxorK35, 4
7. Call CopyMemsBox24, m_sBox6, ERxorK36, ERxorK37, ERxorK38,
ERxorK39, ERxorK40, ERxorK41, 4 8.
Call CopyMemsBox28, m_sBox7, ERxorK42, ERxorK43, ERxorK44, ERxorK45, ERxorK46, ERxorK47, 4
Kemudian algoritmanya adalah sebagai berikut i = 16 sampai 1: 1.
LiRi0 = l0 Xor sBox15 2.
LiRi1 = l1 Xor sBox6 3.
LiRi2 = l2 Xor sBox19 4.
LiRi3 = l3 Xor sBox20 5.
LiRi4 = l4 Xor sBox28 6.
LiRi5 = l5 Xor sBox11 7.
LiRi6 = l6 Xor sBox27 8.
LiRi7 = l7 Xor sBox16 9.
LiRi8 = l8 Xor sBox0 10.
LiRi9 = l9 Xor sBox14 11.
LiRi10 = l10 Xor sBox22 12.
LiRi11 = l11 Xor sBox25 13.
LiRi12 = l12 Xor sBox4 14.
LiRi13 = l13 Xor sBox17 15.
LiRi14 = l14 Xor sBox30 16.
LiRi15 = l15 Xor sBox9 17.
LiRi16 = l16 Xor sBox1
Universitas Sumatera Utara
18. LiRi17 = l17 Xor sBox7
19. LiRi18 = l18 Xor sBox23
20. LiRi19 = l19 Xor sBox13
21. LiRi20 = l20 Xor sBox31
22. LiRi21 = l21 Xor sBox26
23. LiRi22 = l22 Xor sBox2
24. LiRi23 = l23 Xor sBox8
25. LiRi24 = l24 Xor sBox18
26. LiRi25 = l25 Xor sBox12
27. LiRi26 = l26 Xor sBox29
28. LiRi27 = l27 Xor sBox5
29. LiRi28 = l28 Xor sBox21
30. LiRi29 = l29 Xor sBox10
31. LiRi30 = l30 Xor sBox3
32. LiRi31 = l31 Xor sBox24
33. Call CopyMeml0, R0, 32
34. Call CopyMemR0, LiRi0, 32
35. Next
3.3 Perancangan Flowchart