.ps32767,78.lm0.rm78.nhd 1 ENCRYPT .p8 ENCRYPT/KEY=["]string["] input-file-spec output-file-spec .b1 Omitted items will be prompted for. .p0 Encryption takes place according to the Data Encryption Standard, as implemented in the encrypt function of Whitesmiths' Portable C Runtime Library. .p0 The file may be decrypted using the companion DECRYPT utility or read with the aid of the C decrypt function (if you know the key!). .b1.nf.rm76 2 Qualifier /KEY .i8 /KEY=["]string["] .f.p0 The key is a 1- to 8- character string of any ASCII characters. If it is less than 8 characters long, it is padded with trailing spaces. .p0 Because C loses case information when fetching the command line, it is a restriction that all alphabetic characters are converted to upper case, even if the key string is enclosed in quotes ("). .p0 String quotes are necessary only when the key is given in the command line and contains any special characters. If it is supplied in response to an "__Key:" prompt, they should NOT be given except when they are part of the actual key. .b1 2 Parameters .b1.rm74 3 input__file .b1 The input file is an ASCII sequential text file. There is no default filetype. .b1 3 output__file .p0 The encrypted output file is a binary file in the following format: .b1.lm+8.nf record length contents ------ ------ -------- .nf.j ##1 ###2 first 2 bytes of the encryption of the key itself. .b1 ##2 ###9 blocks of 8 encrypted bytes, each followed by the #... number of bytes in the original block (always 8 .nj ##n except for the last block, which may be shorter). .b1.j #last ###9 8 dummy bytes plus 0, in case the last "real" .nj block was exactly 8 bytes long. .f.j.b1.lm0 2 Encryption__program .b1.rm76.f.j The following is a skeleton C program to encrypt a text file into the required form, using a fixed key "abcd####" (note trailing blanks):- .b1.lm+4.literal static TINY ks[16][8],data[40]; static TINY key[8] = {'a','b','c','d',' ',' ',' ',' '}; ... infile = open("file.txt",READ,0); /* Open input text file */ outfile = create("file.txt",WRITE,1); /* Open encrypted bin output */ bldks(ks,key); /* Build key schedule */ fwrite(outfile,encrypt(key,ks),2); /* Write encrypted key */ while ((data[8]=fread(infile,data,8))>0) fwrite(outfile,encrypt(data,ks),9); /* Write data blocks */ data[8] = 0; fwrite(outfile,data,9); /* Null terminator */ .eli.lm0.b1 2 Decryption__program .p0 The following is a skeleton C program to decrypt an encrypted file into the required form, using a fixed key "abcd####" (note trailing blanks):- .b1.lm+4.literal static TINY ks[16][8],data[40]; static TINY key[8] = {'a','b','c','d',' ',' ',' ',' '}; ... infile = open("file.enc",READ,1); /* Open binary encrypted file */ outfile = create("file.txt",WRITE,0); /* Open text decrypted output */ bldks(ks,key); /* Build key schedule */ encrypt(key,ks); /* Encrypt key itself */ fread(infile,data,2); /* Fetch key from file */ if (key[0] != data[0] || key[1] != data[1]) error("Wrong key\n",NULL); /* Error if not what expected */ while (fread(infile,data,9) > 0 && data[8] != 0) /* OK, read, decrypt,*/ fwrite(outfile,decrypt(data,ks),data[8]); /* and write out */ .eli.b1.lm0.rm78 1 DECRYPT .p8 DECRYPT/KEY=["]string["] input-file-spec output-file-spec .b1 Any items not given will be prompted for. .p0 Decryption takes place according to the Data Encryption Standard, as implemented in the encrypt function of Whitesmiths' Portable C Runtime Library. .p0 The file may have been encrypted using the companion ENCRYPT utility or written with the aid of the C encrypt function. .p0 See the HELP text on ENCRYPT for further information, including descriptions of the encrypted file, and example C programs to read and write encrypted files.