Login| Sign Up| Help| Contact|

Patent Searching and Data


Title:
BINARY DATA COMMUNICATION SYSTEM
Document Type and Number:
WIPO Patent Application WO/1992/010035
Kind Code:
A1
Abstract:
Improved means and methods are provided for transmitting binary data on a communication system, such as E-mail, which restricts the number of acceptable characters that can be transmitted. In a preferred embodiment, the binary data to be transmitted is first subjected to a Welch compression and then converted into base-85 digits for transmission. At the receiving end, the received base-85 digits are converted back into compressed binary and then subjected to Welch decompression to obtain the original binary data.

Inventors:
TEAGUE TOMMY K (US)
Application Number:
PCT/US1991/008878
Publication Date:
June 11, 1992
Filing Date:
November 27, 1991
Export Citation:
Click for automatic bibliography generation   Help
Assignee:
UNISYS CORP (US)
International Classes:
G06F13/00; G06F5/00; H03M7/06; H03M7/12; H03M7/30; (IPC1-7): G06F5/00; H03M7/00; H04L12/54
Foreign References:
US4789852A1988-12-06
US4342027A1982-07-27
US4558302A1985-12-10
EP0371609A21990-06-06
US4792793A1988-12-20
Download PDF:
Claims:
What is Claimed is:
1. In an electronically implemented method for transmitting binary data using data communication means which restricts the number of acceptable characters for transmission, the steps of: converting each of a predetermined plurality of bits of the binary data to be transmitted into a predetermined plurality of digits in a predetermined base, deriving a corresponding acceptable character for transmission on said data communication means in response to each digit produced by said converting, each digit of said predetermined base corresponding to a different acceptable character; and producing binary signals representing the derived acceptable characters for transmission on said system, said predetermined base being chosen so that the number of bits constituted by the binary signals produced for transmission of each predetermined plurality of digits is no more than 25% greater than said predetermined plurality of bits.
2. The method of claim 1, including performing Welch compression on the binary data to be transmitted prior to said converting.
3. In an electronically implemented method for transmitting and receiving binary data using data communication means which restricts the number of acceptable characters for transmission, wherein transmitted binary signals represent digits of a predetermined base, wherein a predetermined plurality of digits of said predetermined base correspond to a predetermined plurality of bits of said binary data, and wherein said predetermined base is such that the number of bits constituted by the transmitted binary signals representing each predetermined plurality of digits is no more than 25% greater than said predetermined plurality of bits, the steps of: receiving binary signals from said data communication means; deriving digits in said predetermined base from the received binary signals; converting each of said predetermined plurality of derived digits in said predetermined base into a corresponding binary number having said predetermined plurality of bits; and producing output binary signals representing each binary number obtained from said converting.
4. The method of claim 3, including performing Welch decompression of the output binary signals obtained from said producing.
5. Electronically implemented apparatus for preparing binary data for transmission on data communication means which restricts the number of acceptable characters for transmission comprising: compression means for compressing the binary data to be transmitted using Welch compression and producing compressed binary signals corresponding thereto; conversion means for converting each of a predetermined plurality of bits of said compressed binary signals into a predetermined plurality of digits in a predetermined base; means for deriving a corresponding acceptable character for each digit produced by said conversion means, each digit of said predetermined base corresponding to a different acceptable character; and means producing binary signals representing the derived acceptable characters for transmission on said data communication means.
6. In a data communication system, the combination comprising: compression means for compressing the binary data to be transmitted using Welch compression and producing compressed binary signals corresponding thereto; binary data communication means which restricts the number of acceptable characters for transmission; conversion means for converting each of a predetermined plurality of bits of said compressed binary signals into a predetermined plurality of digits in a predetermined base; means for deriving a corresponding acceptable character for each digit produced by said conversion means, each digit of said predetermined base corresponding to a different acceptable character; means producing binary signals representing the derived characters; means for transmitting the binary signals representing the derived characters on said communication means; means for receiving binary signals from said data communication means; means for deriving digits in said predetermined base from the received binary signals; conversion means for converting each of said predetermined plurality of derived digits in said predetermined base into a corresponding binary number having said predetermined plurality of bits; means for producing output binary signals representing each binary number obtained from said last mentioned conversion means; and means providing for Welch decompression of the output binary signals provided by said means for producing.
7. The invention defined by claim 1, 2, 3, 4, 5 or 6, wherein said predetermined plurality of bits comprises 32 bits.
8. The invention defined by claim 7, wherein said predetermined plurality of digits in said predetermined base comprises 5 digits.
9. The invention defined by claim 8, wherein said predetermined base is 85 or greater.
10. The invention defined by claim 9, wherein the number of acceptable characters is equal or greater than said predetermined base.
11. The invention defined by claim 10, wherein said predetermined base is 85.
12. The invention defined by claim 1, 2, 3, 4, 5 or 6, wherein the derivation of a corresponding acceptable character for each digit in said predetermined base is accomplished by using said digit as an index into the set of acceptable characters.
13. The invention defined by claim 1, 2, 3, 4, 5 or 6, wherein the conversion of binary into said predetermined base is accomplished using an iterative dividebyradix approach.
Description:
._ /) _

BINARY DATA COMMUNICATION SYSTEM

BACKGROUND OF THE INVENTION

This invention relates to an improved method for sending binary data using a data communication system, which restricts the number of data characters which are acceptable for transmission such as electronic mail (E-mail).

E-mail systems are well known in the art for communicating data from one location to another location. Typically, data sent by electronic mail is in the form of 8-bit characters or bytes (a byte comprises 8-bits). It will be understood that 2 8 or 256 different characters may be represented by these 8-bit characters. However, because particular ones of these 256 characters are reserved by the

E-mail system for data communication protocol purposes, only the remaining ones of these 256 characters can be used for transmitting data, which are typically those which are present on the keyboard of a terminal, such as the keyboard of a personal computer. These data characters are typically referred to as displayable, printable or text characters. The number of data characters which can be transmitted by an E-mail system may be further restricted, since data communication lines frequently support only 7-bit codes, reserving the eighth bit as a parity check. In such case, only a total of 128 characters (data plus control characters) are available.

Since E-mail systems typically permit transmission of only a limited number of the 256 possible values provided by an 8-bit (one-byte) representation, as explained above, a problem is presented when it is desired to use E-mail for transmitting binary data, such as, for example, the contents of a file stored in the memory of a personal computer. Accordingly, when E-mail is to be used for such purpose, the binary file has to be modified so that its 256 8-bit data characters are converted into the particular subset of data characters which the E-mail system is able to deal with. Known methods for this purpose have the disadvantage of requiring the transmission of a significant number of extra bits and a relatively complicated implementation.

SUMMARY AND OBJECTS OF THE INVENTION

It is accordingly, a broad object of the present invention to provide new and improved methods for transmitting binary data using a transmission system, such as E-mail, which restricts the number of data characters which are acceptable for transmission.

A more specific object of the invention, in accordance with the foregoing object, is to provide a new and improved method for converting binary data into characters acceptable to the transmission system. Another object of the invention, in accordance with the foregoing object, is to provide a new and improved method for reconverting received binary data into the original binary data prior to conversion.

A further object of the invention, in accordance with the foregoing objects, is to provide methods which can be relatively simply implemented.

A still further object of the invention, in accordance with the foregoing objects, is to provide methods which require a minimum number of extra bits required to be transmitted.

In a particular preferred embodiment of the invention, the above objects are accomplished by employing a method which considers the binary data to be transmitted as

being comprised of a sequence of 32-bit characters, and then performs a base-85 conversion on these 32-bit characters to produce acceptable characters for transmission. At the receiving end, the received characters are converted back to the original binary data.

The specific nature of the invention as well as other objects, features, advantages and uses thereof will become evident from the following detailed description along with the accompanying drawings.

BRIEF DESCRIPTION OF THE DRAWINGS

Fig. 1 is a block diagram illustrating an implementation of the present invention.

Fig. 2 is a flow chart illustrating the conversion of a binary file into ASCII for E-mail transmission in accordance with the invention.

Fig. 3 is a flow chart illustrating the conversion of ASCII received from an E-mail system back into the original binary file in accordance with the invention.

DETAILED DESCRIPTION OF A PREFERRED EMBODIMENT

Like numerals and characters refer to like elements throughout the figures of the drawings.

Before proceeding to a detailed description of a preferred embodiment of the invention, it will be helpful to initially consider two well known methods for transmitting binary data using E-mail transmission.

Perhaps the most common known way of converting binary data for E-mail transmission is to use a 4-bit to 8-bit conversion method in which the binary data to be transmitted is considered to be comprised of a sequence of 4-bit hex digits, each hex digit being converted into its ASCII 8-bit representation for transmission purposes. For example, binary data comprises of the 8-bits 01000101 is represented as two 4-bit hex digits 0100 and 1010, which correspond to hex digits "4" and "A", respectively. The ASCII equivalent of "4" is 34 and the ASCII equivalent of "A" is 41. Thus, to transmit the original 8-bit binary data 01000101 using this 4-bit to 8-bit conversion system, the following two 8-bit ASCII characters are transmitted respectively corresponding to 34 and 41:

001101000100001

At the receiving end, the received ASCII numbers 34 and 41 are converted back to the original 8-bit string 01000101.

