View Full Version : even shuffle of numbers
havey
06-27-2006, 09:06 PM
Hi, i have three stings, string one is 5 characters long and so is string 2, string 3 can be any where from 13 to 16 in length.
i would like to shuffle the string in a patterns like this:
string1= 43095
string2= 95837
string 3 = 450098856887021
i would like to mix the string together to produce this
string1-firstvalue string3-firstvalue string1-secondValue string3-secondValue, etc until all 5 of string 1 are mixed in, then i would like to mix in string 2 but starting from the right hand side, so the end result would be:
4435009059885688975082317
thanks for helping me do the shuffle!
Brandoe85
06-27-2006, 11:14 PM
I don't think your ending number matches your formula...unless i'm missing it....
havey
06-27-2006, 11:21 PM
ok, it is incorrect, but i hope those get the picture, I want to take string 1 and two and mix them into string 3 in an alternating way
Brandoe85
06-27-2006, 11:52 PM
Ok, give this a try:
<%
Option Explicit
Response.Write(shuffle("43095", "95837", "450098856887021"))
Private Function shuffle(str1, str2, str3)
Dim i
Dim j
Dim max
Dim strTemp
j = 1
max = CInt(Len(str3))
For i = 1 To max
If i <= 5 Then
strTemp = strTemp & Mid(str1, j, 1) & Mid(str3, i, 1)
j = j + 1
Else
If j > 0 Then
strTemp = strTemp & Mid(str2, j, 1) & Mid(str3, i, 1)
j = j - 1
Else
strTemp = strTemp & Mid(str3, i, 1)
End If
End If
If i = 5 Then
j = 5
End If
Next
shuffle = strTemp
End Function
%>
Good luck;
havey
06-28-2006, 07:01 PM
Thanks a lot, that should get me started
cheers!
Brandoe85
06-28-2006, 09:33 PM
Thanks a lot, that should get me started
cheers!
Cool, good luck :)
havey
06-29-2006, 06:28 PM
Ok, i finished the encryption with salt, but i'm unhappy with the speed results, a lot of cancatenations i suspect. this is the encode function, any thought on how to spped/make more effecient? thanks
Function Encode(sIn)
dim x, y, abfrom, abto
Encode="": ABFrom = ""
For x = 0 To 25: ABFrom = ABFrom & Chr(64 + x): Next
For x = 0 To 25: ABFrom = ABFrom & Chr(96 + x): Next
For x = 0 To 9: ABFrom = ABFrom & CStr(x): Next
abto = Mid(abfrom, 14, Len(abfrom) - 13) & Left(abfrom, 13)
For x=1 to Len(sin): y = InStr(abfrom, Mid(sin, x, 1))
If y = 0 Then
Encode = Encode & Mid(sin, x, 1)
Else
Encode = Encode & Mid(abto, y, 1)
End If
Next
End Function
Function shuffle(str1, str2, str3)
Dim i
str4 = ""
FOR i = 1 to 5: str4 = str4 & mid(str1,i,1) & mid(str3,i,1): NEXT
str4 = str4 & mid(str3,6,len(str3)-10)
FOR i = 1 to 5: str4 = str4 & mid(str3,len(str3)-5+i,1) & mid(str2,i,1): NEXT
shuffle = str4
End Function
Response.Write Encode((shuffle("43095","95837","450098856887021")))
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.