📄 rfc1505.txt
字号:
{
uint i, j;
long r;
for (i = 0; i <= 255; i++) {
r = i;
for (j = 8; j > 0; j--) {
if (r & 1)
r = (r >> 1) ^ CRCPOLY;
else
r >>= 1;
}
crctable[i] = r;
}
}
void PutXX(int c) /* Translate and put xxcode */
{
c = xxcodes[c & 0x3F];
if (++char_ct > CHARSLINE) {
char_ct = 1;
fputc('\n', out);
}
fputc(c, out);
out_count++;
}
void PutBits(int c, int len) /* Put rightmost "len" bits of "c" */
{
c <<= 16 - len;
c &= 0xFFFF;
putbuf |= (uint) c >> putlen;
Costanzo, Robinson & Ullmann [Page 29]
RFC 1505 Encoding Header Field August 1993
c <<= 16 - putlen;
c &= 0xFFFF;
putlen += len;
while (putlen >= 6) {
PutXX(putbuf >> 10);
putlen -= 6;
putbuf <<= 6;
putbuf &= 0xFFFF;
putbuf |= (uint) c >> 10;
c = 0;
}
}
void EncodePosition(int ch) /* Encode offset position pointer */
{
int width;
int prefix;
int pwr;
pwr = 1 << STRTP;
for (width = STRTP; ch >= pwr; width += STEPP, pwr <<= 1)
ch -= pwr;
if ((prefix = width - STRTP) != 0)
PutBits(0xffff, prefix);
if (width < STOPP)
width++;
/* else if (width > STOPP)
abort(); do nothing */
PutBits(ch, width);
}
void EncodeLength(int ch) /* Encode code length */
{
int width;
int prefix;
int pwr;
pwr = 1 << STRTL;
for (width = STRTL; ch >= pwr; width += STEPL, pwr <<= 1)
ch -= pwr;
if ((prefix = width - STRTL) != 0)
PutBits(0xffff, prefix);
if (width < STOPL)
width++;
/* else if (width > STOPL)
abort(); do nothing */
PutBits(ch, width);
}
Costanzo, Robinson & Ullmann [Page 30]
RFC 1505 Encoding Header Field August 1993
main(int ac, char **av) /* main program */
{
uint r, s, i, c;
uchar *p, *rp;
int match_position;
int match_length;
int len;
uint hash, h;
if (ac < 3) {
fprintf(stderr, "usage: juencode in out\n");
return(1);
}
in = fopen(av[1], "rb");
if (!in) {
fprintf(stderr, "Can't open %s\n", av[1]);
return(1);
}
out = fopen(av[2], "w");
if (!out) {
fprintf(stderr, "Can't open %s\n", av[2]);
fclose(in);
return(1);
}
char_ct = 0;
in_count = 0;
out_count = 0;
putbuf = 0;
putlen = 0;
hash = 0;
MakeCrctable();
crc = CRC_MASK;
fprintf(out, "* LZJU90 %s\n", av[1]);
/* The hash table inititialization is somewhat arbitrary */
for (i = 0; i < K; i++) hash_table[i] = i % N;
r = 0;
s = 0;
/* Fill lookahead buffer */
for (len = 0; len < F && (c = fgetc(in)) != EOF; len++) {
Costanzo, Robinson & Ullmann [Page 31]
RFC 1505 Encoding Header Field August 1993
UPDATE_CRC(crc, c);
in_count++;
window_text[s++] = c;
}
while (len > 0) {
/* look for match in window at hash position */
h = ((((window_text[r] << 5) ^ window_text[r+1])
<< 5) ^ window_text[r+2]);
p = window_text + hash_table[h % K];
rp = window_text + r;
for (i = 0, match_length = 0; i < F; i++) {
if (*p++ != *rp++) break;
match_length++;
}
match_position = r - hash_table[h % K];
if (match_position <= 0) match_position += N;
if (match_position > N - F - 2) match_length = 0;
if (match_position > in_count - len - 2)
match_length = 0; /* ! :-) */
if (match_length > len)
match_length = len;
if (match_length < THRESHOLD) {
EncodeLength(0);
PutBits(window_text[r], 8);
match_length = 1;
}
else {
EncodeLength(match_length - THRESHOLD + 1);
EncodePosition(match_position);
}
for (i = 0; i < match_length &&
(c = fgetc(in)) != EOF; i++) {
UPDATE_CRC(crc, c);
in_count++;
window_text[s] = c;
if (s < F - 1)
window_text
[s + N] = c;
if (++s > N - 1) s = 0;
hash = ((hash << 5) ^ window_text[r]);
if (r > 1) hash_table[hash % K] = r - 2;
if (++r > N - 1) r = 0;
}
Costanzo, Robinson & Ullmann [Page 32]
RFC 1505 Encoding Header Field August 1993
while (i++ < match_length) {
if (++s > N - 1) s = 0;
hash = ((hash << 5) ^ window_text[r]);
if (r > 1) hash_table[hash % K] = r - 2;
if (++r > N - 1 ) r = 0;
len--;
}
}
/* end compression indicator */
EncodeLength(1);
EncodePosition(0);
PutBits(0, 7);
fprintf(out, "\n* %lu %08lX\n", in_count, crc);
fprintf(stderr, "Encoded %lu bytes to %lu symbols\n",
in_count, out_count);
fclose(in);
fclose(out);
return(0);
}
5.3.2 Example LZJU90 Compressed Object
The following is an example of an LZJU90 compressed object. Using
this as source for the program in section 5.3 will reveal what it is.
Encoding: 7 LZJU90 Text
* LZJU90 example
8-mBtWA7WBVZ3dEBtnCNdU2WkE4owW+l4kkaApW+o4Ir0k33Ao4IE4kk
bYtk1XY618NnCQl+OHQ61d+J8FZBVVCVdClZ2-LUI0v+I4EraItasHbG
VVg7c8tdk2lCBtr3U86FZANVCdnAcUCNcAcbCMUCdicx0+u4wEETHcRM
7tZ2-6Btr268-Eh3cUAlmBth2-IUo3As42laIE2Ao4Yq4G-cHHT-wCEU
6tjBtnAci-I++
* 190 081E2601
Costanzo, Robinson & Ullmann [Page 33]
RFC 1505 Encoding Header Field August 1993
6. Alphabetical Listing of Defined Encodings
Keyword Description Section Reference(s)
_______ ___________ _______ ____________
EDIFACT EDIFACT format 3.5
EDI-X12 EDI X12 format 3.5 ANSI X12
EVFU FORTRAN format 3.4
FS File System format 3.6, 4
Hex Hex binary format 3.3
LZJU90 LZJU90 format 3.7, 5
LZW LZW format 3.8
Message Encapsulated Message 3.2 STD 11, RFC 822
PEM, PEM-Clear Privacy Enhanced Mail 3.10 RFC 1421-1424
PGP Pretty Good Privacy 3.11
Postscript Postscript format 3.14 [8]
Shar Shell Archive format 3.15
Signature Signature 3.12
Tar Tar format 3.13
Text Text 3.1 IS 10646
uuencode uuencode format 3.9
URL external URL-reference 3.16
7. Security Considerations
Security of content and the receiving (decoding) system is discussed
in sections 3.10, 3.11, 3.15, and 4.2.10. The considerations
mentioned also apply to other encodings and attributes with similar
functions.
8. References
[1] Robinson, D. and R. Ullmann, "Encoding Header Field for Internet
Messages", RFC 1154, Prime Computer, Inc., April 1990.
[2] Crocker, D., "Standard for the Format of ARPA Internet Text
Messages", STD 11, RFC 822, University of Delaware, August 1982.
[3] International Organization for Standardization, Information
Technology -- Universal Coded Character Set (UCS). ISO/IEC
10646-1:1993, June 1993.
[4] Linn, J., "Privacy Enhancement for Internet Electronic Mail: Part
I: Message Encryption and Authentication Procedures" RFC 1421,
IAB IRTF PSRG, IETF PEM WG, February 1993.
Costanzo, Robinson & Ullmann [Page 34]
RFC 1505 Encoding Header Field August 1993
[5] Kent, S., "Privacy Enhancement for Internet Electronic Mail: Part
II: Certificate-Based Key Management", RFC 1422, IAB IRTF PSRG,
IETF PEM, BBN, February 1993.
[6] Balenson, D., "Privacy Enhancement for Internet Electronic Mail:
Part III: Algorithms, Modes, and Identifiers", RFC 1423, IAB IRTF
PSRG, IETF PEM WG, TIS, February 1993.
[7] Kaliski, B., "Privacy Enhancement for Internet Electronic Mail:
Part IV: Key Certification and Related Services", RFC 1424, RSR
Laboratories, February 1993.
[8] Adobe Systems Inc., PostScript Language Reference Manual. 2nd
Edition, 2nd Printing, January 1991.
[9] Rose, M. and E. Steffererud, "Proposed Standard for Message
Encapsulation", RFC 934, Delaware and NMA, January 1985.
[10] Postel, J., "Simple Mail Transfer Protocol", STD 10, RFC 821,
USC/Information Sciences Institute, August 1982.
[11] Borenstein, N., and N. Freed, "MIME (Multipurpose Internet Mail
Extensions): Mechanisms for Specifying and Describing the Format
of Internet Message Bodies", RFC 1341, Bellcore, Innosoft, June
1992.
[12] Borenstein, N., and M. Linimon, "Extension of MIME Content-Types
to a New Medium", RFC 1437, 1 April 1993.
9. Acknowledgements
The authors would like to thank Robert Jung for his contributions to
this work, in particular the public domain sample code for LZJU90.
Costanzo, Robinson & Ullmann [Page 35]
RFC 1505 Encoding Header Field August 1993
10. Authors' Addresses
Albert K. Costanzo
AKC Consulting Inc.
P.O. Box 4031
Roselle Park, NJ 07204-0531
Phone: +1 908 298 9000
Email: AL@AKC.COM
David Robinson
Computervision Corporation
100 Crosby Drive
Bedford, MA 017
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -