GPGVM
GPGVM

Reputation: 5619

Break stream of digits into smaller chunks for processing

Please understand the problem I am going to present is academic and as such may not make sense in a real world application.

I have a sample program that functions properly. This program writes data to a file in which every line is a byte. The lines are numeric representations of these bytes. This numeric representation is the result of 128 bit RSA encryption of the bytes.

For example the very first line:

96044789616462297850953361101470572607 translates (decrypts) into 60 and byte 60 is of course < which is correct as this is an xml doc.

Now the sample program has a distinct advantage as the encrypted source file has line breaks in all the correct spots.

My self-inflicted pursuit was to try and instead read from a stream of digits. So where the sample program reads 4 lines and process each one:

96044789616462297850953361101470572607 == 60 == <
40994093243674456311017847789777907446  == 63 == ?
61444338813524296592539084778436332638  == 120 == x
169017452170450092162160631302176410189  == 109 == m
//Note how the fourth line is 39 not 38 digits

I would instead have:

960447896164622978509533611014705726074099409324367445631101784778977790744661444338813524296592539084778436332638169017452170450092162160631302176410189......

Now originally I thought to split on every 38th digit:

lineSplitted = Enumerable.Range(0, (line.Length / 38)).Select(l => line.Substring(l * 38, 38)).ToArray();

but as mentioned above that isn't a guaranteed delimiter. So it seems that I must inject a delimiter as the stream is built. For example a palindrome like 1971791 that I could recognize and use for my splits when reading.

Is this the proper approach to this problem of identifying and plucking each encrypted segment out of the stream for decryption?


Edit:

So it seems from the comments a delimiter is the approach to use. Following @usr suggestion to avoid a numeric delimiter I use the split | and it of course base64 encodes and decodes just fine.

Upvotes: 1

Views: 75

Answers (1)

usr
usr

Reputation: 171206

Are you willing to use a non-digit delimiter? Consider using Split('|').

Upvotes: 3

Related Questions