This is a function I wrote, part 1 of 3 functions that I incorporate into my custom encryption method. I'm not going to reveal all three and how they perform with each other, but I thought maybe this might give someone a head start for their own encryption function, or serve a useful or entertaining purpose of some sort. Enjoy!

What this does is take a string, be it single or multi-line (it doesn't matter), and scrambles the order of the characters. There are several ways to do this I'm sure (some faster than this, more than likely), but this is just one way to guise text. It's simple, not enough to fully encrypt an important message, but it's a start. It could also serve some other purposes.

Enjoy!


-Brendan


VB Code:
  1. Public Function strScramble(keyString As String) As String
  2.  
  3. Dim newS As String
  4. Dim stp1, lnCnt As Integer
  5. Dim stp2 As Long
  6.  
  7. If Len(keyString) <= 2 Then strScramble = keyString: Exit Function
  8. If Len(keyString) <= 5 Then strScramble = StrReverse(keyString): Exit Function
  9.  
  10. If InStr(keyString, vbCrLf) > 0 Then 'For multi-line text
  11.     'Get line count
  12.     lnCnt = (Len(keyString) - Len(Replace(keyString, vbCrLf, ""))) / 2
  13.         For stp2 = 0 To lnCnt
  14.             'Get line
  15.             gtLn = Split(keyString, vbCrLf)(stp2)
  16.                 'Scramble Line
  17.                 For stp1 = 1 To Len(gtLn) Step 4 'Reverse every group of 4
  18.                     newS = (newS) & StrReverse(Mid$(gtLn, stp1, 4))
  19.                 Next
  20.                 'Add return line
  21.                 newS = (newS) & vbCrLf
  22.         Next stp2
  23. Else 'For single-line text
  24.     For stp1 = 1 To Len(keyString) Step 4
  25.         newS = (newS) & StrReverse(Mid$(keyString, stp1, 4))
  26.     Next
  27. End If
  28.  
  29. strScramble = newS
  30.  
  31. End Function