It will be understood that the 4-bit to 8-bit conversion method described above has the advantage of requiring use of only the 16 displayable hex digits "0" through "9" and "A" through "F". However, as will be evident from the above example, this method presents the disadvantage of requiring that twice as many bits be transmitted as were present in the original file.

Another well known approach is to use a 6-bit to 8-bit conversion method in which the binary data to be transmitted is considered to be comprised of a sequence of 6-bit numbers. Since 2 6 = 64, these 6-bit numbers can be used as an index into a set of 64 characters which are acceptable to the E-mail transmission protocol. For example, assume that the following 64-element set is acceptable to the E-mail system:

ABc EFGHIiJKLMNOPQRSTÏ‹V YZ abcdefghijklmnopqrs tuvwxyz (I)

0123456789-/

wherein the first character "A" is represented by the 6-bit number 000000, the second character "B H is represented by the 6-bit number 000001 and so on, until the sixty-fourth character / is reached which is represented by the 6-bit number 111111 - 63.

An example of this 6-bit to 8-bit conversion will now be presented. For this example, it will be assumed that

the binary data to be transmitted comprises three 8-bit bytes (24-bits) as follows:

001101010100111100011100 (2)

In accordance with the 6-bit to 8-bit conversion method being described, the three 8-bit bytes shown in (2) above are considered to be four 6-bit numbers as follows:

001101010100111100011100 (3)

The values represented by these four 6-bit numbers in (3) above are used as indexes into the set of (1) above as follows: the first 6-bit number 001101 in (3) above has the value 13 and thus corresponds to the thirteenth character H N" of the 64-character set shown in (1) above; the second 6-bit number 010100 in (3) above has the value 20 and thus corresponds to the twentieth character "U" of the set shown in (1) above; the third 6-bit number 111100 in (3) above has the value 60 and thus corresponds to the sixtieth character "8" of the set shown in (1) above; and the fourth 6-bit number 011100 in (3) above has the value 28 and thus corresponds to the twenty-eighth character "c" of the set shown in (1) above.

Based on the above indexing, the original 24 bit binary data in (2) above is represented by the following four displayable characters of the character set shown in (1) above:

- 9 -

N U 8 c (4)

These four characters N U 8 c are then transmitted by the E-mail system using their respective ASCII 8-bit equivalents set forth in hex below:

4.E 553863

which in binary corresponds to:

01001110010101010011100001100011

5 In accordance with the present invention, a new and improved approach is provided for sending binary data using E-mail. This new approach requires sending significantly fewer binary bits than is possible using presently known methods. More specifically, in the preferred embodiment of

10 this new approach to be described herein, each 4-bits of binary data requires that only 5-bits be transmitted by the E-mail system. This compares with the requirement of sending 8-bits for every 4-bits of binary data in the first previously described system, and 6-bits for every 4-bits of binary data

15 in the second previously described system.

The new and approved approach of the present invention will now be considered with respect to a particular

preferred embodiment which uses a set containing the following

85 characters which are acceptable to the E-mail system:

ABCDEFGHIJIOJmOPQRSTUVWXYZ abcdefghijklmnopq∑stuvwxyz 01234567890 ^

In the preferred embodiment, the binary data to be transmitted is considered to be comprised of sequences of 32-bit numbers. For example, assume that the following

8-bytes 64-bits of binary data (represented in hex) is to be transmitted:

35 AF 1C 2D 17 A2 B4 SC (6)

In the preferred embodiment this binary data in (6) above is considered as two 32-bit numbers as follows:

354F2C2.D YJA2B49C ( 7) The manner in which each of the two 32-bit numbers in (7) above is transmitted in the preferred embodiment of the invention will be illustrated using the first 32-bit number 354F1C2D.

For the purposes of the preferred embodiment, the first 32-bit number 354F1C2D in (7) above is converted into a base-85 number, that is, a number having a radix of 85. One way for accomplishing this conversion is to employ an iterative divide-by-radix approach, such as described in U.S. Patent No. 4,342,027, using the following divide-by-radix iterative equation for converting a number N represented in a first base

(radix r,) into a number M in a second base (radix r 2) :

-^-O (8 )

where j=l, 2,....n, Q 0 (obtained when j=l) is the number N in radix ri which is to be converted to the number M in radix r 2 , r 2 is radix r 2 expressed in radix r x ; Q j is the quotient of the j ch iteration: n is the number for which the quotient Q j =o, b j is the remainder of the j 1 * division and is also the converted digit in radix r 2 ; and M in radix r 2 is fo.rmed by assembling the b j remainders for j-l,2,....n such that M=b n ....b 2 b : .

To illustrate how equation (8) above is used, the 32-bit hex number 354F1C2D in (7) above will be converted into a base-85 number using its decimal (base-10) equivalent given below, since decimal division is easier to understand:

