Base64 string search

I have a string that is base64 encoded. How can I find this string to check if this string contains a specific substring that is not encoded? I don't want to decode this string and then search for it.

Can I just encode this particular substring and search for the encoded string using the encoded substring?

Thank,

0


source to share


4 answers


The best way is probably to just decode the string. However, if really needed, it can be done on the fly instead of full decoding followed by a search. You will have to implement your one search and just decode only the part you are currently checking. This is most likely only useful if you have very large strings that you really don't want (or can't) store twice in memory.



If the string you are looking for is long enough, you can also encode that string three times with various complements (e.g. '', 'x' and 'xx') and look for those that do not have the first 4 and last 4 characters ( you don't want to match the padding). When you find a match, you have to make sure the alignment matches the padding, and make sure the pieces you haven't typed in (due to padding) are also in place. The latter, of course, requires some decoding.

+8


source


Assuming you know the exact form of base64 encoding, you can encode your string as if it happened at each of the three offsets (start% 3 == 0, start% 3 == 1, start% 3 == 2). You have to be tricky around the beginning and end of the string, as these characters will be affected by the surrounding data. Then you can just use a regular IndexOf or whatever to check the middle of the string, and then it's better to check the start and end.



Personally, I wouldn't go for all of these problems, although as other suggestions recommend, just decipher and then search. It will be much easier to get right.

+2


source


Base64 can take several different forms or values ​​with different algorithms or implementations. Even looking at the Wikipedia examples , you can see that the encoded character values ​​can change depending on the position. The short answer is: no, you cannot encode just a string and search in a larger encoded text.

0


source


You cannot just search for an encoded substring. The search string will be encoded differently depending on where in the original string it appears. I think you will need to decode the whole string and then search for the substring.

-1


source







All Articles