#!/bin/sh # This is a shar archive. # The rest of this file is a shell script which will extract: # # 4_11.c 4_11.cmp 4_11.in 4_11b.c makefile # # To extract the files from this shell archive file simply # create a directory for this file, move the archive file # to it and enter the command # # sh filename # # The files will be extracted automatically. # Note: Do not use csh. # # Archive created: Mon Jul 30 23:00:00 EDT 1990 # echo x - 4_11.c sed 's/^X//' > 4_11.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // Encrypt input with provided key // using simple XOR algorithm. // No key or NULL key gives cleartext. #include #include #include int main(int argc, char **argv) { char c; switch (argc) { case 1: // no key: cleartext copy while (cin.get(c) && cout.put(c)) ; break; case 2: // provided key: encrypted copy char *key = argv[1]; int codelen = strlen(key); int i = 0; while (cin.get(c) && cout.put(c ^ key[i++])) i %= codelen; break; default: // usage error cerr << "usage: " << argv[0] << " [key] < clear > crypt\n"; return 1; } if (cout.bad()) error("output failed"); else if (!cin.eof()) error("input failed"); return 0; } !EOF! ls -l 4_11.c echo x - 4_11.cmp sed 's/^X//' > 4_11.cmp << '!EOF!'  STW @\yC E_y]  E _WdHA NVIPZI BU_9NSZ]C]\IBPW^ y  NBDQC~T]A ~ \]]N_BFS^FmU]P _IFXTR]AX _WIB T@V_KYS]X  T_RIB PQX~] No] NBP\@ _ ;_VIN[Z]\W@I_^~ESGN_ABS EA K\HRIBP\QX K][]_KTPJXE SC XBSXXEBR_K[SPIBRQE W@_K[[^X K[_G~   C_y  M_B P@J E _PK][]y] N ]KX TV _KBZ\ XX _YIc I GPI~  C_BPTX^GIdP_V_IAYTP\@ _][\XcFA NPBN _WDo] NB^]G~ST_9 T]N mUBG_ILQT\_X WPI B CE~-!4S@_IM[T B\Vo7;:CJBZ N\@N TF90* YC  @_ ;v|'HDT] d#~aYHNSWQ _@~-!4@Y_IM^T B\Vo7;:C N\KN TF90* YDCJ  M_ ;WK] N ]A9INX^W D^~ C EUAN CABEZ X BW]XdI L]CNc!+u EUCDSH8\] DUI !EOF! ls -l 4_11.cmp echo x - 4_11.in sed 's/^X//' > 4_11.in << '!EOF!' root::0:root other::1: bin::2:root,bin,daemon sys::3:root,bin,sys,adm adm::4:root,adm,daemon uucp::5:root,uucp mail::6:root daemon::12:root,daemon docx::21:pcor,russak,mds,dsl,jeremy,bwp,hansen,coleman,chu,jack guest::22: cmts::23:cmts,hansen,mzal mesa::24:mesa,hansen,mzal mrstat::26:cmts,hansen,mzal,bwp,danb,guidi,linda,dsl,eby,cbp,hlb,pcor,russak,clt,mds,aku,wpw,jack,cjs,bcc,paul,alf,sld,drr,jim,larry,jmt intest::27: arch::29:efh,maryrose,danb,russak,linda ots::31:butterly,fwl,daved,so,dwr,shorty,mjk,mjm,aj dbx::35: erm::37:efs,caf,jaa,mjb,lth,rlm games::50:hansen,autilio,avi news::51:netnews slan::57:slan,root sie::80: sable::117:sable dptg::88:emm,kbs,jak,ecc,jhc,jrw,rkh DOS-ash::92:msnet DOS--sh::93:msnet DOS-a-h::94:msnet DOS-as-::95:msnet DOS---h::96:msnet DOS--s-::97:msnet DOS-a--::98:msnet DOS----::99:msnet exptools::90:exptools vm::100:vmsys pcor::102:pcor,russak,eth,jim,hansen,jack dx::880: OLD::1000:scy olympus::1100:olympus,aku tsys::1101:root,tadm !EOF! ls -l 4_11.in echo x - 4_11b.c sed 's/^X//' > 4_11b.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // Encrypt input with provided key // using simple XOR algorithm. // No key or NULL key gives cleartext. // stdio version #include #include #include int main(int argc, char **argv) { int c; switch (argc) { case 1: // no key: cleartext copy while (((c = getchar()) != EOF) && (putchar(c) != EOF)) ; break; case 2: // provided key: encrypted copy char *key = argv[1]; int codelen = strlen(key); int i = 0; while (((c = getchar()) != EOF) && (putchar(c ^ key[i++]) != EOF)) i %= codelen; break; default: // usage error (void) fprintf(stderr, "usage: %s [key] < clear > crypt\n", argv[0]); return 1; } if (ferror(stdout)) error("output failed"); else if (!feof(stdin)) error("input failed"); return 0; } !EOF! ls -l 4_11b.c echo x - makefile sed 's/^X//' > makefile << '!EOF!' CC= CC -I. -I../../CC ERROR= ../../error.o CFLAGS= +i -g all: 4_11 4_11b 4_11: 4_11.c $(CC) $(CFLAGS) 4_11.c -o 4_11 $(ERROR) 4_11b: 4_11b.c $(CC) $(CFLAGS) 4_11b.c -o 4_11b $(ERROR) OUT= 4_11a1.out 4_11a2.out 4_11b1.out 4_11a3.out 4_11a4.out 4_11b2.out CMP= 4_11.cmp 4_11.in 4_11a1.out: 4_11 4_11.in ; 4_11 < 4_11.in > 4_11a1.out 4_11a2.out: 4_11 4_11.in ; 4_11 testing123 < 4_11.in > 4_11a2.out 4_11b1.out: 4_11 4_11a1.out ; 4_11 testing123 < 4_11a1.out > 4_11b1.out 4_11a3.out: 4_11b 4_11.in ; 4_11b < 4_11.in > 4_11a3.out 4_11a4.out: 4_11b 4_11.in ; 4_11b testing123 < 4_11.in > 4_11a4.out 4_11b2.out: 4_11b 4_11a4.out ; 4_11b testing123 < 4_11a4.out > 4_11b2.out test: all $(OUT) $(CMP) cmp 4_11a1.out 4_11.in cmp 4_11a2.out 4_11.cmp cmp 4_11b1.out 4_11.in cmp 4_11a3.out 4_11.in cmp 4_11a4.out 4_11.cmp cmp 4_11b2.out 4_11.in echo tests done !EOF! ls -l makefile # The following exit is to ensure that extra garbage # after the end of the shar file will be ignored. exit 0