64,663
社区成员
发帖
与我相关
我的任务
分享
/*
**以下程序是一个信息编码程序,阅读器encode部分,并补全decode部分
**最后运行程序,会打印出一句话,这句话就是我们要求的答案。
**注意:这句话是GBK编码的!
*/
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
typedef unsigned int uint_32;
typedef unsigned char byte;
void encode(const void* raw_in, void* raw_out, uint_32 password, uint_32 len)
{
const byte* in = (const byte*)raw_in;
byte* out = (byte*)raw_out;
uint_32 seed = password ^ 0x9394d4e9u;
uint_32 i;
for (i = 0 ; i < len; ++i)
{
byte a = ( in[i] ^ seed ) >> 1;
byte b = ( ( ((uint_32)in[i]) << 13 ) ^ seed ) >> (13-7);
a &= 127;
b &= 128;
a = 127 & ( a ^ (b << 3));
out[i] = a | b;
seed = (((seed << 7) ^ seed ^ out[i]) + 48475829);
}
}
void decode(const void* raw_in, void* raw_out, uint_32 password, uint_32 len)
{
const byte* in = (const byte*)raw_in;
byte* out = (byte*)raw_out;
uint_32 seed = password ^ 0x9394d4e9u;
uint_32 i;
for (i = 0 ; i < len; ++i) {
// 请在此处补全代码
}
}
int main()
{
const byte buf1[] = {0x9c, 0xf9, 0x5b, 0x1f, 0xb9, 0x86, 0x4e, 0x39, 0xce, 0xec, 0x31, 0xbc, 0x31, 0xde, 0xc4, 0x3d, 0xfe, 0x56, 0xed, 0xdf, 0xc1, 0x4c, 0x07, 0xa8, 0x23, 0xdc, 0xdc, 0x97, 0x48, 0xc7, 0x5f, 0xeb, 0xb9, 0x1e };
byte buf2[100] = {0};
const uint_32 password = 0x8f98ce1bu;
const uint_32 len = sizeof(buf1);
decode(buf1, buf2, password, len);
printf("%s\n", buf2);
}
void decode(const void* raw_in, void* raw_out, uint_32 password, uint_32 len)
{
const byte* in = (const byte*)raw_in;
byte* out = (byte*)raw_out;
uint_32 seed = password ^ 0x9394d4e9u;
uint_32 i;
for (i = 0 ; i < len; ++i) {
// calculate seed
//
byte A = in[i] & 127;
byte B = in[i] & 128;
A = A ^ (B << 3);
A = A & 127;
byte Resultbit0 = (( seed ^ ((uint_32)B << 6) ) >> 13) & 1 ;
byte Resultbit1_7 = ((A << 1) ^ seed) & 254;
out[i] = Resultbit0 | Resultbit1_7 ;
seed = (((seed << 7) ^ seed ^ in[i]) + 48475829);
}
}
void decode(const void* raw_in, void* raw_out, uint_32 password, uint_32 len)
{
const byte* in = (const byte*)raw_in;
byte* out = (byte*)raw_out;
uint_32 seed = password ^ 0x9394d4e9u;
uint_32 i;
for (i = 0 ; i < len; ++i) {
// calculate seed
seed = seed + 48475829 * (len -i - i);
seed = seed ^ in[len - i - i];
seed = seed ^ (seed << 7);
//
byte A = ( in[len-i-1] ^ 0 ) & 127;
byte B = in[len-i-1] & 128;
byte Resultbit0 = (( seed ^ (B << 6) ) >> 13) & 1 ;
byte Resultbit1_7 = ((A << 1) ^ seed) & 254;
out[len-i-1] = Resultbit0 | Resultbit1_7 ;
}
}
void decode(const void* raw_in, void* raw_out, uint_32 password, uint_32 len)
{
const byte* in = (const byte*)raw_in;
byte* out = (byte*)raw_out;
uint_32 seed = password ^ 0x9394d4e9u;
uint_32 i;
for (i = 0 ; i < len; ++i) {
byte a = in[i] & 0x7f;
byte b = in[i] & 0x80;
b = (((b << 6) ^ seed) >> 13) & 0x1;
out[i] = (((a << 1) ^ seed) & 0xfe) | b;
seed = (((seed << 7) ^ seed ^ in[i]) + 48475829);
}
}