Did you try Benoit's suggestion:
Public Sub Main()
Dim sIn as String
Dim sOut as String
sIn = File.Load("/home/fernando/temp/deah001.dhn")
sOut = Add11(sIn)
File.Save("/home/fernando/temp/deah001.11Added.dhn", sOut)
End
Public Sub Add11(InputString as String) as String
Dim bArray As Byte[]
Dim String11 As String
Dim i As Integer
bArray = Byte[].FromString(InputString)
For i = 0 To bArray.Max
bArray[i] += 11
Next
Return bArray.ToString
End
On 2017-07-15 01:36 PM, Fernando Cabral wrote:
Well, after 5 hours the most efficient version is still running. Only 1/5
of the file has been processed. The less efficient version has only
processed 1 MB, or 1/ 42 of the file.
So I decided to write a C program to do the same task. Since I have not
been using C in the last 20 years, I did not try any fancy thing. I know C
has to be more efficient, so I expected to find find, perhaps, 10 minutes,
5 minutes. Not so. To my surprise, the program bellow did the whole thing
in ONE SECOND!
I found this to be quite inexpected.
*#include <stdio.h>int main(void){ FILE *fp; int c; fp =
fopen("/home/fernando/temp/deah001.dhn", "r"); while((c = fgetc(fp)) !=
EOF) { putchar(c + 11); } fclose(fp); return 0;}*
I am sure there is a way to do this efficiently in Gambas.Certainly not in
1 second, as it happened here, but perhaps in 5 or 10 minutes instead of
the several hours it is now taking.
- fernando
2017-07-15 11:08 GMT-03:00 Fernando Cabral <fernandojosecab...@gmail.com>:
Hi
I've found a file whose text has been obfuscated by subtracting 11 from
every byte. Now I want to bring it back to regular text. To do this I have
to add 11 to each byte read from that file. Now, I have tried several ways
to do it, and they all seemed every inefficient to me. Two examples follow
*j = 0For i = 0 To Len(RawText)str &= Chr(CByte(Asc(RawText, i) + 11)) '
either this or the following'Mid(Rawtext, i, 1) = Chr(CByte(Asc(RawText, i)
+ 11))Inc jIf j = 100000 Then Print i; Now j = 0EndifNext*
In the first option (uncommented) I am building a new string byte by byte.
In the second option (commented) I am replacing each character in place.
I expected the second option to be way faster, especially because there is
no need for the string to be reallocated. Nevertheless, it showed to be a
snail.
The first option, in spite of the fact that it grows slower and slower as
the string grows, is still way faster than the second option.
To me it does not make sense. Does it for you?
Also, is there a faster way to do this?
--
Fernando Cabral
Blogue: http://fernandocabral.org
Twitter: http://twitter.com/fjcabral
e-mail: fernandojosecab...@gmail.com
Facebook: f...@fcabral.com.br
Telegram: +55 (37) 99988-8868 <(37)%2099988-8868>
Wickr ID: fernandocabral
WhatsApp: +55 (37) 99988-8868 <(37)%2099988-8868>
Skype: fernandojosecabral
Telefone fixo: +55 (37) 3521-2183 <(37)%203521-2183>
Telefone celular: +55 (37) 99988-8868 <(37)%2099988-8868>
Enquanto houver no mundo uma só pessoa sem casa ou sem alimentos,
nenhum político ou cientista poderá se gabar de nada.
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user