meteo
12-23-2002, 09:35 PM
I know, this is a really strange question, but I have no clue where to put it. Here's the code:
Private Function SubstitutionEncode(ByVal PlainText As String) As String
'encodes plaintext by using a simple substitution cipher.
Dim s As String
Dim i As Long, j As Long
Const InText As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijkl" & _
"mnopqrstuvwxyz0123456789 .,?!"
Const OUTCODE As String = "Kv iFyaehOVGpM.HfT60StRDBZ3XUmWdCo" & _
"P8u2,cqIwj!J9sbLnQ?EAlz7rk41xg5NY"
For i = 1 To Len(PlainText)
j = InStr(InText, Mid$(PlainText, i, 1))
If j Then
s = s & Mid$(OUTCODE, j, 1)
Else
s = s & Mid$(PlainText, i, 1)
End If
Next i
SubstitutionEncode = s
End Function
And this also:
Private Function SubstitutionDecode(ByVal CodeText As String) As String
'Decodes codetext by using a simple substitution cipher.
Dim s As String
Dim i As Long, j As Long
Const OUTTEXT As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijkl" & _
"mnopqrstuvwxyz0123456789 .,?!"
Const INCODE As String = "Kv iFyaehOVGpM.HfT60StRDBZ3XUmWdCo" & _
"P8u2,cqIwj!J9sbLnQ?EAlz7rk41xg5NY"
For i = 1 To Len(CodeText)
j = InStr(INCODE, Mid$(CodeText, i, 1))
If j Then
s = s & Mid$(OUTTEXT, j, 1)
Else
s = s & Mid$(CodeText, i, 1)
End If
Next i
SubstitutionDecode = s
End Function
As you can see, it's encryption. It is an example from BillSoo. I'm trying to familiarize myself with the methods. I have a simple project I'm trying to put this code into. One simple form. Here's the code:
Private Sub cmdEncr_Click()
strText = txtTest.Text
Open ("C:\Encrypt\file.txt") For Output As #1
Write #1, strText
Close #1
Open ("C:\encrypt\file.txt") For Input As #1
Input #1, strEncrypt
Close #1
lbl1.Caption = strEncrypt
End Sub
Private Sub cmdSplit_Click()
Dim str As String
Dim strArray() As String
Dim x As Integer
str = txtTest.Text
For x = 0 To Len(str) - 1
ReDim Preserve strArray(x)
strArray(x) = Mid(str, x + 1, 1)
Next x
lbl1.Caption = Join(strArray, " ")
End Sub
Private Sub Form_Load()
Dim strText As String
Dim strEncrypt As String
End Sub
Basically, the user types a string into the textbox, and hits the "encrypt" command button. I thought the above sample code would go in here, but it didn't work. Any help is appreciated.
Thanks!
Private Function SubstitutionEncode(ByVal PlainText As String) As String
'encodes plaintext by using a simple substitution cipher.
Dim s As String
Dim i As Long, j As Long
Const InText As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijkl" & _
"mnopqrstuvwxyz0123456789 .,?!"
Const OUTCODE As String = "Kv iFyaehOVGpM.HfT60StRDBZ3XUmWdCo" & _
"P8u2,cqIwj!J9sbLnQ?EAlz7rk41xg5NY"
For i = 1 To Len(PlainText)
j = InStr(InText, Mid$(PlainText, i, 1))
If j Then
s = s & Mid$(OUTCODE, j, 1)
Else
s = s & Mid$(PlainText, i, 1)
End If
Next i
SubstitutionEncode = s
End Function
And this also:
Private Function SubstitutionDecode(ByVal CodeText As String) As String
'Decodes codetext by using a simple substitution cipher.
Dim s As String
Dim i As Long, j As Long
Const OUTTEXT As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijkl" & _
"mnopqrstuvwxyz0123456789 .,?!"
Const INCODE As String = "Kv iFyaehOVGpM.HfT60StRDBZ3XUmWdCo" & _
"P8u2,cqIwj!J9sbLnQ?EAlz7rk41xg5NY"
For i = 1 To Len(CodeText)
j = InStr(INCODE, Mid$(CodeText, i, 1))
If j Then
s = s & Mid$(OUTTEXT, j, 1)
Else
s = s & Mid$(CodeText, i, 1)
End If
Next i
SubstitutionDecode = s
End Function
As you can see, it's encryption. It is an example from BillSoo. I'm trying to familiarize myself with the methods. I have a simple project I'm trying to put this code into. One simple form. Here's the code:
Private Sub cmdEncr_Click()
strText = txtTest.Text
Open ("C:\Encrypt\file.txt") For Output As #1
Write #1, strText
Close #1
Open ("C:\encrypt\file.txt") For Input As #1
Input #1, strEncrypt
Close #1
lbl1.Caption = strEncrypt
End Sub
Private Sub cmdSplit_Click()
Dim str As String
Dim strArray() As String
Dim x As Integer
str = txtTest.Text
For x = 0 To Len(str) - 1
ReDim Preserve strArray(x)
strArray(x) = Mid(str, x + 1, 1)
Next x
lbl1.Caption = Join(strArray, " ")
End Sub
Private Sub Form_Load()
Dim strText As String
Dim strEncrypt As String
End Sub
Basically, the user types a string into the textbox, and hits the "encrypt" command button. I thought the above sample code would go in here, but it didn't work. Any help is appreciated.
Thanks!