This is probably going to be a bit advanced for some people...it definitely is for me...what I basically want is to be able to take two strings and merge their *values* together to make a third string.

For instance, if I had "aaaaaa" and the values of the second string was "123456" (note the string *ISN'T* 123456, their ascii values would be) then the outputted string would be "bcdefg"

This is a piece of code that I have written that can do it the simple way:

VB Code:
  1. str1 = "aaaaaa"
  2. str2 = "123456"
  3.  
  4. For b = 1 To Len(str1)
  5. tmpnum = Asc(Mid(str1, b, 1)) + Val(Mid(str2, b, 1))
  6. If tmpnum > 255 Then tmpnum = tmpnum - 256
  7. str3 = str3 & Chr(tmpnum)
  8. Next b

For simplicity, I have made this use val rather than asc for the second string, and for the purposes of my requirements either way works fine for me...and if val was used, the string COULD be "123456" rather than an ascii equivalent. The code also *HAS* to deduct 256 from the value if it's over 255 to keep it a valid character

Basically, this piece of code will be run something like 90%-95% of the time in my program and I need it to be as fast as possible. In my case, the code works with 50k strings of text and will need to process many gigabytes of data, so any speed increase would help.

For the record, this sort of code used with a prng (search wiki for the word :-)) would make an excellent encryption system...although that's not what I am doing with it. :-)

Another aspect of this code I will need is the ability to do the opposite...deduct the value from string 1 and if it's below 0 add 256 to it...which again would be useful for decrypting the encrypted data...the simple way to do this is to have 256 minus the value in string 2 then deduct 256 from the value of the number...or two lines of code where one adds while the other subtracts and an if/then on each checking for something.

And if anyone is wondering why I would want this, it's just a filter for something I'm working on...you could say it's encryption as that *is* the effect it has but the resulting effect for me has nothing to do with encryption :-P