-
Dec 22nd, 2006, 12:03 AM
#1
Thread Starter
Hyperactive Member
String Scrambler
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:
Public Function strScramble(keyString As String) As String
Dim newS As String
Dim stp1, lnCnt As Integer
Dim stp2 As Long
If Len(keyString) <= 2 Then strScramble = keyString: Exit Function
If Len(keyString) <= 5 Then strScramble = StrReverse(keyString): Exit Function
If InStr(keyString, vbCrLf) > 0 Then 'For multi-line text
'Get line count
lnCnt = (Len(keyString) - Len(Replace(keyString, vbCrLf, ""))) / 2
For stp2 = 0 To lnCnt
'Get line
gtLn = Split(keyString, vbCrLf)(stp2)
'Scramble Line
For stp1 = 1 To Len(gtLn) Step 4 'Reverse every group of 4
newS = (newS) & StrReverse(Mid$(gtLn, stp1, 4))
Next
'Add return line
newS = (newS) & vbCrLf
Next stp2
Else 'For single-line text
For stp1 = 1 To Len(keyString) Step 4
newS = (newS) & StrReverse(Mid$(keyString, stp1, 4))
Next
End If
strScramble = newS
End Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|