Switch endian encrypted char array

I am working on a project at school, where we created a simple key distribution center on our network, encrypted using blowfish. I have successfully coded it and am working on similar machines. The problem arises when I have to send it to the machine of another end user. The key is encrypted as an array of characters, and is sent and received over the network as such. When an encrypted key is printed at either end, it displays the same encrypted string, but decryption is not performed. I tried changing the order of the array and decrypting, but the results are the same.

My questions:

  • Is my reversing the char array the correct way to solve Endian issues in this situation?

  • Could the problem be that it was encrypted on a machine in the same endian style and there it cannot be decrypted using the same algorithm on a small destination machine? (here is the version of blowfish that I used: http://www.codeproject.com/KB/security/blowfish.aspx )

+4
source share
3 answers

It depends on the implementation of the algorithm. Considering the implementation you are using (see BytesToBlock and BlockToBytes ), it translates byte blocks into unsigned ints,

This transformation depends on the end and, therefore, the algorithm must be adjusted based on the limb of the machine on which it is running.

+2
source

Concreteness applies to smaller elements of your data. If the other destination computer cannot read your char array, then it probably means that it expects bytes in the same order, but with the change of their bits.

So you need to reorder the bits in your char elements. Your array order should remain intact.

0
source

It is possible that bytes change in some quality, but this usually only happens with numbers (see https://beej.us/guide/bgnet/html/multi/htonsman.html ). Most likely, this is a bit with each char. You just need a simple algorithm to switch them before decryption. Of course, if the AND bits are mixed up, this is even more fun.

Now the fact that it displays the same line leads me to think that the problem is not in the character array itself - it is something in the decryption algorithm itself, depending on the byte order. In this case, you should definitely take a look at the link above and think about what operations you perform for multibyte types. (64-bit limit switches usually need to be written manually, but byte replacement is not a complicated algorithm for writing.)

0
source

Source: https://habr.com/ru/post/1343857/


All Articles