(354F1C2D) hex = (894377005) decimal

Using equation (8), iterative division for base-85 is performed on the decimal number 894377005 as follows:

(894377005) * 85 = 10522082 + 35 remainder

(10522082) + 85 = 123789 + 17 remainder

(123789) + 85 = 1456 + 29 remainder (9) '

(1456) + 85 = 17 + 11 remainder

(17) + 85 = 0 + 17 remainder Assembling the remainders then provides the following five base-85 digits:

1711291735 (10)

As in the 4-bit to 6-bit conversion previously described, the digits in (10) above are used as indexes into the 85 character set shown in (5) above, wherein A is 0, B is 1, and so on, until the 85th character / is reached which corresponds to 84. Accordingly, the five base-85 digits 1711 29 17 35 in (10) above are represented for transmission

purposes by the following five characters of the character set shown in (5) above:

R L d R j (11)

Thus, to transmit the first 32-bits of the binary data shown in (6) above, the five characters R L d R j in (11) are transmitted by the E-mail system using their respective ASCII 8-bit equivalents set forth in hex below:

524C64526A

which in binary corresponds to:

0101001001001100011001000101001001101010

It will thus be evident that the above described conversion resulting from the preferred embodJLment of the invention permits the original 32-bits of binary data to be transmitted on the E-mail system using only 40-bits, thereby requiring an expansion of only 4 to 5 or 25% over the original binary data.

The validity of the above described base-85 conversion for E-mail transmission will be understood from the following relationship:

84 5 < 2 32 -l < 85 5 (12)

The middle te.rm (2 32 -l) in the above relationship (12) is the largest value a 32-bit (unsigned) integer can attain. The inequality on the right proves that any 32-bit integer can be represented by no more than 5 base-85 integers. In particular, this guarantees that the last quotient produced using equation (8) above will always be less than 85. The inequality on the left in " the above relationship (12) proves that a character set comprised of at least 85 acceptable characters satisfies this condition. It is also possible to achieve the desired 4 to 5 expansion using a base greater than 85, in which case the min.imum number of acceptable characters

required is changed accordingly. For example, if a base of 90 is employed, the minimum number of acceptable characters required would be 90.

At the receiving end of the E-Mail system, the received ASCII characters, 52 4C 64 52 6A respectively, corresponding to characters R L d R j of the character set in (5) above are used as an index to derive the respectively corresponding base-85 digits 17 11 29 17 35 shown in (10) above. These base-85 digits are then converted back into the first 32-bit number 354F1CD2D shown in (7) above, which may be accomplished using equation (8) above.

Although the above example of the preferred embodiment has been concerned with only the first 32-bits 354F1CD2D of the hex-represented binary data shown in (6) and (7) above, it will be understood that each following 32-bits of the binary data to be transmitted is handled in a like manner.

Reference is next directed to Fig. 1, which illustrates a preferred implementation of the invention in which the above described 85-base conversion approach for converting binary data into ASCII for E-Mail transmission is combined with the binary compression and decompression system disclosed in the commonly assigned U.S. Patent No. 4,558,302 issued December 10, 1985, Terry A. Welch, inventor. The disclosure in this patent is hereby incorporated herein. The compression and decompression approaches disclosed in this patent are typically referred to as the Welch compression and decompression algorithms.

As shown in Fig. 1, each end of a two-way E-mail communication system 10 is provided with a Welch compressor 12 and a Welch decompressor 14, along with an E-Mail transmitting converter 16 and an E-Mail receiving converter 18. Binary data to be transmitted is first compressed by the Welch compressor 12 and the resulting compressed binary data then applied to the E-Mail transmitting converter 16, which

converts the Welch-compressed binary data using 85-base conversion into ASCII for E-Mail transmission, as described above.

Received ASCII is applied to the E-Mail receiving converter 18, which converts the ASCII into binary using 85-base to binary conversion as described above. The binary data at the output of the E-Mail receiving converter 18, which corresponds to the Welch-compressed data at the output of the Welch compressor 16, is then applied to the Welch decompressor 18, which produces the original binary data.

The flow chart in Fig. 2 illustrates how binary data from a binary file is converted into ASCII for E-Mail transmission, while the flow chart in Fig. 3 illustrates how received ASCII is converted back into the original binary file. Examples of how the Welch compression and decompression may be performed can be found in the aforementioned U.S. Patent No. 4,558,302. An example of a program in C-language which may be employed for performing the remaining portions of Figs. 2 and 3, that is, the conversion of binary data into ASCII using binary to 85-base conversion, or for performing the conversion of received .ASCII back into binary using base-85 to binary conversion as shown in APPENDIX I.

INTENTIONALLY

