encryptAll

By | 2002-06-01

This simple encryption Function uses Xor encryption and itterative encoding to more securely encrypt a text string. Although the code is not unbreakable, it cannot be broken with a simple key. Itterative encoding ensures that code-cracking techniques, like character frequency study, will not work. It’s as easy as could be. Function can be easily modified to encode more than strings.

Original Author: Bryan Hurley

Inputs

data As String, seed As Long Integer

Assumptions

Module is set to Option Base 1. This is to simplify the code. If you are adding this to a pre-existing module, make sure that Base Option 1 will not adversely affect your other functions, or modify the code to work off of Base Option 0.

Returns

Function returns String of encoded/decoded text.

Code

Public Function encryptAll(data As String, seed As Long) As String
Dim x As Integer, tmp As String, stepnum As Integer
Dim byteArray() As Byte, seedOffset As Integer, n As String
tmp = Trim$(Str(seed))
seed = 0
For x = 1 To Len(tmp)
n = Mid(tmp, x, 1)
seed = seed + CLng(n)
Next x

reCheckSeed:
If seed > 255 Then
  seed = -1 + (seed - 255)
  GoTo reCheckSeed
End If
For x = 1 To Len(data)
ReDim Preserve byteArray(x)
n = Mid(data, x, 1)
byteArray(x) = Asc(n)

stepnum = seed + x
reCheckstepnum:
If stepnum > 255 Then
  stepnum = -1 + (stepnum - 255)
  GoTo reCheckstepnum
End If

byteArray(x) = byteArray(x) Xor CByte(stepnum)

Next x
tmp = ""
For x = 1 To Len(data)
  tmp = tmp & Chr(byteArray(x))
Next x
encryptAll = tmp
End Function

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.