FutureTexualizer[ In C ]
FutureCode
posted @ Sat, 31 Jul 2010 02:50:45 +0800
in Chapter 1 - Applications
, 1668 readers
可以把任何文件显示成文本,并且能够再转换回去的工具。
在上传文件十分痛苦的今天,显示成为文本的文件可以更加方便的发布在各类论坛上(百度贴吧支持)。
转换后文件大小将增大23.1%左右。(理论上可以达到14.3%,有空改改)
编码器代码:
#include <stdio.h> #include <string.h> #include <sys\stat.h> unsigned buffer[3] = {0, 0, 0}; int curPos = 16; int code; int finish = 0; int size; void Encode(int x); FILE *fIn, *fOut; const int HIGHSTART = 0x81; const int LOWSTART = 0x80; const int LOWEND = 0xFE; int main(int argc, char** argv) { int i, j; char name[128]; if(argc != 2) return 0; fIn = fopen(argv[1], "rb"); if(fIn == NULL) return 0; struct stat st; if(stat(argv[1], &st) == 0) size = st.st_size; for(i = strlen(argv[1]); i >= 0; i--) if(argv[1][i] == '\\') break; for(j = i + 1; j <= strlen(argv[1]); j++) name[j - i - 1] = argv[1][j]; argv[1][i + 1] = 0; fOut = fopen(strcat(strcat(argv[1], name), "-texualized.txt"), "w"); if(fread(&buffer[1], 1, 1, fIn) != 1) return 0; fprintf(fOut, "%d\n%s\n", size, name); while(finish < 2) { if(feof(fIn) != 0) finish++, buffer[2] = 0; else fread(&buffer[2], 1, 1, fIn); curPos -= 8; if(curPos <= 8) { if(curPos <= 3) { code = (buffer[0] << (curPos + 5)) + (buffer[1] >> (3 - curPos)); code &= 0x1FFF; Encode(code); } else { code = (buffer[0] << (curPos + 5)) + (buffer[1] << (curPos - 3)) + (buffer[2] >> (11 - curPos)); code &= 0x1FFF; Encode(code); } curPos += 13; } buffer[0] = buffer[1]; buffer[1] = buffer[2]; } fclose(fIn); fclose(fOut); return 0; } void Encode(int x) { int high, low; high = x / (LOWEND - LOWSTART) + HIGHSTART; low = x % (LOWEND- LOWSTART) + LOWSTART; fprintf(fOut, "%c%c", high, low); }
解码器代码:
#include <stdio.h> #include <string.h> unsigned char buffer[3] = {0, 0, 0}; FILE *fIn, *fOut; unsigned code; int curPos = 0; char tCh1, tCh2; int size; const int HIGHSTART = 0x81; const int LOWSTART = 0x80; const int LOWEND = 0xFE; unsigned Decode(char high, char low); int main(int argc, char** argv) { char add[128]; int i; unsigned char t; if(argc != 2) return 0; fIn = fopen(argv[1], "r"); if(fIn == NULL) return 0; fscanf(fIn, "%d\n", &size); fgets(add, 1024, fIn); add[strlen(add) - 1] = 0; for(i = strlen(argv[1]); i >= 0; i--) if(argv[1][i] == '\\') break; argv[1][i + 1] = 0; fOut = fopen(strcat(argv[1], add), "wb"); while(1) { if(fscanf(fIn, "%c%c", &tCh1, &tCh2) != 2) break; code = Decode(tCh1, tCh2); if(curPos <= 3) { t = 0; for(i = 0; i < 8 - curPos; i++) t = (t << 1) + 1; buffer[0] &= ~t; buffer[0] += code >> (curPos + 5); buffer[1] = (code << (3 - curPos)) & 0xFF; } else { t = 0; for(i = 0; i < 8 - curPos; i++) t = (t << 1) + 1; buffer[0] &= ~t; buffer[0] += code >> (curPos + 5); buffer[1] = (code >> (curPos - 3)) & 0xFF; buffer[2] = (code << (11 - curPos)) & 0xFF; } curPos += 13; while(curPos >= 8) { fwrite(&buffer[0], 1, 1, fOut); size--; if(size <= 0) { fclose(fIn); fclose(fOut); return 0; } buffer[0] = buffer[1], buffer[1] = buffer[2]; curPos -= 8; } } return 0; } unsigned Decode(char high, char low) { unsigned x; x = (high + 256 - HIGHSTART) * (LOWEND - LOWSTART) + (low + 256 - LOWSTART); return (x & 0x1FFF); }
编码器下载地址:http://futurecode.qupan.com/6548257.html
解码器下载地址:http://futurecode.qupan.com/6548264.html
使用方法:将需要编码/解码的文件用鼠标拽到exe图标上即可
Fri, 21 Nov 2014 22:46:10 +0800
有意思,但下载链接挂了
Tue, 31 Aug 2021 00:32:15 +0800
This is one of the best sites to follow as it will be definitely helpful for the computer programming students as they always discuss about the computer Code related topic and here also we can see the same Python full Stack course in Kochi
Mon, 29 Nov 2021 14:29:30 +0800
This is one of the most useful sites to follow as it will be helpful for the computer science students as they always explain the computer Code related topic and thanks for the valuable information shared lupus nephritis
Sun, 02 Jan 2022 05:16:09 +0800
This is certainly a awesome write-up. Thanks for bothering to describe all of this out for us. It is a great help! 메이저사이트
Wed, 16 Feb 2022 05:45:35 +0800
This is simply the info I'm discovering almost everywhere. Many thanks for the weblog, I simply sign up your site. This can be a good weblog. inch. 메이저사이트
Wed, 28 Sep 2022 00:49:21 +0800
General Science is one of the most important subjects to the Assam State SEBA board Government and Private school class 10th Grade. Assam HSLC Science Question Paper General Science is one of the most important subjects to the Assam State SEBA board Government and Private school class 10th Grade.Those students can download SEBA HSLC Science Study Material 2023 Pdf with an important question bank along suggested question bank for all science examination tests conducted by Secondary Education Board Assam.
Tue, 04 Oct 2022 00:08:48 +0800
A really fascinating read, I may well not agree totally, but you do make some quite legitimate factors. 手提電腦
Thu, 20 Oct 2022 08:03:54 +0800
Technology is rapidly accelerating and this blog post is much relevant to my thoughts. You should share more posts and get reviews from http://www.huffpost.com/archive/ca/entry/to-pay-or-not-to-pay-someone-to-write-my-essay-for-me_b_14793970 online forum. Good job done. Thanks.