字符串使用GBK编码。首先保证你的终端能够解析GBK编码。才能得到答案。
- #include <stdio.h>
- #include <sys/types.h>
- #include <stdint.h>
- int encode(const void* raw_in, void* raw_out,uint32_t password, size_t len)
- {
- const uint8_t* in = (const uint8_t*)raw_in;
- uint8_t* out = (uint8_t*)raw_out;
- uint32_t seed = password ^ 0x72590570u;
- size_t i;
- for (i = 0; i < len; ++i) {
- uint8_t a = ( in[i] ^ seed ) >> 2;
- uint8_t b = ( ( ((uint32_t)in[i]) << 17 ) ^ seed ) >> (17-6);
- a &= 63;
- b &= 192;
- a = 63 & ( a ^ (b << 3));
- out[i] = a | b;
- seed = (seed * 84723701 ^ seed ^ out[i]);
- }
- }
- int decode(const void* raw_in, void* raw_out, uint32_t password, size_t len)
- {
- const uint8_t* in = (const uint8_t*)raw_in;
- uint8_t* out = (uint8_t*)raw_out;
- uint32_t seed = password ^ 0x72590570u;
- size_t i;
- for (i = 0 ; i < len; ++i) {
- uint8_t a = ((in[i] << 2) ^ seed);
- uint8_t b = ((((uint32_t)in[i]) << 11) ^ seed) >> 17;
- a &= 252;
- b &= 3;
- out[i] = a | b;
- seed = (seed * 84723701 ^ seed ^ in[i]);
- }
- }
- int main()
- {
- const uint8_t buf1[] = {0x5f, 0xc0, 0x91, 0xbd, 0x9f, 0x7e, 0x51, \
- 0x72, 0x82, 0xff, 0xbc, 0x29, 0x12, 0x53, \
- 0x4f, 0x24, 0x2d, 0x52, 0xf9, 0x0d, 0x04, \
- 0xa6, 0x56, 0x44, 0xe9, 0x0b, 0x72, 0xd0, 0x37, 0x9d, 0xd7, \
- 0x7e, 0x60, 0x9a, 0xe6, 0x3f, 0x4d, 0xbe, 0xda, 0x78, 0xac, 0x13, };
- uint8_t buf2[100] = {};
- const uint32_t password = 0xf514c1c5u;
- const size_t len = sizeof(buf1);
- decode(buf1, buf2, password, len);
- printf("%s\n", buf2);
- }
阅读(683) | 评论(0) | 转发(0) |