A free open source data encryption program for steemit users [repost]

View this thread on: d.buzz | hive.blog | peakd.com | ecency.com
·@royalmacro·
0.000 HBD
A free open source data encryption program for steemit users [repost]
<html>
<p>Hello, everyone this is my first software sharing for Steemit Community. I developed a software (programmed in Visual Basic 8) for encrypting any text data. It’ll play a vital role on Steemit Community, because, on Steemit Platform we need a very long passphrase to be saved. It’s impossible to memorize this passphrase. And, it’s also very dangerous to write down this passphrase in the notepad. There are too many free password keepers &amp; encryption programs, but, maximum are not open-source. My main objective is to provide such type open-source program.</p>
<h1>I use <a href="https://en.wikipedia.org/wiki/Advanced_Encryption_Standard">AES Rijndael Block Cipher Encryption Algorithm</a> to encrypt text data.</h1>
<h2><strong>Step by Step Development :</strong></h2>
<p>&nbsp;1. <strong>Open a new project in Visual Basic 8. Select “Standard EXE”.&nbsp;</strong></p>
<p><img src="https://img1.steemit.com/0x0/https://www.steemimg.com/images/2016/09/16/VB1c3f0e.jpg" width="1366" height="768"/></p>
<p><br></p>
<p><img src="https://img1.steemit.com/0x0/https://www.steemimg.com/images/2016/09/16/VB2ce10f.jpg" width="1366" height="768"/></p>
<p><br></p>
<p>2. <strong>Create two text boxes &amp; two command buttons on the form. Text1 textbox, Text2 textbox, Command1 commandbutton &amp; Command2 commandbutton.</strong>&nbsp;</p>
<p><img src="https://img1.steemit.com/0x0/https://www.steemimg.com/images/2016/09/16/vb386e21.jpg" width="1366" height="768"/></p>
<p><br></p>
<p>3. <strong>Change the caption of the command buttons from “Command1” to “Encrypt data” &amp; “Command2” to “Decrypt data”.</strong>&nbsp;</p>
<p><img src="https://img1.steemit.com/0x0/https://www.steemimg.com/images/2016/09/16/vb454e00.jpg" width="1366" height="768"/></p>
<p><br></p>
<p>4. &nbsp;<strong>Add a class module “CRijndael” to the project</strong>&nbsp;</p>
<p><img src="https://img1.steemit.com/0x0/https://www.steemimg.com/images/2016/09/16/vb5532df.jpg" width="1366" height="768"/></p>
<p><br></p>
<p>5. &nbsp;<strong>Add this following codes to the class module “CRijndael” :</strong>&nbsp;</p>
<p><img src="https://img1.steemit.com/0x0/https://www.steemimg.com/images/2016/09/16/vb66bb27.jpg" width="1366" height="768"/></p>
<p><br></p>
<blockquote>&nbsp;Option Explicit <br>
Private m_lOnBits(30) As Long <br>
Private m_l2Power(30) As Long <br>
Private m_bytOnBits(7) As Byte <br>
Private m_byt2Power(7) As Byte <br>
Private m_InCo(3) As Byte <br>
Private m_fbsub(255) As Byte <br>
Private m_rbsub(255) As Byte <br>
Private m_ptab(255) As Byte <br>
Private m_ltab(255) As Byte <br>
Private m_ftable(255) As Long <br>
Private m_rtable(255) As Long <br>
Private m_rco(29) As Long <br>
Private m_Nk As Long <br>
Private m_Nb As Long <br>
Private m_Nr As Long <br>
Private m_fi(23) As Byte <br>
Private m_ri(23) As Byte <br>
Private m_fkey(119) As Long <br>
Private m_rkey(119) As Long <br>
Private Declare Sub CopyMemory Lib “kernel32” Alias “RtlMoveMemory” (ByVal Destination As Any, ByVal Source As Any, ByVal Length As Long) <br>
Private Sub Class_Initialize() <br>
m_InCo(0) = &amp;HB: m_InCo(1) = &amp;HD <br>
m_InCo(2) = &amp;H9: m_InCo(3) = &amp;HE <br>
m_bytOnBits(0) = 1 ’ 00000001 <br>
m_bytOnBits(1) = 3 ’ 00000011 <br>
m_bytOnBits(2) = 7 ’ 00000111 <br>
m_bytOnBits(3) = 15 ’ 00001111 <br>
m_bytOnBits(4) = 31 ’ 00011111 <br>
m_bytOnBits(5) = 63 ’ 00111111 <br>
m_bytOnBits(6) = 127 ’ 01111111 <br>
m_bytOnBits(7) = 255 ’ 11111111 <br>
m_byt2Power(0) = 1 ’ 00000001 <br>
m_byt2Power(1) = 2 ’ 00000010 <br>
m_byt2Power(2) = 4 ’ 00000100 <br>
m_byt2Power(3) = 8 ’ 00001000 <br>
m_byt2Power(4) = 16 ’ 00010000 <br>
m_byt2Power(5) = 32 ’ 00100000 <br>
m_byt2Power(6) = 64 ’ 01000000 <br>
m_byt2Power(7) = 128 ’ 10000000 <br>
m_lOnBits(0) = 1 ’ 00000000000000000000000000000001 <br>
m_lOnBits(1) = 3 ’ 00000000000000000000000000000011 <br>
m_lOnBits(2) = 7 ’ 00000000000000000000000000000111 <br>
m_lOnBits(3) = 15 ’ 00000000000000000000000000001111 <br>
m_lOnBits(4) = 31 ’ 00000000000000000000000000011111 <br>
m_lOnBits(5) = 63 ’ 00000000000000000000000000111111 <br>
m_lOnBits(6) = 127 ’ 00000000000000000000000001111111 <br>
m_lOnBits(7) = 255 ’ 00000000000000000000000011111111 <br>
m_lOnBits(8) = 511 ’ 00000000000000000000000111111111 <br>
m_lOnBits(9) = 1023 ’ 00000000000000000000001111111111 <br>
m_lOnBits(10) = 2047 ’ 00000000000000000000011111111111 <br>
m_lOnBits(11) = 4095 ’ 00000000000000000000111111111111 <br>
m_lOnBits(12) = 8191 ’ 00000000000000000001111111111111 <br>
m_lOnBits(13) = 16383 ’ 00000000000000000011111111111111 <br>
m_lOnBits(14) = 32767 ’ 00000000000000000111111111111111 <br>
m_lOnBits(15) = 65535 ’ 00000000000000001111111111111111 <br>
m_lOnBits(16) = 131071 ’ 00000000000000011111111111111111 <br>
m_lOnBits(17) = 262143 ’ 00000000000000111111111111111111 <br>
m_lOnBits(18) = 524287 ’ 00000000000001111111111111111111 <br>
m_lOnBits(19) = 1048575 ’ 00000000000011111111111111111111 <br>
m_lOnBits(20) = 2097151 ’ 00000000000111111111111111111111 <br>
m_lOnBits(21) = 4194303 ’ 00000000001111111111111111111111 <br>
m_lOnBits(22) = 8388607 ’ 00000000011111111111111111111111 <br>
m_lOnBits(23) = 16777215 ’ 00000000111111111111111111111111 <br>
m_lOnBits(24) = 33554431 ’ 00000001111111111111111111111111 <br>
m_lOnBits(25) = 67108863 ’ 00000011111111111111111111111111 <br>
m_lOnBits(26) = 134217727 ’ 00000111111111111111111111111111 <br>
m_lOnBits(27) = 268435455 ’ 00001111111111111111111111111111 <br>
m_lOnBits(28) = 536870911 ’ 00011111111111111111111111111111 <br>
m_lOnBits(29) = 1073741823 ’ 00111111111111111111111111111111 <br>
m_lOnBits(30) = 2147483647 ’ 01111111111111111111111111111111 <br>
m_l2Power(0) = 1 ’ 00000000000000000000000000000001 <br>
m_l2Power(1) = 2 ’ 00000000000000000000000000000010 <br>
m_l2Power(2) = 4 ’ 00000000000000000000000000000100 <br>
m_l2Power(3) = 8 ’ 00000000000000000000000000001000 <br>
m_l2Power(4) = 16 ’ 00000000000000000000000000010000 <br>
m_l2Power(5) = 32 ’ 00000000000000000000000000100000 <br>
m_l2Power(6) = 64 ’ 00000000000000000000000001000000 <br>
m_l2Power(7) = 128 ’ 00000000000000000000000010000000 <br>
m_l2Power(8) = 256 ’ 00000000000000000000000100000000 <br>
m_l2Power(9) = 512 ’ 00000000000000000000001000000000 <br>
m_l2Power(10) = 1024 ’ 00000000000000000000010000000000 <br>
m_l2Power(11) = 2048 ’ 00000000000000000000100000000000 <br>
m_l2Power(12) = 4096 ’ 00000000000000000001000000000000 <br>
m_l2Power(13) = 8192 ’ 00000000000000000010000000000000 <br>
m_l2Power(14) = 16384 ’ 00000000000000000100000000000000 <br>
m_l2Power(15) = 32768 ’ 00000000000000001000000000000000 <br>
m_l2Power(16) = 65536 ’ 00000000000000010000000000000000 <br>
m_l2Power(17) = 131072 ’ 00000000000000100000000000000000 <br>
m_l2Power(18) = 262144 ’ 00000000000001000000000000000000 <br>
m_l2Power(19) = 524288 ’ 00000000000010000000000000000000 <br>
m_l2Power(20) = 1048576 ’ 00000000000100000000000000000000 <br>
m_l2Power(21) = 2097152 ’ 00000000001000000000000000000000 <br>
m_l2Power(22) = 4194304 ’ 00000000010000000000000000000000 <br>
m_l2Power(23) = 8388608 ’ 00000000100000000000000000000000 <br>
m_l2Power(24) = 16777216 ’ 00000001000000000000000000000000 <br>
m_l2Power(25) = 33554432 ’ 00000010000000000000000000000000 <br>
m_l2Power(26) = 67108864 ’ 00000100000000000000000000000000 <br>
m_l2Power(27) = 134217728 ’ 00001000000000000000000000000000 <br>
m_l2Power(28) = 268435456 ’ 00010000000000000000000000000000 <br>
m_l2Power(29) = 536870912 ’ 00100000000000000000000000000000 <br>
m_l2Power(30) = 1073741824 ’ 01000000000000000000000000000000 <br>
End Sub <br>
Private Function LShift(ByVal lValue As Long, ByVal iShiftBits As Integer) As Long <br>
If iShiftBits = 0 Then <br>
LShift = lValue: Exit Function <br>
ElseIf iShiftBits = 31 Then <br>
LShift = IIf(lValue And 1, &amp;H80000000, 0) <br>
Exit Function <br>
ElseIf iShiftBits &lt; 0 Or iShiftBits &gt; 31 Then <br>
Err.Raise 6 <br>
End If <br>
If (lValue And m_l2Power(31 - iShiftBits)) Then <br>
LShift = ((lValue And m_lOnBits(31 - (iShiftBits + 1))) * m_l2Power(iShiftBits)) Or &amp;H80000000 <br>
Else <br>
LShift = ((lValue And m_lOnBits(31 - iShiftBits)) * m_l2Power(iShiftBits)) <br>
End If <br>
End Function <br>
Private Function RShift(ByVal lValue As Long, ByVal iShiftBits As Integer) As Long <br>
If iShiftBits = 0 Then <br>
RShift = lValue: Exit Function <br>
ElseIf iShiftBits = 31 Then <br>
RShift = IIf(lValue And &amp;H80000000, 1, 0) <br>
Exit Function <br>
ElseIf iShiftBits &lt; 0 Or iShiftBits &gt; 31 Then <br>
Err.Raise 6 <br>
End If <br>
RShift = (lValue And &amp;H7FFFFFFE) \ m_l2Power(iShiftBits) <br>
If (lValue And &amp;H80000000) Then RShift = (RShift Or (&amp;H40000000 \ m_l2Power(iShiftBits - 1))) <br>
End Function <br>
Private Function LShiftByte(ByVal bytValue As Byte, ByVal bytShiftBits As Byte) As Byte <br>
If bytShiftBits = 0 Then <br>
LShiftByte = bytValue: Exit Function <br>
ElseIf bytShiftBits = 7 Then <br>
LShiftByte = IIf(bytValue And 1, &amp;H80, 0) <br>
Exit Function <br>
ElseIf bytShiftBits &lt; 0 Or bytShiftBits &gt; 7 Then <br>
Err.Raise 6 <br>
End If <br>
LShiftByte = ((bytValue And m_bytOnBits(7 - bytShiftBits)) * m_byt2Power(bytShiftBits)) <br>
End Function <br>
Private Function RShiftByte(ByVal bytValue As Byte, ByVal bytShiftBits As Byte) As Byte <br>
If bytShiftBits = 0 Then <br>
RShiftByte = bytValue: Exit Function <br>
ElseIf bytShiftBits = 7 Then <br>
RShiftByte = IIf(bytValue And &amp;H80, 1, 0) <br>
Exit Function <br>
ElseIf bytShiftBits &lt; 0 Or bytShiftBits &gt; 7 Then <br>
Err.Raise 6 <br>
End If <br>
RShiftByte = bytValue \ m_byt2Power(bytShiftBits) <br>
End Function <br>
Private Function RotateLeft(ByVal lValue As Long, ByVal iShiftBits As Integer) As Long <br>
RotateLeft = LShift(lValue, iShiftBits) Or RShift(lValue, (32 - iShiftBits)) <br>
End Function <br>
Private Function RotateLeftByte(ByVal bytValue As Byte, ByVal bytShiftBits As Byte) As Byte <br>
RotateLeftByte = LShiftByte(bytValue, bytShiftBits) Or RShiftByte(bytValue, (8 - bytShiftBits)) <br>
End Function <br>
Private Function Pack(b() As Byte) As Long <br>
Dim lCount As Long, lTemp As Long <br>
For lCount = 0 To 3 <br>
lTemp = b(lCount): Pack = Pack Or LShift(lTemp, (lCount * 8)) <br>
Next lCount <br>
End Function <br>
Private Function PackFrom(b() As Byte, ByVal k As Long) As Long <br>
Dim lCount As Long, lTemp As Long <br>
For lCount = 0 To 3 <br>
lTemp = b(lCount + k): PackFrom = PackFrom Or LShift(lTemp, (lCount * 8)) <br>
Next lCount <br>
End Function <br>
Private Sub Unpack(ByVal a As Long, b() As Byte) <br>
b(0) = a And m_lOnBits(7) <br>
b(1) = RShift(a, 8) And m_lOnBits(7) <br>
b(2) = RShift(a, 16) And m_lOnBits(7) <br>
b(3) = RShift(a, 24) And m_lOnBits(7) <br>
End Sub <br>
Private Sub UnpackFrom(ByVal a As Long, b() As Byte, ByVal k As Long) <br>
b(0 + k) = a And m_lOnBits(7) <br>
b(1 + k) = RShift(a, 8) And m_lOnBits(7) <br>
b(2 + k) = RShift(a, 16) And m_lOnBits(7) <br>
b(3 + k) = RShift(a, 24) And m_lOnBits(7) <br>
End Sub <br>
Private Function Xtime(ByVal a As Byte) As Byte <br>
Dim b As Byte: b = IIf(a And &amp;H80, &amp;H1B, 0) <br>
a = LShiftByte(a, 1): a = a Xor b: Xtime = a <br>
End Function <br>
Private Function Bmul(ByVal x As Byte, y As Byte) As Byte <br>
If x &lt;&gt; 0 And y &lt;&gt; 0 Then <br>
Bmul = m_ptab((CLng(m_ltab(x)) + CLng(m_ltab(y))) Mod 255) <br>
Else <br>
Bmul = 0 <br>
End If <br>
End Function <br>
Private Function SubByte(ByVal a As Long) As Long <br>
Dim b(3) As Byte <br>
Unpack a, b <br>
b(0) = m_fbsub(b(0)): b(1) = m_fbsub(b(1)) <br>
b(2) = m_fbsub(b(2)): b(3) = m_fbsub(b(3)) <br>
SubByte = Pack(b) <br>
End Function <br>
Private Function Product(ByVal x As Long, ByVal y As Long) As Long <br>
Dim xb(3) As Byte, yb(3) As Byte <br>
Unpack x, xb: Unpack y, yb <br>
Product = Bmul(xb(0), yb(0)) Xor Bmul(xb(1), yb(1)) Xor Bmul(xb(2), yb(2)) Xor Bmul(xb(3), yb(3)) <br>
End Function <br>
Private Function InvMixCol(ByVal x As Long) As Long <br>
Dim y As Long, m As Long, b(3) As Byte <br>
m = Pack(m_InCo) <br>
b(3) = Product(m, x): m = RotateLeft(m, 24) <br>
b(2) = Product(m, x): m = RotateLeft(m, 24) <br>
b(1) = Product(m, x): m = RotateLeft(m, 24) <br>
b(0) = Product(m, x): y = Pack(b) <br>
InvMixCol = y <br>
End Function <br>
Private Function ByteSub(ByVal x As Byte) As Byte <br>
Dim y As Byte <br>
y = m_ptab(255 - m_ltab(x)): x = y <br>
x = RotateLeftByte(x, 1): y = y Xor x <br>
x = RotateLeftByte(x, 1): y = y Xor x <br>
x = RotateLeftByte(x, 1): y = y Xor x <br>
x = RotateLeftByte(x, 1): y = y Xor x <br>
y = y Xor &amp;H63: ByteSub = y <br>
End Function <br>
Private Sub gentables() <br>
Dim i As Long, y As Byte <br>
Dim b(3) As Byte, ib As Byte <br>
m_ltab(0) = 0: m_ptab(0) = 1 <br>
m_ltab(1) = 0: m_ptab(1) = 3 <br>
m_ltab(3) = 1 <br>
For i = 2 To 255 <br>
m_ptab(i) = m_ptab(i - 1) Xor Xtime(m_ptab(i - 1)) <br>
m_ltab(m_ptab(i)) = i <br>
Next i <br>
m_fbsub(0) = &amp;H63: m_rbsub(&amp;H63) = 0 <br>
For i = 1 To 255 <br>
ib = i: y = ByteSub(ib) <br>
m_fbsub(i) = y: m_rbsub(y) = i <br>
Next i <br>
y = 1 <br>
For i = 0 To 29 <br>
m_rco(i) = y: y = Xtime(y) <br>
Next i <br>
For i = 0 To 255 <br>
y = m_fbsub(i): b(3) = y Xor Xtime(y) <br>
b(2) = y: b(1) = y <br>
b(0) = Xtime(y): m_ftable(i) = Pack(b) <br>
y = m_rbsub(i): b(3) = Bmul(m_InCo(0), y) <br>
b(2) = Bmul(m_InCo(1), y): b(1) = Bmul(m_InCo(2), y) <br>
b(0) = Bmul(m_InCo(3), y): m_rtable(i) = Pack(b) <br>
Next i <br>
End Sub <br>
Private Sub gkey(ByVal nb As Long, ByVal nk As Long, Key() As Byte) <br>
Dim i As Long, j As Long, k As Long, m As Long <br>
Dim N As Long, C1 As Long, C2 As Long, C3 As Long <br>
Dim CipherKey(7) As Long <br>
m_Nb = nb: m_Nk = nk <br>
If m_Nb &gt;= m_Nk Then <br>
m_Nr = 6 + m_Nb <br>
Else <br>
m_Nr = 6 + m_Nk <br>
End If <br>
C1 = 1 <br>
If m_Nb &lt; 8 Then <br>
C2 = 2: C3 = 3 <br>
Else <br>
C2 = 3: C3 = 4 <br>
End If <br>
For j = 0 To nb - 1 <br>
m = j * 3 <br>
m_fi(m) = (j + C1) Mod nb <br>
m_fi(m + 1) = (j + C2) Mod nb <br>
m_fi(m + 2) = (j + C3) Mod nb <br>
m_ri(m) = (nb + j - C1) Mod nb <br>
m_ri(m + 1) = (nb + j - C2) Mod nb <br>
m_ri(m + 2) = (nb + j - C3) Mod nb <br>
Next j <br>
N = m_Nb * (m_Nr + 1) <br>
For i = 0 To m_Nk - 1 <br>
j = i * 4: CipherKey(i) = PackFrom(Key, j) <br>
Next i <br>
For i = 0 To m_Nk - 1 <br>
m_fkey(i) = CipherKey(i) <br>
Next i <br>
j = m_Nk: k = 0 <br>
Do While j &lt; N <br>
m_fkey(j) = m_fkey(j - m_Nk) Xor SubByte(RotateLeft(m_fkey(j - 1), 24)) Xor m_rco(k) <br>
If m_Nk &lt;= 6 Then <br>
i = 1 <br>
Do While i &lt; m_Nk And (i + j) &lt; N <br>
m_fkey(i + j) = m_fkey(i + j - m_Nk) Xor m_fkey(i + j - 1): i = i + 1 <br>
Loop <br>
Else <br>
i = 1 <br>
Do While i &lt; 4 And (i + j) &lt; N <br>
m_fkey(i + j) = m_fkey(i + j - m_Nk) Xor m_fkey(i + j - 1): i = i + 1 <br>
Loop <br>
If j + 4 &lt; N Then <br>
m_fkey(j + 4) = m_fkey(j + 4 - m_Nk) Xor SubByte(m_fkey(j + 3)) <br>
End If <br>
i = 5 <br>
Do While i &lt; m_Nk And (i + j) &lt; N <br>
m_fkey(i + j) = m_fkey(i + j - m_Nk) Xor m_fkey(i + j - 1): i = i + 1 <br>
Loop <br>
End If <br>
j = j + m_Nk: k = k + 1 <br>
Loop <br>
For j = 0 To m_Nb - 1 <br>
m_rkey(j + N - nb) = m_fkey(j) <br>
Next j <br>
i = m_Nb <br>
Do While i &lt; N - m_Nb <br>
k = N - m_Nb - i <br>
For j = 0 To m_Nb - 1 <br>
m_rkey(k + j) = InvMixCol(m_fkey(i + j)) <br>
Next j <br>
i = i + m_Nb <br>
Loop <br>
j = N - m_Nb <br>
Do While j &lt; N <br>
m_rkey(j - N + m_Nb) = m_fkey(j): j = j + 1 <br>
Loop <br>
End Sub <br>
Private Sub Encrypt(Buff() As Byte) <br>
Dim i As Long, j As Long, k As Long, m As Long <br>
Dim a(7) As Long, b(7) As Long, x() As Long <br>
Dim y() As Long, t() As Long <br>
For i = 0 To m_Nb - 1 <br>
j = i * 4: a(i) = PackFrom(Buff, j): a(i) = a(i) Xor m_fkey(i) <br>
Next i <br>
k = m_Nb: x = a: y = b <br>
For i = 1 To m_Nr - 1 <br>
For j = 0 To m_Nb - 1 <br>
m = j * 3 <br>
y(j) = m_fkey(k) Xor m_ftable(x(j) And m_lOnBits(7)) Xor RotateLeft(m_ftable(RShift(x(m_fi(m)), 8) And m_lOnBits(7)), 8) Xor RotateLeft(m_ftable(RShift(x(m_fi(m + 1)), 16) And m_lOnBits(7)), 16) Xor RotateLeft(m_ftable(RShift(x(m_fi(m + 2)), 24) And m_lOnBits(7)), 24) <br>
k = k + 1 <br>
Next j <br>
t = x: x = y: y = t <br>
Next i <br>
For j = 0 To m_Nb - 1 <br>
m = j * 3 <br>
y(j) = m_fkey(k) Xor m_fbsub(x(j) And m_lOnBits(7)) Xor RotateLeft(m_fbsub(RShift(x(m_fi(m)), 8) And m_lOnBits(7)), 8) Xor RotateLeft(m_fbsub(RShift(x(m_fi(m + 1)), 16) And m_lOnBits(7)), 16) Xor RotateLeft(m_fbsub(RShift(x(m_fi(m + 2)), 24) And m_lOnBits(7)), 24) <br>
k = k + 1 <br>
Next j <br>
For i = 0 To m_Nb - 1 <br>
j = i * 4: UnpackFrom y(i), Buff, j: x(i) = 0: y(i) = 0 <br>
Next i <br>
End Sub <br>
Private Sub Decrypt(Buff() As Byte) <br>
Dim i As Long, j As Long, k As Long, m As Long <br>
Dim a(7) As Long, b(7) As Long, x() As Long <br>
Dim y() As Long, t() As Long <br>
For i = 0 To m_Nb - 1 <br>
j = i * 4: a(i) = PackFrom(Buff, j): a(i) = a(i) Xor m_rkey(i) <br>
Next i <br>
k = m_Nb: x = a: y = b <br>
For i = 1 To m_Nr - 1 <br>
For j = 0 To m_Nb - 1 <br>
m = j * 3 <br>
y(j) = m_rkey(k) Xor m_rtable(x(j) And m_lOnBits(7)) Xor RotateLeft(m_rtable(RShift(x(m_ri(m)), 8) And m_lOnBits(7)), 8) Xor RotateLeft(m_rtable(RShift(x(m_ri(m + 1)), 16) And m_lOnBits(7)), 16) Xor RotateLeft(m_rtable(RShift(x(m_ri(m + 2)), 24) And m_lOnBits(7)), 24) <br>
k = k + 1 <br>
Next j <br>
t = x: x = y: y = t <br>
Next i <br>
For j = 0 To m_Nb - 1 <br>
m = j * 3 <br>
y(j) = m_rkey(k) Xor m_rbsub(x(j) And m_lOnBits(7)) Xor RotateLeft(m_rbsub(RShift(x(m_ri(m)), 8) And m_lOnBits(7)), 8) Xor RotateLeft(m_rbsub(RShift(x(m_ri(m + 1)), 16) And m_lOnBits(7)), 16) Xor RotateLeft(m_rbsub(RShift(x(m_ri(m + 2)), 24) And m_lOnBits(7)), 24) <br>
k = k + 1 <br>
Next j <br>
For i = 0 To m_Nb - 1 <br>
j = i * 4: UnpackFrom y(i), Buff, j: x(i) = 0: y(i) = 0 <br>
Next i <br>
End Sub <br>
Private Function IsInitialized(ByRef vArray As Variant) As Boolean <br>
On Local Error Resume Next <br>
IsInitialized = IsNumeric(UBound(vArray)) <br>
End Function <br>
Public Function EncryptData(bytMessage() As Byte, bytPassword() As Byte) As Byte() <br>
Dim bytKey(31) As Byte, bytIn() As Byte, bytOut() As Byte <br>
Dim bytTemp(31) As Byte, lCount As Long, lLength As Long <br>
Dim lEncodedLength As Long, bytLen(3) As Byte, lPosition As Long <br>
If Not IsInitialized(bytMessage) Then Exit Function <br>
If Not IsInitialized(bytPassword) Then Exit Function <br>
For lCount = 0 To UBound(bytPassword) <br>
bytKey(lCount) = bytPassword(lCount): If lCount = 31 Then Exit For <br>
Next lCount <br>
gentables <br>
gkey 8, 8, bytKey <br>
lLength = UBound(bytMessage) + 1: lEncodedLength = lLength + 4 <br>
If lEncodedLength Mod 32 &lt;&gt; 0 Then lEncodedLength = lEncodedLength + 32 - (lEncodedLength Mod 32) <br>
ReDim bytIn(lEncodedLength - 1): ReDim bytOut(lEncodedLength - 1) <br>
CopyMemory VarPtr(bytIn(0)), VarPtr(lLength), 4 <br>
CopyMemory VarPtr(bytIn(4)), VarPtr(bytMessage(0)), lLength <br>
For lCount = 0 To lEncodedLength - 1 Step 32 <br>
CopyMemory VarPtr(bytTemp(0)), VarPtr(bytIn(lCount)), 32 <br>
Encrypt bytTemp <br>
CopyMemory VarPtr(bytOut(lCount)), VarPtr(bytTemp(0)), 32 <br>
Next lCount <br>
EncryptData = bytOut <br>
End Function <br>
Public Function DecryptData(bytIn() As Byte, bytPassword() As Byte) As Byte() <br>
Dim bytMessage() As Byte, bytKey(31) As Byte, bytOut() As Byte <br>
Dim bytTemp(31) As Byte, lCount As Long, lLength As Long <br>
Dim lEncodedLength As Long, bytLen(3) As Byte, lPosition As Long <br>
If Not IsInitialized(bytIn) Then Exit Function <br>
If Not IsInitialized(bytPassword) Then Exit Function <br>
lEncodedLength = UBound(bytIn) + 1 <br>
If lEncodedLength Mod 32 &lt;&gt; 0 Then Exit Function <br>
For lCount = 0 To UBound(bytPassword) <br>
bytKey(lCount) = bytPassword(lCount): If lCount = 31 Then Exit For <br>
Next lCount <br>
gentables <br>
gkey 8, 8, bytKey <br>
ReDim bytOut(lEncodedLength - 1) <br>
For lCount = 0 To lEncodedLength - 1 Step 32 <br>
CopyMemory VarPtr(bytTemp(0)), VarPtr(bytIn(lCount)), 32 <br>
Decrypt bytTemp <br>
CopyMemory VarPtr(bytOut(lCount)), VarPtr(bytTemp(0)), 32 <br>
Next lCount <br>
CopyMemory VarPtr(lLength), VarPtr(bytOut(0)), 4 <br>
If lLength &gt; lEncodedLength - 4 Then Exit Function <br>
ReDim bytMessage(lLength - 1) <br>
CopyMemory VarPtr(bytMessage(0)), VarPtr(bytOut(4)), lLength <br>
DecryptData = bytMessage <br>
End Function&nbsp;&nbsp;</blockquote>
<p>&nbsp;6. <strong>Add a module “Module 1” to the project</strong>&nbsp;</p>
<p><img src="https://img1.steemit.com/0x0/https://www.steemimg.com/images/2016/09/16/vb703526.jpg" width="1366" height="768"/></p>
<p><br></p>
<p>7. &nbsp;<strong>Add this following codes to the module “Module 1” :</strong>&nbsp;</p>
<p><img src="https://img1.steemit.com/0x0/https://www.steemimg.com/images/2016/09/16/vb8a74a1.jpg" width="1366" height="768"/></p>
<p><br></p>
<blockquote>&nbsp;Option Explicit&nbsp;</blockquote>
<blockquote>' <em>&nbsp;I use AES Rijndael Block Cipher Encryption Algorithm</em>&nbsp;</blockquote>
<blockquote>&nbsp;Private AES_alog &nbsp;As CRijndael &nbsp;&nbsp;&nbsp;</blockquote>
<blockquote>&nbsp;Public encryption_key As String 'hexadeimal to String Conversion function<br>
Public Function hexa_to_str(ByVal textData As String)<br>
Dim i As Long, CryptString As String, tmpChar As String<br>
On Local Error Resume Next<br>
For i = 1 To Len(textData) Step 2<br>
CryptString = CryptString &amp; Chr$(Val("&amp;H" &amp; Mid$(textData, i, 2)))<br>
Next i<br>
hexa_to_str = CryptString<br>
End Function 'String to hexadecimal Convertion function<br>
Public Function str_to_hexa(ByVal textData As String)<br>
Dim i As Long, CryptString As String, tmpAppend As String<br>
On Local Error Resume Next<br>
For i = 1 To Len(textData)<br>
tmpAppend = Hex$(Asc(Mid$(textData, i, 1)))<br>
If Len(tmpAppend) = 1 Then tmpAppend = Trim$(Str$(0)) &amp; tmpAppend<br>
CryptString = CryptString &amp; tmpAppend: DoEvents<br>
Next i<br>
str_to_hexa = CryptString<br>
End Function 'Encryption function with AES encryption algorithm<br>
Public Function Encrypt_it(ByVal strMsg As String,<br>
ByVal pKey As String) As String<br>
Dim ByteArray() As Byte, byteKey() As Byte, CryptText() As Byte<br>
On Local Error Resume Next<br>
Set AES_alog = New CRijndael<br>
ByteArray() = StrConv(strMsg, vbFromUnicode)<br>
byteKey() = StrConv(pKey, vbFromUnicode)<br>
CryptText() = AES_alog.EncryptData(ByteArray(), byteKey())<br>
Set AES_alog = Nothing<br>
Encrypt_it = StrConv(CryptText(), vbUnicode)<br>
End Function 'Decryption function with AES encryption algorithm<br>
Public Function Decrypt_it(ByVal strMsg As String,<br>
ByVal pKey As String) As String<br>
Dim ByteArray() As Byte, byteKey() As Byte, CryptText() As Byte<br>
On Local Error Resume Next<br>
Set AES_alog = New CRijndael<br>
ByteArray() = StrConv(strMsg, vbFromUnicode)<br>
byteKey() = StrConv(pKey, vbFromUnicode)<br>
CryptText() = AES_alog.DecryptData(ByteArray(), byteKey())<br>
Set AES_alog = Nothing<br>
Decrypt_it = StrConv(CryptText(), vbUnicode)<br>
End Function&nbsp;</blockquote>
<p><br></p>
<p>8. &nbsp;<strong>Input this following code to Form1 :</strong>&nbsp;</p>
<p><img src="https://img1.steemit.com/0x0/https://www.steemimg.com/images/2016/09/16/vb91ae48.jpg" width="1366" height="768"/></p>
<p><br></p>
<blockquote>Private Sub Form_Load()&nbsp;</blockquote>
<blockquote>encryption_key = "37979fa464f002d8a9bcf743f786863bc090b16864f93a5d1f4b83f9d05"&nbsp;</blockquote>
<blockquote>'don't reveal this key, you may set your own key</blockquote>
<blockquote>End Sub</blockquote>
<blockquote>&nbsp;'Encrypt data&nbsp;</blockquote>
<blockquote>Private Sub Command1_Click()&nbsp;</blockquote>
<blockquote>Dim sData As String</blockquote>
<blockquote>sData = Text1.Text</blockquote>
<blockquote>sData = Encrypt_it(sData, encryption_key)</blockquote>
<blockquote>Text2.Text = str_to_hexa(sData)</blockquote>
<blockquote>End Sub</blockquote>
<blockquote>Decrypt Data</blockquote>
<blockquote>Private Sub Command2_Click()</blockquote>
<blockquote>Dim sData As String</blockquote>
<blockquote>sData = Trim$(Text1.Text)</blockquote>
<blockquote>sData = hexa_to_str(sData)</blockquote>
<blockquote>Text2.Text = Decrypt_it(sData, encryption_key)</blockquote>
<blockquote>End Sub</blockquote>
<p><br></p>
<p>9. &nbsp;<strong>Make the exe file :</strong>&nbsp;</p>
<p><img src="https://img1.steemit.com/0x0/https://www.steemimg.com/images/2016/09/16/vb1081c90.jpg" width="1366" height="768"/></p>
<p><br></p>
<h1>Completed ! Now run the exe file</h1>
<h2>In this tutorial I’ll encrypt my steemit posting public key&nbsp;</h2>
<h2><strong>STM6ipnKtY59NESmg7Km5HjUuYzzRHKd8VYdLNXMyHAGUX7MnDWMh</strong></h2>
<p><br></p>
<p><img src="https://img1.steemit.com/0x0/https://www.steemimg.com/images/2016/09/16/vb11d045c.jpg" width="1366" height="768"/></p>
<p><br></p>
<h2>After encryption I got this encrypted data&nbsp;</h2>
<h2><strong>873B6CC83B0CBDC2CAC0FA1D94D4A7B9C092A6734EEC85480466DFBADCE7B8F179202D1E25AEA7FE354631E0193860ED2FB4226B162504D258A5E80FE0F5CF9D</strong>&nbsp;</h2>
<p><br></p>
<h1>You can save this data anywhere without any risk.&nbsp;</h1>
<p><br></p>
<h1>&nbsp;Now, I’m going to decrypt it again –&nbsp;</h1>
<p><br></p>
<p><img src="https://img1.steemit.com/0x0/https://www.steemimg.com/images/2016/09/16/vb125e411.jpg" width="1366" height="768"/></p>
<p><br></p>
<h2>&nbsp;Look that I successfully decrypt it by getting the text again&nbsp;</h2>
<h2><strong>STM6ipnKtY59NESmg7Km5HjUuYzzRHKd8VYdLNXMyHAGUX7MnDWMh</strong>&nbsp;</h2>
<p><br></p>
<h2><strong>I use an encryption key in the code.</strong> It's my master key. I can encrypt any text data with this key. So, it must be kept in safe. I do not need change my master key to encrypt different text data.</h2>
<blockquote>&nbsp;‘don’t reveal this key <br>
encryption_key = “37979fa464f002d8a9bcf743f786863bc090b16864f93a5d1f4b83f9d05” &nbsp;</blockquote>
<blockquote>’ you may set your own key&nbsp;&nbsp;</blockquote>
<h1><strong>WARNING !!! </strong>&nbsp;</h1>
<h1><strong>This encryption key must be different when you make your own software. And you don’t reveal this key. If anyone gets this encryption key then your encrypted data shall be at risk.</strong>&nbsp;</h1>
<p>&nbsp;</p>
<h1>&lt;&lt; <a href="https://drive.google.com/open?id=0BxKS2iCY4L_wQktwbC1ab2IxTms">Download the source code project</a> &gt;&gt;</h1>
</html>
👍 , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,