I am working on ARM-based modem Linux host machine and I need to read a bin file as an 8-,16- or 32- bits array. I basically need to encrypt the file in question and was thinking of just XOR-ing the bits with a random bit sequence (I don't need a very complex system). The Linux host doesn't have C or PERL modules in it so I cannot use them and hence I need to do it using a shell script. Can anyone give me some pointers on how to proceed with this?
Use
For XOR 123, you'd need to compute the corresponding
More generally, to answer the question, to convert a file into an array of numbers to be used by the shell with standard commands:
You can then apply the transformations you want and convert back to a file with That's going to be very inefficient though. Like:
You can use |
|||||||||||||
|
You can't use null terminators in most shell's variables (or rather, you can, but they will be terminated as, in general, they are stored as such), so that's a fairly major caveat of any binary read. If you have
For example:
|
|||||
|
I used this very crude function to xor two 128 byte files:
Performance wise this is utterly horrible (it's calling awk twice for every byte!). In my case, performance simply wasn't an issue. I'm sure you can find a much better way. |
|||
|
awk
doesn't do XOR native. The shell's$((...))
does though. How is that not encryption? – Stéphane Chazelas Jun 19 '13 at 12:02cat
. – Gilles Jun 19 '13 at 23:24