PDA

View Full Version : Encription



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

fumei
12-06-2005, 09:33 AM
Depending on who you may conceive as being paranoid about, there is NOTHING you can come up with that is more than "a bit weak".

In other words, unless you are very clever indeed, if you want to hide your document contents from the NSA....forget it.

If you want to lock your documents from normal level snooping, password protecting the documents works fine. and is readily available.

On the other hand, if you are just having fun, try making it a version of a one-time pad. Of course that is only useful between two people. If you are considering it within a business structure, forget it.

gibbo1715
12-06-2005, 11:33 AM
On the other hand, if you are just having fun, try making it a version of a one-time pad. Of course that is only useful between two people. If you are considering it within a business structure, forget it.

Hi Gerry


To be honest im having a bit of fun with encription stuff, thought id share and see what ides others have.

Any links to more of this type of stuff would be appreciated

Gibbo