Public Class Form1
Private Structure word
Dim b1 As Byte
Dim b2 As Byte
Dim b3 As Byte
Dim b4 As Byte
End Structure
Private Function CircShiftLeftW(ByVal w As word, ByVal n As Integer) As word
Dim d1 As Double, d2 As Double
d1 = WordToDouble(w)
d2 = d1
d1 = d1 * (2 ^ n)
d2 = d2 / (2 ^ (32 - n))
CircShiftLeftW = OrW(DoubleToWord(d1), DoubleToWord(d2))
End Function
Private Function DoubleToWord(ByVal n As Double) As word
DoubleToWord.b1 = Int(DMod(n, 2 ^ 32) / (2 ^ 24))
DoubleToWord.b2 = Int(DMod(n, 2 ^ 24) / (2 ^ 16))
DoubleToWord.b3 = Int(DMod(n, 2 ^ 16) / (2 ^ 8))
DoubleToWord.b4 = Int(DMod(n, 2 ^ 8))
End Function
Private Function DMod(ByVal value As Double, ByVal divisor As Double) As Double
DMod = value - (Int(value / divisor) * divisor)
If DMod < 0 Then DMod = DMod + divisor
End Function
Private Function WordToDouble(ByVal w As word) As Double
WordToDouble = (w.b1 * (2 ^ 24)) + (w.b2 * (2 ^ 16)) + (w.b3 * (2 ^ 8)) + w.b4
End Function
Private Function OrW(ByVal w1 As word, ByVal w2 As word) As word
OrW.b1 = w1.b1 Or w2.b1
OrW.b2 = w1.b2 Or w2.b2
OrW.b3 = w1.b3 Or w2.b3
OrW.b4 = w1.b4 Or w2.b4
End Function
Private Function XorW(ByVal w1 As word, ByVal w2 As word) As word
XorW.b1 = w1.b1 Xor w2.b1
XorW.b2 = w1.b2 Xor w2.b2
XorW.b3 = w1.b3 Xor w2.b3
XorW.b4 = w1.b4 Xor w2.b4
End Function
Private Function HexToWord(ByVal H As String) As word
HexToWord = DoubleToWord(Val("&H" & H & "#"))
End Function
Private Function AddW(ByVal w1 As word, ByVal w2 As word) As word
Dim I As Decimal, w As word
I = CInt(w1.b4) + w2.b4
w.b4 = I Mod 256
I = CInt(w1.b3) + w2.b3 + (I \ 512)
w.b3 = I Mod 256
I = CInt(w1.b2) + w2.b2 + (I \ 512)
w.b2 = I Mod 256
I = CInt(w1.b1) + w2.b1 + (I \ 512)
w.b1 = I Mod 256
AddW = w
End Function
Private Function WordToHex(ByVal w As word) As String
WordToHex = Hex(w.b1).PadLeft(2, "0") & Hex(w.b2).PadLeft(2, "0") & Hex(w.b3).PadLeft(2, "0") & Hex(w.b4).PadLeft(2, "0")
End Function
Private Function FuncF(ByVal x As word) As word
FuncF = XorW(AddW(x, CircShiftLeftW(x, 15)), CircShiftLeftW(x, 27))
End Function
Private Function FuncG(ByVal x As word) As word
FuncG = XorW(AddW(x, CircShiftLeftW(x, 7)), CircShiftLeftW(x, 25))
End Function
Private Function Branch(ByVal A As word, ByVal B As word, ByVal C As word, ByVal D As word, ByVal E As word, ByVal F As word, ByVal G As word, ByVal H As word, ByVal w1 As word, ByVal w2 As word, ByVal D1 As word, ByVal D2 As word) As word
Dim temp As word
Dim kata As String = ""
temp = XorW(H, CircShiftLeftW((FuncF(AddW(AddW(E, w2), D2))), 8))
H = XorW(AddW(G, CircShiftLeftW((FuncG(AddW(E, w2))), 3)), FuncF(AddW(AddW(E, w2), D2)))
G = AddW(F, FuncG(AddW(E, w2)))
F = AddW(AddW(E, w2), D2)
E = XorW(D, CircShiftLeftW(FuncG(AddW(AddW(A, w1), D1)), 17))
D = XorW((AddW(C, CircShiftLeftW(FuncF(AddW(A, w1)), 13))), FuncG(AddW(AddW(A, w1), D1)))
C = AddW(B, FuncF(AddW(A, w1)))
B = AddW(AddW(A, w1), D1)
A = temp
display(A)
End Function
Private Function display(ByVal x As word) As word
Dim kata As String = ""
kata &= WordToHex(x)
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim teks, wordtext
Dim d(63) As word
Dim CV(7) As word
Dim A(2) As word
Dim delta(15) As word
Dim A1, A2, A3, A4 As word
Dim B1, B2, B3, B4 As word
Dim C1, C2, C3, C4 As word
Dim D1, D2, D3, D4 As word
Dim E1, E2, E3, E4 As word
Dim F1, F2, F3, F4 As word
Dim G1, G2, G3, G4 As word
Dim H1, H2, H3, H4 As word
Dim w(16) As word
Dim temp As String = ""
Dim temp1 As String = ""
Dim pad1, k1 As Byte
Dim pad, i As Integer
Dim k(3) As word
Dim kata As String = ""
CV(0) = HexToWord("6a09e667")
CV(1) = HexToWord("bb67ae85")
CV(2) = HexToWord("3c6ef372")
CV(3) = HexToWord("a54ff53a")
CV(4) = HexToWord("510e527f")
CV(5) = HexToWord("9b05688c")
CV(6) = HexToWord("1f83d9ab")
CV(7) = HexToWord("5be0cd19")
delta(0) = HexToWord("428a2f98")
delta(1) = HexToWord("71374491")
delta(2) = HexToWord("b5c0fbcf")
delta(3) = HexToWord("e9b5dba5")
delta(4) = HexToWord("3956c25b")
delta(5) = HexToWord("59f111f1")
delta(6) = HexToWord("923f82a4")
delta(7) = HexToWord("ab1c5ed5")
delta(8) = HexToWord("d807aa98")
delta(9) = HexToWord("12835b01")
delta(10) = HexToWord("243185be")
delta(11) = HexToWord("550c7dc3")
delta(12) = HexToWord("72be5d74")
delta(13) = HexToWord("80deb1fe")
delta(14) = HexToWord("9bdc06a7")
delta(15) = HexToWord("c19bf174")
A1 = CV(0)
A2 = CV(0)
A3 = CV(0)
A4 = CV(0)
B1 = CV(1)
B2 = CV(1)
B3 = CV(1)
B4 = CV(1)
C1 = CV(2)
C2 = CV(2)
C3 = CV(2)
C4 = CV(2)
D1 = CV(3)
D2 = CV(3)
D3 = CV(3)
D4 = CV(3)
E1 = CV(4)
E2 = CV(4)
E3 = CV(4)
E4 = CV(4)
F1 = CV(5)
F2 = CV(5)
F3 = CV(5)
F4 = CV(5)
G1 = CV(6)
G2 = CV(6)
G3 = CV(6)
G4 = CV(6)
H1 = CV(7)
H2 = CV(7)
H3 = CV(7)
H4 = CV(7)
teks = TextBox1.Text
kata &= "Message = " & TextBox1.Text & vbCrLf & vbCrLf
For i = 0 To Len(teks) - 1
temp1 &= Hex(Asc(teks.Chars(i))) & ""
Next
kata &= "temp1 sebelum dipadding = " & temp1 & vbCrLf
kata &= "panjang temp1 sebelum dipadding = " & Len(temp1) & vbCrLf & vbCrLf
temp1 &= "8"
kata &= "temp1 setelah dtmbah 8 = " & temp1 & vbCrLf
kata &= "panjang temp1 setelah dtmbah 8 = " & Len(temp1) & vbCrLf & vbCrLf
pad = (448 - (8 * Len(teks) + 1))
pad1 = pad \ 4
kata &= "panjang pad = " & pad & vbCrLf
kata &= "panjang pad1 = " & pad1 & vbCrLf & vbCrLf
For i = 1 To pad1
temp1 &= "0"
Next
kata &= "panjang temp1 setelah dtambahh 8 & pjg teks = " & Len(temp1) & vbCrLf
kata &= "teks temp1 setelah dtambahh 8 & pjg teks = " & temp1 & vbCrLf & vbCrLf
k1 = Len(Hex(8 * Len(teks)))
kata &= "panjang k1 = " & k1 & vbCrLf & vbCrLf
For i = 1 To 16
If i = 17 - k1 Then
temp1 &= Hex(8 * Len(teks))
i = 16
Else
temp1 &= "0"
End If
Next
kata &= "panjang akhir temp1 = " & Len(temp1) & vbCrLf
kata &= "temp1 = " & temp1 & vbCrLf & vbCrLf
For i = 0 To Len(temp1) - 1
If (i <> 0) And (i Mod 8 = 0) Then
temp &= vbNewLine & temp1.Chars(i)
ElseIf i = 407 Then
temp &= vbNewLine & vbNewLine
Else
temp &= temp1.Chars(i)
End If
Next
'padding pesan
For i = 0 To 15
wordtext = Mid(temp1, i * 8 + 1, 8)
w(i).b1 = Convert.ToInt32(Mid(wordtext, 1, 2), 16)
w(i).b2 = Convert.ToInt32(Mid(wordtext, 3, 2), 16)
w(i).b3 = Convert.ToInt32(Mid(wordtext, 5, 2), 16)
w(i).b4 = Convert.ToInt32(Mid(wordtext, 7, 2), 16)
kata &= "M(" & CStr(i).PadLeft(2, "0") & ")" & vbTab & "= "
kata &= Hex(w(i).b1).PadLeft(2, "0")
kata &= Hex(w(i).b2).PadLeft(2, "0")
kata &= Hex(w(i).b3).PadLeft(2, "0")
kata &= Hex(w(i).b4).PadLeft(2, "0")
kata &= vbNewLine
Next
Branch(A1, B1, C1, D1, E1, F1, G1, H1, w(0), w(1), delta(0), delta(1))
RichTextBox1.Text = kata
End Sub
End Class
why from function branch don't show any result
plz help me