gibbo1715
12-06-2005, 07:00 AM
Been looking into encripting the contents of a word doc (or other office app actually)
havnt seen anything here to do with encription so thought id post what i have
Im using the following that works fine for a word document with forms and will encript it
Sub btnEncript_Click()
Dim Test As String
For Each aField In ActiveDocument.FormFields
If aField.Type = wdFieldFormTextInput Then
Test = ActiveDocument.FormFields(aField.Name).Result
ActiveDocument.FormFields(aField.Name).Result = SubstitutionEncode(Test)
End If
Next aField
'Test = ActiveDocument.FormFields("txtTest").Result
'ActiveDocument.FormFields("txtTest").Result = SubstitutionEncode(Test)
End Sub
Sub btnDecript_Click()
Dim Test As String
For Each aField In ActiveDocument.FormFields
If aField.Type = wdFieldFormTextInput Then
Test = ActiveDocument.FormFields(aField.Name).Result
ActiveDocument.FormFields(aField.Name).Result = SubstitutionDecode(Test)
End If
Next aField
End Sub
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
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
See what you think and was wondering if anyone is aware of a more secure method of encription that would work in the same way as this method is a bit weak for anyone whos serious about it
Cheers
Gibbo
havnt seen anything here to do with encription so thought id post what i have
Im using the following that works fine for a word document with forms and will encript it
Sub btnEncript_Click()
Dim Test As String
For Each aField In ActiveDocument.FormFields
If aField.Type = wdFieldFormTextInput Then
Test = ActiveDocument.FormFields(aField.Name).Result
ActiveDocument.FormFields(aField.Name).Result = SubstitutionEncode(Test)
End If
Next aField
'Test = ActiveDocument.FormFields("txtTest").Result
'ActiveDocument.FormFields("txtTest").Result = SubstitutionEncode(Test)
End Sub
Sub btnDecript_Click()
Dim Test As String
For Each aField In ActiveDocument.FormFields
If aField.Type = wdFieldFormTextInput Then
Test = ActiveDocument.FormFields(aField.Name).Result
ActiveDocument.FormFields(aField.Name).Result = SubstitutionDecode(Test)
End If
Next aField
End Sub
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
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
See what you think and was wondering if anyone is aware of a more secure method of encription that would work in the same way as this method is a bit weak for anyone whos serious about it
Cheers
Gibbo