LEFT

BLANK

APPENDIX I

TITLE

A MAIL FILE CONVERSION UTILITY FOR PC FILES

FILE ID: BINMAIL.C

#include <stdlib.h> tinclude <string.h> #include <signal.h> tinclude <stdio.h> tinclude <bios.h> #include <dos.h> tinclude <io.h> #include <sys/types.h> #include <sys/stat.h> char my_name[] = "BINMAIL"; char my_release[] = "2.00";

#define THIS RELEASE 200

typedef enura {

LITERAL, OPTION } PTYPE; typedef struct { char *s; PTYPE type; } P RM; typedef struct { int max; int total; int names; } PARM_INFO;

#define MAX_PARMS 10 PA.RM parm[MAX_PARMS] ; PARM_INFO pinfo={MAX_PARMS, 0, 0}; char *edit; typedef unsigned char BYTE;

#define ESC OxlB

#define CR OxOD

#define SPACE 0x20

#define CtrlC 0x03

#define beep putch 7) int receiving, overwrite, nonstop;

#define BIN_BUFFER_SIZE_100 51

#define TEXT_BUFFER_SIZE_100 ((4*BIN_BUFFER_SIZE_100)/3)

#define BIN_BUFFER_SIZE_200 56

#define TEXT_BUFFER_SIZE_200 ((5*BIN_BUFFER_SIZE_200)/4)

tdefine

tdefine )

BYTE text_buffer[80+TEXT_BUFFER_SIZE]; /* Extra for receiving */

BYTE bin_buffer[BIN_BUFFER_SIZE]; char original_dos_id[13]; long original_file_size; unsigned original_file_date; unsigned original_file_time;

FILE *fin, *fout; char fin_id[_.MAX_PATH], fout_id[_MAX_PATH]; char *fin_id_given,

*fout_id_given=""; char *id_string = "tEag"; int version; int valid_versions[] = { 100, 200, 0 };

#define t64 t85 #define t64_ t85_

BYTE t85[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" "0123456789() H

"\"[]{}<>:;,.+=#$%&*-_/";

BYTE t85_ [256]; int record, cksum_errors;

BYTE cksura; /*

*/ void pascal copyrite(char *who_is, char *which_is)

{ f rintf(stderr,

"\nFile Conversion Utility %s Version %s (%s)\n", who_is,which_is,_TIMESTAMP_); fprintf(stderr,"Copyright (c) 1990 Unisys Corporation\n") ; fprintf(stderr,"All Rights Reserved\n") ; ) /*

vo*/id pascal invalid_input(void)

{ static char *instructs[] =

{ 11 Switch Command",

——————————————————— ——————————————————_—†”———_»

"/R Recreate a file from a file which is in BINMAIL ", encoded format. If this switch is not set, the ", input file will be copied to the output file and",

" encoded.\n",

"/O Overwrite the output file if it exists.\n",

"/N Do not pause if checksum errors are encountered ", (/R set).\n",

"/V:nnn Encode with version level nnn algorithm ", (/R not set) .\n",

NULL

} char **line; printf("\a\nlnvalid Input Parameters\n") ; printf(

"Syntax: %s [switches] [d:][path]filename " "[[d:][path]filename]\n\n", my_name)? for(line=instructs;*line!=NULL;line++)printf("%s\n",*line) ; exit(l)f } /* invalid_input */

/*

*/ void c_break(void)

{ static char str[] = "\r\nProcess terminated at user "

"request\r\n"; char *ptr; union REGS inregs, outregs; signal SIGINT, SIG TGN ); inregs.h.ah = OxOe; inregs. .bx = 0; ptr = str; while( *ptr )

{ inregs.h.al = *ptr++; int86( 0x10, Sinregs, δoutregs );

} exit(l);

} /*

*/ unsigned pascal getkey(void)

/* Reads character from the extended keyboard */ union { unsigned code; struct {

BYTE low, high; } bytes; } key; key.code=_bios_keybrd(_KEYBRD_READ) ; if(key.bytes.lσw==0xE0)key.bytes.low=0; /* Clear flag */ if(key.bytes.low)key.bytes.high=0; /* Clear scan code */ return(key.code) ; } /* getkey */

