7 b - & gt; 8 b (complete)
Encryption methods: full program)
Will be encrypted string into an array of bytes (b), and supplement the shortage of bytes, so that the number of 7 byte array (t1) element integer times,
This byte array into every 7 bytes in a sequence as a group, which each group of 56 bits, put this 56 bits per seven bits in a byte of low seven, namely each group of 7 bytes into 8 bytes (t2), transformation rules
Append the original length of the byte array after the new byte array information (may be patched up bytes), and converted to a string (t3),
Handle new possible '\ 0' character in the string (using the method of escape characters),
Will process after the final string as an encrypted string,
Decryption method
Tip: analytical escape, and then application transformation rules
CodePudding user response:
Bit operations, there is no difficulty, it is a little trouble56 bits to 64 bits
Long long int is eight int, just 64 can do the things
Design a joint types to accommodate the initial data
The union BT {
Unsigned long long int v.
Unsigned char b8 [8].
} b7t;
Memset (b7t b8, 0, 8).
Give b7t. 7 byte assignment b8 0 to 6, the last one empty, if less than 7 byte just in front of the assignment for several can
To design a structure type, used to hold the converted data
Struct B8T {
Unsigned char b8 [8].
int len;
} b8t;
Encode:
For (int j=0; j<8; J++)
B8t. B8 [j].=b7t v& 0 x7f, b7t. V> 7.
Decode:
B7t. V=0 l;
For (int j=0; j<8; J++)
B7t. V |=b8t. B8 [j], b7t. V<7.