Seti Fauziah Tumanggor : Studi Enkripsi Dan Dekripsi File Dengan Menggunakan Algoritma Twofish, 2009. USU Repository © 2009
1. Penjadwalan
2. Pembagian Plaintext dan proses subsitusi
3.4 Analisa Prosedural
Analisa prosedural merupakan analisa implementasi pada pemrograman sistem. Sistem yang dimaksud disini adalah analisa sistem pemograman enkripsi dengan
menggunakan algoritma twofish.
3.4.1 Pembangkitan Kunci
Jumlah kunci internal yang harus dibangkitkan adalah sejumlah 40 kunci masing- masing 32 bit K
hingga K
39
. Dan juga dibutuhkan pembangkitan 4 buah kotak substitusi dari yang bergantung pada kunci. Twofish dapat menerima kunci sepanjang
128, 192, dan 256 bit N.
Kemudian terdefinisi k=N64. Kunci M terdiri dari 8k byte, m , ..., m
8k-1
. Byte- byte tersebut pertama-tama diubah menjadi 2k buah yang masing-masing terdiri dari
32 bit.
Hasil fungsi diatas kemudian digolongkan menjadi dua buah, ganjil dan genap. M
e
= M , M
2
, ..., M
2k-2
M
o
= M
1
, M
3
, ..., M
2k-1
Selanjutnya adalah kotak S. Langkah pertama adalah dengan
mengelompokkan kunci tersebut dikalikan dengan matriks 4x8 yang diturunkan dari RS. Setiap hasil sepanjang 4 byte duartikan sebagai satu buah 32 bit, menghasilkan
kotak S.
Seti Fauziah Tumanggor : Studi Enkripsi Dan Dekripsi File Dengan Menggunakan Algoritma Twofish, 2009. USU Repository © 2009
Hasil keluaran tahap ini adalah 2 buah matriks, matriks M genap dan matriks M ganjil, dan sebuah matriks kotak substitusi.
Adapun algoritma untuk membangkitan kunci adalah sebagai berikut
Tahap I :
Pada tahap pertama adalah pengujian ukuran kunci apakah sudah memenuhi syarat berikut pseudocode untuk menguji kunci :
If KeyLength 192 Then ReDim Preserve Key31
KeyLength = 256 ElseIf KeyLength 128 Then
ReDim Preserve Key23 KeyLength = 192
ElseIf KeyLength 64 Then ReDim Preserve Key15
KeyLength = 128 ElseIf KeyLength 32 Then
ReDim Preserve Key7 KeyLength = 64
Else ReDim Preserve Key3
KeyLength = 32 End I
Tahap II : Pada tahap kedua adalah pembentukan kunci yang tergantung pada S-box
pseudocodenya adalah:
Private Static Sub KeyCreateK As Byte, KeyLength As Long Dim i As Long
Dim lA As Long Dim lB As Long
Seti Fauziah Tumanggor : Studi Enkripsi Dan Dekripsi File Dengan Menggunakan Algoritma Twofish, 2009. USU Repository © 2009
Dim b3 As Byte Dim k64Cnt As Long
Dim k32e3 As Long Dim k32o3 As Long
Dim subkeyCnt As Long Dim sBoxKey3 As Long
Dim Key0 To 3, 0 To 3 As Byte Const SK_STEP = H2020202
Const SK_BUMP = H1010101 Const SK_ROTL = 9
k64Cnt = KeyLength \ 8 subkeyCnt = ROUND_SUBKEYS + 2 ROUNDS
For i = 0 To IIfKeyLength 32, KeyLength \ 8 - 1, 3 Call CopyMemk32ei, Ki 8, 4
Call CopyMemk32oi, Ki 8 + 4, 4 sBoxKeyKeyLength
\ 8
- 1
- i =
RS_RemRS_RemRS_RemRS_RemRS_RemRS_RemRS_RemRS_Remk32oi Xor k32ei
Next ReDim sKeysubkeyCnt
For i = 0 To subkeyCnt 2 - 1 lA = F32k64Cnt, i SK_STEP, k32e
lB = F32k64Cnt, i SK_STEP + SK_BUMP, k32o lB = lBSLlB, 8 Or lBSRUlB, 24
If m_RunningCompiled Then lA = lA + lB
Else lA = UnsignedAddlA, lB
End If sKey2 i = lA
If m_RunningCompiled Then lA = lA + lB
Seti Fauziah Tumanggor : Studi Enkripsi Dan Dekripsi File Dengan Menggunakan Algoritma Twofish, 2009. USU Repository © 2009
Else lA = UnsignedAddlA, lB
End If sKey2 i + 1 = lBSLlA, SK_ROTL Or lBSRUlA, 32 -
SK_ROTL Next
Call CopyMemKey0, 0, sBoxKey0, 16 For i = 0 To 255
If k64Cnt And 3 = 1 Then sBox2 i = MDS0, P0, i Xor Key0, 0
sBox2 i + 1 = MDS1, P0, i Xor Key1, 0 sBoxH200 + 2 i = MDS2, P1, i Xor Key2, 0
sBoxH200 + 2 i + 1 = MDS3, P1, i Xor Key3, 0 Else
b0 = i b1 = i
b2 = i b3 = i
If k64Cnt And 3 = 0 Then b0 = P1, b0 Xor Key0, 3
b1 = P0, b1 Xor Key1, 3 b2 = P0, b2 Xor Key2, 3
b3 = P1, b3 Xor Key3, 3 End If
If k64Cnt And 3 = 3 Or k64Cnt And 3 = 0 Then exception = True Then
b0 = P1, b0 Xor Key0, 2 b1 = P1, b1 Xor Key1, 2
b2 = P0, b2 Xor Key2, 2 b3 = P0, b3 Xor Key3, 2
End If sBox2 i = MDS0, P0, P0, b0 Xor Key0, 1 Xor
Key0, 0
Seti Fauziah Tumanggor : Studi Enkripsi Dan Dekripsi File Dengan Menggunakan Algoritma Twofish, 2009. USU Repository © 2009
sBox2 i + 1 = MDS1, P0, P1, b1 Xor Key1, 1 Xor Key1, 0
sBoxH200 + 2 i = MDS2, P1, P0, b2 Xor Key2, 1 Xor Key2, 0
sBoxH200 + 2 i + 1 = MDS3, P1, P1, b3 Xor Key3, 1 Xor Key3, 0
End If Next
End Sub
3.4.2 Pembagian Plaintext