/*

*( void pascal setup(int argc, char **argv ) int i, names_given; if ( parse_parms (argc,argv,my_name,parm,&pinfo) ) invalid_input ( ) ; if ( pinfo. names==0 ) invalid_input() ; names_given=0 ; receiving=0; overwrite=0; nonstop=0; version=THIS_RELEASE; for(i=0;i<pinfo.tota1;i++)

{ edit=parra[i] .s; if( parm[i] .type==OPTION )

{ switch( toupper(*edit) )

{ case 'R': i f ( set_ f lag (edit , &receiving) ) invalid_input () ; break; case if ( set_f lag ( edit , & overwrite) ) invalid_input () ; break;

case ' N » : if( set_flag(edit,Snonstop) ) invalid__input() ; break; case 'V r : break rSi ° n=atθiCedit+2 ) == ° ) inv alid_in P ut() ; default:

invalid_input() ; } /* End CASE */ else /* LITERAL */ { if( strpbrk(edit,"*?")1=NULL) { printf("\a\nWildcards not permitted in "

"filename: \"%s\"\n",edit); exit(l) ;

} switch( names_given )

{ case 0: fin_id_given=edit; break; case 1: fout_id_given=edit; break; default: invalid_input() ;

} names_given++;

} } } /*

*/ void pascal verify_release(void)

{ int *v; for(v=valid_versions;*v;v++)if( *v==version )return; printf("\a\nVersion Not Supported: %d\n",version) ; exit(l); } /*

*/ void _fastcall four2three(BYTE *in_four, BYTE *out_three)

{

static BYTE wb;

/* */ /* aaaaaa aabbbb bbbbcc cccccc */ out_three[0] = t64_[in_four[0]]«2; wb = t64_[in_four[l]]; out__three[0] += wb»4; ~* out_three[l] = wb«4; wb = t64_[in_four[2]]; out_three[l] += wb»2; out_three[2] = (wb«6) + t64_[in_four[3]];

} /*

*/ void _fastcall three2four(BYTE *in_three, BYTE *out_four)

{

/* 000000001111111122222222 */ /* aaaaaabbbbbbccccccdddddd */ out_four[0] = t64[ in_three[0]»2 ]; out_four[l] = t64[ ( (in_three[0]&0x03)«4)

+ (in_three[l]»4) ]; out_four[2] = t64[ ( (in_three[l]&0x0f)«2)

+ (in_three[2]»6) ]; out_four[3] = t64[ m_three[2]&0x3f ];

} /*

*/ void _fastcall five2four(BYTE *in_five, BYTE *out_four)

{ static int i; static unsigned long xul; xul=85*t85_[in_five[0]]+t85_[in_five[l]]; for(i=2;i<5i++)xul=85*xul+t85_[in_five[i]] ;

* (unsigned long *) out four = xul;

} /*

*/ void _fastcall four2five(BYTE *in_four, BYTE *out_five)

