1 #include <iostream>
2 #include <cstdlib>
3 #include <cmath>
4 using namespace std;
5 unsigned char data[1000];
6
7 void build_data()
8 {
9 for(int a=0;a<1000;a++)
10 data[a]='A'+(rand()%26);
11 }
12
13 void Compress(const unsigned char data[1000],unsigned char dest[625]);
14 void Decompress(const unsigned char data[625],unsigned char dest[1000]);
15
16 int main()
17 {
18 unsigned char out[625];
19 unsigned char data2[1000];
20 build_data();
21 Compress(data,out);
22 Decompress(out,data2);
23 for(int i=0;i<1000;i++)
24 {
25 if(i%50==0)
26 cout <<endl;
27 cout <<data[i];
28 }
29 cout <<endl;
30 for(int i=0;i<1000;i++)
31 {
32 if(i%50==0)
33 cout <<endl;
34 cout <<data2[i];
35 }
36 return 0;
37 }
38
39
40 void Compress(const unsigned char data[1000],unsigned char dest[625])
41 {
42 char temp[1000];
43 for(int i=0;i<1000;i++)
44 temp[i]=data[i]-'A';
45 for(int i=0;i<125;i++)
46 {
47 dest[i*5+0]=(temp[i*8+0]<<3);
48 dest[i*5+0]^=(temp[i*8+1]>>2);
49
50 dest[i*5+1]=(temp[i*8+1]<<6);
51 dest[i*5+1]^=(temp[i*8+2]<<1);
52 dest[i*5+1]^=(temp[i*8+3]>>4);
53
54 dest[i*5+2]=(temp[i*8+3]<<4);
55 dest[i*5+2]^=(temp[i*8+4]>>1);
56
57 dest[i*5+3]=(temp[i*8+4]<<7);
58 dest[i*5+3]^=(temp[i*8+5]<<2);
59 dest[i*5+3]^=(temp[i*8+6]>>3);
60
61
62 dest[i*5+4]=(temp[i*8+6]<<5);
63 dest[i*5+4]^=(temp[i*8+7]);
64 }
65 }
66
67 void Decompress(const unsigned char data[625],unsigned char dest[1000])
68 {
69 char temp[1000];
70 for(int i=0;i<1000;i++)
71 temp[i]=data[i];
72 for(int i=0;i<125;i++)
73 {
74 dest[i*8+0]=(temp[i*5+0]>>3)&0x1F;
75 dest[i*8+1]=((temp[i*5+0]<<2)&0x1C)^((temp[i*5+1]>>6)&0x3);
76 dest[i*8+2]=(temp[i*5+1]>>1)&0x1F;
77 dest[i*8+3]=((temp[i*5+1]<<4)&0x10)^((temp[i*5+2]>>4)&0x0F) ;
78 dest[i*8+4]=((temp[i*5+2]<<1)&0x1E)^((temp[i*5+3]>>7)&0x1);
79 dest[i*8+5]=(temp[i*5+3]>>2)&0x1F;
80 dest[i*8+6]=((temp[i*5+3]<<3)&0x18)^((temp[i*5+4]>>5)&0x7);
81 dest[i*8+7]=(temp[i*5+4])&0x1F;
82 }
83 for(int i=0;i<1000;i++)
84 dest[i]+='A';
85 }
86
87 ////
88 ////int main()
89 ////{
90 //// int a,b;
91 //// a=5;
92 //// b=(a>>2);
93 //// cout <<a<<endl;
94 //// cout <<b<<endl;
95 //// return 0;
96 ////}