{ static ldiv_t ldivres; static div_t divres; static long xl; static int xi;

static int i; static unsigned long xul; xul = * (unsigned long *) in_four;

/* ldiv accepts only signed variables */ if( in_four[3]&0x80 )

{ xl=xul/85; out five[4]=t85[ int) (xul-85*xl) ] ; i=3;

> else

{ xl=xul; i=4;

} while( xl > (unsigned) (-1)»1 )

{ ldivres=ldiv(xl,85L) ; out_five[i]=t85[(int) Idivres.rem]; xl=ldivres.quot; i~; > xi=(int)xl; for(;;)

{ divres=div(xi,85) ; out_five[i]=t85[divres.rem]; if i—1 )

{ out_five[0]=t85[divres.quot]; return;

} xi=divres.quot; i—;

} > /*

*/ void pascal fullpath(char *gname, char *surname, char *nname)

{ struct stat filestat; int len; unsigned current_drive_no.

given_drive_no, drivecount; char cwd[_.MAX_PATH]; char work[_MAX_PATH]; char nname_drive[_MAX_DRIVE] ; char nname_dir[_MAX_DIR]; char nname_fname[_MAX_FNAME] ; char nname_ext[_MAX_EXT]; len=strlen( gname );

/* Response is 1-relative */

_dos_getdrive( ¤t_drive_no ); if( len>l && gname[l]=a=' : ' )

{ strcpy( nname, gname ); given_drive_no=toupper(nname[0])-( Α'-l) ;

} else

{ sprintf( nname, "%c:%s", current_drive_no+( » A*-1) , gname ) ; given_drive_no=current_drive_no; len+=2; } if( len==2 I j nnametlen-l^'W' || stat( nname, fifilestat )==0 && (filestat.st_mode&S_IFDIR)==S_IFDIR )

{ if( surname==(char *)NULL ) invalid_input() ; if( len>2 && nname[len-l] !='\\* )nname[len++]=•\\* ; strcpy( nna e+len, surname ); }

_splitpath( nname, nname_drive, nname_dir, nname_fname, nname_ext ) ; if( current_drive_no != given__drive_no )

_dos_setdrive( given_drive_no, Sdrivecount ) ; getcwd( cwd, _MAX_PATH ); /* To restore later */ if( *nname dir )

i if( (Ien=strlen(nname_dir)-1)>0 SS nname_dir[len]== , ' ) nname ^ dir[len]=0; chdir( nname__dir ) ; getcwd( work, _MAX__PATH ) ; chdir( cwd ) ; > if( current_drive__no != given_drive_no )

_dos_setdrive( current_drive__no,Sdrivecount );

/* * Now reconstruct the full path name

*/

_makepath( nname, nname_drive, *nname_dir ? work+2 : cwd+2, nname_fname, nname_ext ) ; strupr( nname ) ;

} /*

*/ void pascal open_output_file(void)

{ unsigned ch; if( stricmp( fin__id, fout_id )==0 )

{ print ("\a\nCannot copy a file to itself: %s\n",f in_id) ; exit(l) } if( overwrite==0 && access(fout_id,00)==0 ) { printf Present. " ch = getkey ) ; if( toupper( ch )=='Y* )

{ printf("Y\n") ;

} else printf("N\nFile Not Written\n") ; exit(l) ; }

} if( (fout=fopen(fout_id,"wb") )==NULL)

{ printf("\a\nCannot Open Output File: %s\n",fout_id) ; exit(l) ; } if( signal( SIGINT, c_break ) == SIG_ERR )

{ fprintf( stderr, "Couldn't set SIGINT\n" ); abort() ; }

} /*

*/ char *name_of_day(unsigned mo, unsigned day, unsigned yrs /* Years since 1980 */ )

{ static char *names[] = {"Tue", "Wed", "Thu", "Fri",

"Sat", "Sun", "Mon"] static int four_years[] = { 0, 366%7, 731%7, 1096%7 }; static int days_so_far[ ] = { 0, 31%7, 59%7, 90%7, 120%7, 151%7, 181%7, 212%7, 243%7, 273%7, 304%7, 334%7}; int leap_index; o—; /* Make 0-relative */ day—; /* Make 0-relative */ yrs%=28; /* Day and date both will repeat in 28 years */ leap_index = yrs&3 return names[ ( ( yrs»2 ) * (1461%7)

+ four_years[ leap_index ]

+ days_so_far[ mo ]

+ ( mo>l SS leap_index==0 )

+ day ) % 7 ];

} /*

*/ void pascal check_disposition(void)

{ const char pause__msg[] = "(<Enter> to continue;"

" <Space> to continue nonstop;" " <Esc> to abort)"; unsigned ch;

printf( pause_msg ); for(;;)

{ ch = getkey() i switch( ch )

{ case ESC: fcloseall() ; unlin (fout_id) ; case CtrlC: raise( SIGINT ) ; case SPACE: nonstop=l; case CR: printf("\n") ; return; } /* End CASE */ beep; } } /*

*/ void pascal checksum_error(void)

{ printf("\nChecksum Error: Record No %d\n",record); if( nonstop==0 )check_disposition() ; c sum_errors++;

> /*

*/ void pascal write_error(void)

{ printf("\a\nError Writing File: %s\n",fout_id) ; fcloseall() ; unlin (fout_id) ; exit(l) ;

> /*

*/ void pascal text_to_binary(void)

{ static char *mo_name[] = { "Jan", "Feb", "Mar", "Apr",

"May", "Jun", "Jul", "Aug",

"Sep", "Oct", "Nov", "Dec" }; char test_id_string[80];

BYTE *text__ptr; char *am_pra;

long bytes_to_go; fullpath( fin_id_given, (char *)NULL, fin_id ); if( (fin=fopen(fin_id,"rt"))==NULL )

{ printf("\a\nCannot Open Input File: %s\n",fin_id) ; exit(l) ; } while(l)

{ if( fgets(text__buffer,80,fin)==NULL ) printf("\a\nlnvalid Input File Format\n") ; exit(l) ;

} if( sscanf(text_buffer,

"%s %d %s %ld %x %x", test_id__string,

Sversion, original_dos_id,

&original_file_size,

Soriginal_file_date, original_file_time )==6 && strcmp(test_id_string,id_string)==0 )

{ verify_release() ; break; }

} fullpath( fout_id_given, original_dos_id, fout_id ); open_output_file() ; yr=original_file_date; day=yr&0xlF yr»=5; mo=yr£0x0F; yr»=4; hr=original_file__time; sec=(hrS0xlF)«1; hr»=5; min=hr&0x3F hr»=6; am_pm = hr<12 ? "am" : "p " ; if( hr>12 ) hr-=12; else if( hr==0 )hr=12; printf("\n%s (%ld bytes: %s %s %u, %u at %u:%02u:%02u %s)\n", original_dos_id, original_file_size, name_of_day(mo,day,yr) , mo__name[mo-l] ,day,1980+yr, hr,min,sec,ara_pm ) ; printf("\nDecoding (%d) \"%s\" as \"%s\" ... ",version, fin_id,fout_id); memset(t85_,0,256) ; for(i=0;i<85i++)t85_[t85[i]]=i; bytes_to_go=original_fi1e_size; record=l; cksum_record=l; cksum_errors=0; switch( version ) { /* */ case 100:

/* */ while( bytes_to_go && fgetsCtext_buffer,TEXT_BUFFER_SIZE_100+80,fin)

!= NULL )

/*

/ while( bytes_to_go && fgets(text_buffer,TEXT_BUFFER_SIZE_200+80,fin) 1= NULL )

{ record++; text_ptr=text_buf fer+strspn(text_buf fer, " ") ; if( *text_ptr=='\n' )continue; cksum_record++; for(i=0,j=0;i<TEXT_BUFFER_SIZE_200;i+=5,j+=4) five2four(text_ptr+i,binjouffer+j) ; cksum=cksura_recordS0xff; for(i=0;i<BIN_BUFFER_SIZE_200-l;i++) cksum Λ =bin_buffer[i]; if( bin_buffer[(BIN_BUFFER_SIZE_200-l)] != cksum ) checksum_error( ); bytes_this_write=min( bytes_to__go,

(BIN_BUFFER_SIZE_200-1) ); if( fwrite(bin_buffer,bytes_this_write,l,fout)==0 ) write_error( ); bytes_to_go-=bytes__this_write;

} break;

/*

End cases

*/

} if(bytes_to_go) printf("\a\nlnvalid File Size\n\n") ; exit(l) ;

} f flush (fout) ;

_dos_setftime(fileno(fout),original_file_date, original_file_time); fclose(fout) ; printf("Done\n%d Checksum Errors\n",cksum_errors) ;

} /*

*/ void pascal binary_to_text(void)

{ int i, j; char default_output_name[13]; struct find_t ffblk; verify_release() ; fullpath( fin_id_given, (char *)NULL, fin_id ); if( _dos_findfirstCfin_id,_A_NORMAL|_A_RDONLY,&ffblk) || (fin=fopen(fin_id,"rb"))==NULL )

{ printf("\a\nCannot Open Input File: %s\n",fin_id) ; exit(l) ; } strcpy ( def ault_output_name , ffblk. name ) ; if ( (edit=strchr( default_output_name, ' . ' ) )

1= (char *)NULL ) *edit=0; strcat( default_output_name,".BMA" ); fullpath( fout__id_given, default_output_name, fout_id ) ; open_output_file() ; printf("\nEncoding (%d) \"%s\" as \"%s\" ...", version, fin_id, fout_id); memset(text_buffer,t85[0],TEXT_BUFFER_SIZE) ; fprintf(fout,

"%s %d %s %ld %04X %04X\r\n", id string,

version, ffblk.name, ffblk.size, ffblk.wr_date, ffblk.wr time record=l; switch( version ) {

/* */ case 100:

/* */ while(fread(bin_buffer,l,BIN_BUFFER_SIZE_100,fin)>0)

{ record++; for(i=0,j=0;i<BIN_BUFFER_SIZE_100;i+=3,j+=4) three2four(bin_buffer+i,text_buffer+j) ; cksum=record&Oxff for(i=0;i<BIN_BUFFER_SIZE_100;i++) cksum=(cksum+i*bin_buffer[i])&0xff if( fwrite(text_buffer,TEXT_BUFFER_SIZE_100,1,fout) == 0 I I fprintf(fout,"%02X\r\n",cksum) 1= 4 ) write_error() ;

} break;

/* */ case 200:

/* */ while(fread(bin_buffer,l, (BIN_BUFFER_SIZE_200-1) ,fin)>0)

{ record++; cksum=record&0xff for(i=0;i<BIN_BUFFER_SIZE_200-l;i++) cksum Λ =bin_buffer[i]; bin_buffer[ (BIN_BUFFER_SIZE_200-1) ]=cksum; for(i=0,j=0;i<BINJBUFFER_SIZE_200;i+=4,j+=5) four2five(bin_buffer+i,text_buffer+j) ; if( fwrite(text_buffer,TEXT_BUFFER_SIZE_200,1,fout) ===== 0 I f fwrite("\r\n",2,l,fout) == 0 ) write_error() ;

} break;

/*

End cases

*/ } print ("Done\n%d Records Written\n",record) ;

} /*

*/ void main(int argc, char **argv) { copyrite(my_name,my_ > release) ; setup (argc, argv) ; if(receiving) text_to__binary() ; else binary_to_text() ; exit(0) ; }

I t is to be understood that the present invention is not limited to the particular implementations and/or examples disclosed herein, and is accordingly to be considered • as including all modifications and variations coming within the scope of the appended claims.