home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / diverses / text_cla / cpt.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-12  |  19.7 KB  |  923 lines

  1. //////////////////////////////////////////////////////////////////////// 
  2. //+ 
  3. //  Module Name:  cpt.cpp 
  4. // 
  5. //  Description:  CPT specific routines to EnCryPT data 
  6. //                 
  7. //                Method is 255 byte swap with optional convolutions 
  8. //                to increase strength of encryption. 
  9. // 
  10. //                Can be used on any file (text, binary, etc.) 
  11. // 
  12. //                NOTE:  Although this method will keep most people and 
  13. //                       most hackers from decoding your data, 
  14. //                       it is NOT intended for use on government or 
  15. //                       DoD data which requires specific security 
  16. //                       performance.   
  17. // 
  18. // 
  19. //  Include Modules Referenced:  cpt.h 
  20. // 
  21. //  Written by:  John Tal 
  22. // 
  23. // 
  24. //  Modification history: 
  25. // 
  26. //  Date         Engineer     Mod #          Modification Description 
  27. // 
  28. //  12-Feb-1992  Tal          v 1.0-001      Initial conversion to C++ 
  29. //- 
  30. //////////////////////////////////////////////////////////////////////// 
  31.  
  32.  
  33.   
  34. #include <stdio.h> 
  35. #include <stdlib.h> 
  36.  
  37. #include <memincs.h> 
  38. #include <cpt.h> 
  39.  
  40.  
  41.   
  42. //////////////////////////////////////////////////////////////////////// 
  43. //+ 
  44. // Function Name:   lpad 
  45. // 
  46. // Class:           STRUTIL_C 
  47. // 
  48. // Security:        Private 
  49. // 
  50. // Description:     Left pad a field with blanks 
  51. // 
  52. // Parameters 
  53. //    In:           str = string to pad 
  54. //                  width = width to pad 
  55. // 
  56. // Return Codes:    SHORT = C_OK always returned 
  57. // 
  58. // Written by:      John Tal 
  59. // 
  60. // 
  61. // Modification History: 
  62. // 
  63. //  Date         Engineer     Mod #          Modification Description 
  64. // 
  65. //  12-Feb-1992  Tal          v 1.0-001      Initial conversion to C++ 
  66. // 
  67. //- 
  68. //////////////////////////////////////////////////////////////////////// 
  69.  
  70. STRUTIL_C::lpad(CHAR * str,INT width) 
  71.     C_DEF_MODULE("STRUTIL_C::lpad") 
  72.  
  73.     INT i,w; 
  74.  
  75.     w = strlen(str); 
  76.  
  77.     /**************************************** 
  78.           if needs padding 
  79.     ****************************************/ 
  80.     if(width > w) 
  81.     { 
  82.        /*  move bytes */ 
  83.        /* 
  84.            123 
  85.            12    3 
  86.            1    23 
  87.                123 
  88.        */ 
  89.        for(i = 0; i < w; i++) 
  90.           str[width-i-1] = str[w-i-1]; 
  91.  
  92.        /*  pad with spaces */ 
  93.        for(i = 0; i < (width - w); i++) 
  94.           str[i] = ' '; 
  95.  
  96.        /*  mark end */ 
  97.        str[width] = '\0'; 
  98.     } 
  99.  
  100.     /**************************************** 
  101.           if needs truncating 
  102.     ****************************************/ 
  103.     if(width < w)    
  104.        str[width] = '\0'; 
  105.  
  106.     C_RETURN 
  107.  
  108.   
  109. //////////////////////////////////////////////////////////////////////// 
  110. //+ 
  111. // Function Name:   srep 
  112. // 
  113. // Class:           STRUTIL_C 
  114. // 
  115. // Security:        Public 
  116. // 
  117. // Description:     String replacement of characters 
  118. // 
  119. // Parameters 
  120. //    In:           ch = string to check 
  121. //                  dh = character to search for 
  122. //                  eh = character to replace with 
  123. // 
  124. // Return Codes:    SHORT = C_OK always returned 
  125. // 
  126. // Written by:      John Tal 
  127. // 
  128. // 
  129. // Modification History: 
  130. // 
  131. //  Date         Engineer     Mod #          Modification Description 
  132. // 
  133. //  12-Feb-1992  Tal          v 1.0-001      Initial conversion to C++ 
  134. // 
  135. //- 
  136. //////////////////////////////////////////////////////////////////////// 
  137.  
  138. SHORT STRUTIL_C::srep(CHAR * ch,CHAR dh,CHAR eh) 
  139.    C_DEF_MODULE("STRUTIL_C::srep") 
  140.  
  141.    INT i; 
  142.  
  143.    for(i = 0; i < strlen(ch); i++) 
  144.       if(ch[i] == dh) 
  145.          ch[i] = eh; 
  146.    
  147.    C_RETURN 
  148.  
  149.   
  150. //////////////////////////////////////////////////////////////////////// 
  151. //+ 
  152. // Function Name:   SetJob 
  153. // 
  154. // Class:           CPT_C 
  155. // 
  156. // Security:        Public 
  157. // 
  158. // Description:     Set Job type to CPT_CODE or CPT_DECODE 
  159. // 
  160. // Parameters 
  161. //    In:           Job type to set to 
  162. // 
  163. // Return Codes:    SHORT = C_OK always returned 
  164. // 
  165. // Written by:      John Tal 
  166. // 
  167. // 
  168. // Modification History: 
  169. // 
  170. //  Date         Engineer     Mod #          Modification Description 
  171. // 
  172. //  12-Feb-1992  Tal          v 1.0-001      Initial conversion to C++ 
  173. // 
  174. //- 
  175. //////////////////////////////////////////////////////////////////////// 
  176.  
  177. SHORT  CPT_C::SetJobType(INT iJob) 
  178.    C_DEF_MODULE("CPT_C::SetJobType") 
  179.  
  180.    iJobType = iJob; 
  181.  
  182.    C_RETURN 
  183.  
  184.   
  185. //////////////////////////////////////////////////////////////////////// 
  186. //+ 
  187. // Function Name:   MemoryKeyGen 
  188. // 
  189. // Class:           CPT_C 
  190. // 
  191. // Security:        Public 
  192. // 
  193. // Description:     Generate a key set in memory 
  194. // 
  195. // Parameters 
  196. //    In:           iConvolutionSet = set to generate keys for 
  197. // 
  198. // Return Codes:    SHORT = C_OK always returned 
  199. // 
  200. // Written by:      John Tal 
  201. // 
  202. // 
  203. // Modification History: 
  204. // 
  205. //  Date         Engineer     Mod #          Modification Description 
  206. // 
  207. //  12-Feb-1992  Tal          v 1.0-001      Initial conversion to C++ 
  208. // 
  209. //- 
  210. //////////////////////////////////////////////////////////////////////// 
  211.  
  212. SHORT  CPT_C::MemoryKeyGen(INT iConvolutionSet) 
  213.    C_DEF_MODULE("CPT_C::MemoryKeyGen") 
  214.  
  215.    unsigned top; 
  216.    INT f; 
  217.    INT i; 
  218.    UCHAR  hold_area[256]; 
  219.  
  220. #ifdef ANNOUNCE 
  221.    if(iSet == 0) 
  222.      printf("\nGenerating Keys - Please Stand By"); 
  223. #endif 
  224.  
  225.    for(i = 0; i < ASCIIBYTES+1; i++) 
  226.    { 
  227.       hold_area[i] = i; 
  228.       cBytes[CPT_ENCODE][iConvolutionSet][i] = -1; 
  229.    } 
  230.  
  231.    srand(iSet); 
  232.  
  233.    /* 
  234.    **  Use 'quick' randomizer 
  235.    **  It copies the top element that has not been selected when 
  236.    **  a duplicate random number is found. 
  237.    */ 
  238.  
  239.    for(top = 256; top > 0; top--) 
  240.    { 
  241.        f = (rand() % 256); 
  242.        cBytes[CPT_ENCODE][iConvolutionSet][top-1] = hold_area[f]; 
  243.        if(f != top-1) 
  244.           hold_area[f] = hold_area[top-1]; 
  245.    } 
  246.  
  247.    C_RETURN 
  248.   
  249. //////////////////////////////////////////////////////////////////////// 
  250. //+ 
  251. // Function Name:   CptUsrGetKeyData 
  252. // 
  253. // Class:           (Standalone) 
  254. // 
  255. // Security:        N/A 
  256. // 
  257. // Description:     Get key set parms from user 
  258. // 
  259. // Parameters 
  260. //    In:           pcSeedPathName = File being looked for 
  261. // 
  262. // Return Codes:    SHORT = FIO_OK = file exists 
  263. //                        = FIO_NO_FILE = file does not exist 
  264. // 
  265. // Written by:      John Tal 
  266. // 
  267. // 
  268. // Modification History: 
  269. // 
  270. //  Date         Engineer     Mod #          Modification Description 
  271. // 
  272. //  12-Feb-1992  Tal          v 1.0-001      Initial conversion to C++ 
  273. // 
  274. //- 
  275. //////////////////////////////////////////////////////////////////////// 
  276.  
  277. SHORT  CptGetKeyData(VOID) 
  278.    C_DEF_MODULE("CptGetKeyData") 
  279.  
  280.    INT keynum; 
  281.    INT i; 
  282.    CHAR  szKeyStr[CPT_KEYSTR_LEN + 1]; 
  283.    CHAR  szKeyFile[CPT_FILE_LEN + 1]; 
  284.    STRUTIL_C  cStrUtil; 
  285.  
  286.    printf("\n\n\nEnter Reference Number For This Key "); 
  287.    scanf("%d",&i); 
  288.    sprintf(szKeyStr,"%d",i); 
  289.    cStrUtil.lpad(szKeyStr,4); 
  290.    cStrUtil.srep(szKeyStr,' ','0'); 
  291.  
  292.    cCpt.SetKeyStr(szKeyStr); 
  293.  
  294.    strcpy(szKeyFile,"key_"); 
  295.    strcat(szKeyFile,szKeyStr); 
  296.    strcat(szKeyFile,".cpt"); 
  297.  
  298.    cCpt.SetKeyFile(szKeyFile); 
  299.  
  300.    printf("\nEnter Convolutions (Usally 1, higher = tighter security) "); 
  301.    scanf("%d",i); 
  302.  
  303.    cCpt.SetConvolutions(i); 
  304.  
  305.    C_RETURN 
  306.   
  307. //////////////////////////////////////////////////////////////////////// 
  308. //+ 
  309. // Function Name:   GenKeys 
  310. // 
  311. // Class:           CPT_C 
  312. // 
  313. // Security:        Protected 
  314. // 
  315. // Description:     Create keys. 
  316. // 
  317. // Parameters 
  318. //    In:           NONE 
  319. // 
  320. // Return Codes:    SHORT = C_OK always returned 
  321. // 
  322. // Written by:      John Tal 
  323. // 
  324. // 
  325. // Modification History: 
  326. // 
  327. //  Date         Engineer     Mod #          Modification Description 
  328. // 
  329. //  12-Feb-1992  Tal          v 1.0-001      Initial conversion to C++ 
  330. // 
  331. //- 
  332. //////////////////////////////////////////////////////////////////////// 
  333.  
  334. SHORT  CPT_C::GenKeys(VOID) 
  335.    C_DEF_MODULE("CPT_C::GenKeys") 
  336.  
  337.    INT i; 
  338.  
  339.    for(i = 0; i < iConvolutions; i++) 
  340.    { 
  341.       C_STATUS = KeyGen(i); 
  342.    } 
  343.  
  344.    C_RETURN 
  345.   
  346. //////////////////////////////////////////////////////////////////////// 
  347. //+ 
  348. // Function Name:   WriteKeys 
  349. // 
  350. // Class:           CPT_C 
  351. // 
  352. // Security:        Public 
  353. // 
  354. // Description:     Write key file. 
  355. // 
  356. // Parameters 
  357. //    In:           NONE 
  358. // 
  359. // Return Codes:    SHORT = C_OK = success 
  360. //                         !C_OK = failure 
  361. // 
  362. // Written by:      John Tal 
  363. // 
  364. // 
  365. // Modification History: 
  366. // 
  367. //  Date         Engineer     Mod #          Modification Description 
  368. // 
  369. //  12-Feb-1992  Tal          v 1.0-001      Initial conversion to C++ 
  370. // 
  371. //- 
  372. //////////////////////////////////////////////////////////////////////// 
  373.   
  374.  
  375. SHORT  CPT_C::WriteKeys(VOID) 
  376.    INT iC; 
  377.    INT i; 
  378.  
  379.    KeyFile = fopen(szKeyFile,"w+"); 
  380.    if(KeyFile == NULL) 
  381.       C_LEAVE(C_NOTOK) 
  382.     
  383.    fprintf(KeyFile,"%s %s %s %d\n",  
  384.            CPT_ID, CPT_VER, szKeyStr, iConvolutions); 
  385.  
  386.    for(iC = 0; iC < iConvolutions; iC++) 
  387.    { 
  388.      for(i = 0; i < ASCIIBYTES+1; i++) 
  389.        fprintf(KeyFile,"%d\n", -> cBytes[CPT_ENCODE][iC][i]); 
  390.    } 
  391.  
  392.    fclose(KeyFile); 
  393.    KeyFile = NULL; 
  394.  
  395. C_MODULE_EXIT: 
  396.  
  397.    C_RETURN 
  398.  
  399.    
  400. SHORT CPT_C::OpenKeyFile(VOID) 
  401.    C_DEF_MODULE("CPT_C::OpenKeyFile") 
  402.  
  403.    KeyFile = fopen(szKeyFile,"w+"); 
  404.    if(KeyFile == NULL) 
  405.       C_LEAVE(C_NOTOK) 
  406.  
  407. C_MODULE_EXIT: 
  408.    
  409.    C_RETURN 
  410.  
  411. SHORT CPT_C::CloseKeyFile(VOID) 
  412.    C_DEF_MODULE("CPT_C::CloseKeyFile") 
  413.  
  414.    fclose(KeyFile); 
  415.    KeyFile = NULL; 
  416.    
  417.    C_RETURN 
  418.  
  419. SHORT CPT_C::OpenInFile(VOID) 
  420.    C_DEF_MODULE("CPT_C::OpenInFile") 
  421.  
  422.    InFile = fopen(szInFile,"rb"); 
  423.    if(InFile == NULL) 
  424.       C_LEAVE(C_NOTOK) 
  425.  
  426. C_MODULE_EXIT: 
  427.  
  428.    C_RETURN 
  429.    
  430. SHORT CPT_C::CloseInFile(VOID) 
  431.    C_DEF_MODULE("CPT_C::CloseInFile") 
  432.  
  433.    fclose(InFile); 
  434.    InFile = NULL; 
  435.    
  436.    C_RETURN 
  437.  
  438.  
  439. SHORT CPT_C::OpenOutFile(VOID) 
  440.    C_DEF_MODULE("CPT_C::OpenOutFile") 
  441.  
  442.    OutFile = fopen(szOutFile,"w+b"); 
  443.    if(OutFile == NULL) 
  444.       C_LEAVE(C_NOTOK) 
  445.  
  446. C_MODULE_EXIT: 
  447.  
  448.    C_RETURN 
  449.    
  450. SHORT CPT_C::CloseOutFile(VOID) 
  451.    C_DEF_MODULE("CPT_C::CloseInFile") 
  452.  
  453.    fclose(OutFile); 
  454.    OutFile = NULL; 
  455.    
  456.    C_RETURN 
  457.  
  458.   
  459. SHORT  CPT_C::SetConvolutions(INT iConvs) 
  460.    C_DEF_MODULE("CPT_C::SetConvolutions") 
  461.  
  462.    iConvolutions = iConvs; 
  463.  
  464.    if(iConvolutions > CPT_MAX_CONVOLUTIONS) 
  465.       iConvolutions = CPT_MAX_CONVOLUTIONS; 
  466.  
  467.    C_RETURN 
  468.  
  469. SHORT  CPT_C::SetKeyFileName(PCHAR pcData) 
  470.    C_DEF_MODULE("CPT_C::SetKeyFileName") 
  471.  
  472.    strcpy(szKeyFile,pcData) 
  473.  
  474.    C_RETURN 
  475.  
  476. SHORT  CPT_C::SetKeyStr(PCHAR pcData) 
  477.    C_DEF_MODULE("CPT_C::SetKeyStr") 
  478.  
  479.    strcpy(szKeyStr,pcData) 
  480.  
  481.    C_RETURN 
  482.  
  483. SHORT  CPT_C::SetInFile(PCHAR pcData) 
  484.    C_DEF_MODULE("CPT_C::SetInFile") 
  485.  
  486.    strcpy(szInFile,pcData) 
  487.  
  488.    C_RETURN 
  489.  
  490.  
  491. SHORT  CPT_C::SetOutFile(PCHAR pcData) 
  492.    C_DEF_MODULE("CPT_C::SetOutFile") 
  493.  
  494.    strcpy(szOutFile,szKey) 
  495.  
  496.    C_RETURN 
  497.  
  498.  
  499. SHORT  CPT_C::SetKeyFile(FILE *fp) 
  500.    C_DEF_MODULE("CPT_C::SetKeyFile") 
  501.  
  502.    KeyFile = fp; 
  503.  
  504.    C_RETURN 
  505.  
  506.  
  507.   
  508. //////////////////////////////////////////////////////////////////////// 
  509. //+ 
  510. // Function Name:   ReadInKeys 
  511. // 
  512. // Class:           CPT_C 
  513. // 
  514. // Security:        Public 
  515. // 
  516. // Description:     Read in keys from file 
  517. // 
  518. // Parameters 
  519. //    In:           NONE 
  520. // 
  521. // Return Codes:    SHORT = C_OK = success 
  522. //                         !C_OK = failure 
  523. // 
  524. // Written by:      John Tal 
  525. // 
  526. // 
  527. // Modification History: 
  528. // 
  529. //  Date         Engineer     Mod #          Modification Description 
  530. // 
  531. //  12-Feb-1992  Tal          v 1.0-001      Initial conversion to C++ 
  532. // 
  533. //- 
  534. //////////////////////////////////////////////////////////////////////// 
  535.   
  536. SHORT  CPT_C::ReadInKeys(VOID) 
  537.    C_DEF_MODULE("CPT_C::ReadInKeys") 
  538.  
  539.    CHAR data[5]; 
  540.    INT i,i2,iC; 
  541.  
  542.    fscanf(KeyFile,"%s %s %s %d", 
  543.           szCptId, 
  544.           szCptVers, 
  545.           szCptKeyId, 
  546.           &iConvolutions); 
  547.  
  548.    for(iC = 0; iC < iConvolutions; iC++) 
  549.    { 
  550.      for(i = 0; i < ASCIIBYTES+1; i++) 
  551.      { 
  552.         fgets(data,BUFSIZE,KeyFile); 
  553.         i2 = atoi(data); 
  554. #ifdef DEBUG 
  555.         printf("Read %d (%c) at %d (%c)\n", i2,i2,i,i); 
  556. #endif 
  557.         cBytes[CPT_ENCODE][iC][i] = i2; 
  558.      } 
  559.    }    
  560.     
  561.    if(iJob == CPT_DECODE) 
  562.       ReverseKeys(); 
  563.  
  564. C_MODULE_EXIT: 
  565.  
  566.    C_RETURN 
  567.   
  568. //////////////////////////////////////////////////////////////////////// 
  569. //+ 
  570. // Function Name:   ReverseKeys 
  571. // 
  572. // Class:           CPT_C 
  573. // 
  574. // Security:        Protected 
  575. // 
  576. // Description:     Reverse a key set 
  577. // 
  578. // Parameters 
  579. //    In:           NONE 
  580. // 
  581. // Return Codes:    SHORT = C_OK always returned 
  582. // 
  583. // Written by:      John Tal 
  584. // 
  585. // 
  586. // Modification History: 
  587. // 
  588. //  Date         Engineer     Mod #          Modification Description 
  589. // 
  590. //  12-Feb-1992  Tal          v 1.0-001      Initial conversion to C++ 
  591. // 
  592. //- 
  593. //////////////////////////////////////////////////////////////////////// 
  594.   
  595. SHORT  CPT_C::ReverseKeys(VOID) 
  596.     C_DEF_MODULE("CPT_C::ReverseKeys") 
  597.  
  598.     INT i,scan,iC; 
  599.  
  600.     for(iC = 0; iC < iConvolutions; iC++) 
  601.     for(i = 0; i < ASCIIBYTES+1; i++) 
  602.        for(scan = 0; scan < ASCIIBYTES+1; scan++) 
  603.           if(cBytes[CPT_ENCODE][iC][scan] == i) 
  604.           { 
  605.              cBytes[CPT_DECODE][iC][i] = scan; 
  606. #ifdef DEBUG 
  607.              printf("%d (%c) used at %d (%c)\n",scan,scan,i,i); 
  608. #endif 
  609.           } 
  610.  
  611.     C_RETURN 
  612.   
  613. //////////////////////////////////////////////////////////////////////// 
  614. //+ 
  615. // Function Name:   CodeFile 
  616. // 
  617. // Class:           CPT_C 
  618. // 
  619. // Security:        Public 
  620. // 
  621. // Description:     Apply keys in conversion from input file to output file. 
  622. //                  Is called for both encoding and decoding. 
  623. // 
  624. // Parameters 
  625. //    In:           NONE 
  626. // 
  627. // Return Codes:    SHORT = C_OK = success 
  628. //                         !C_OK = failure 
  629. // 
  630. // Written by:      John Tal 
  631. // 
  632. // 
  633. // Modification History: 
  634. // 
  635. //  Date         Engineer     Mod #          Modification Description 
  636. // 
  637. //  12-Feb-1992  Tal          v 1.0-001      Initial conversion to C++ 
  638. // 
  639. //- 
  640. //////////////////////////////////////////////////////////////////////// 
  641.  
  642. SHORT  CPT_C::CodeFile(VOID) 
  643.     C_DEF_MODULE("CPT_C::CodeFile") 
  644.  
  645.     INT i,iC,iBytesRead; 
  646.     UCHAR szBuffer[BUFSIZE + 1]; 
  647.  
  648.     /* 
  649.     **  Reset convolution ptr 
  650.     */ 
  651.  
  652.     iC = 0; 
  653.  
  654.     do 
  655.     { 
  656.        iBytesRead = fread(szBuffer,1,BUFSIZE,InFile); 
  657.        if(iBytesRead > 0) 
  658.        { 
  659.           CodeBuffer(szBuffer,szBuffer,iBytesRead); 
  660.           fwrite(szBuffer,1,iBytesRead,OutFile); 
  661.        } 
  662.  
  663.     } while(iBytesRead != 0); 
  664.  
  665. C_MODULE_EXIT: 
  666.  
  667.     C_RETURN 
  668.   
  669. //////////////////////////////////////////////////////////////////////// 
  670. //+ 
  671. // Function Name:   CodeBuffer 
  672. // 
  673. // Class:           CPT_C 
  674. // 
  675. // Security:        Protected 
  676. // 
  677. // Description:     Apply key translation/coding on a buffer 
  678. // 
  679. // Parameters 
  680. //    In:           NONE 
  681. // 
  682. // Return Codes:    SHORT = C_OK = success 
  683. //                         !C_OK = failure 
  684. // 
  685. // Written by:      John Tal 
  686. // 
  687. // 
  688. // Modification History: 
  689. // 
  690. //  Date         Engineer     Mod #          Modification Description 
  691. // 
  692. //  12-Feb-1992  Tal          v 1.0-001      Initial conversion to C++ 
  693. // 
  694. //- 
  695. //////////////////////////////////////////////////////////////////////// 
  696.  
  697. SHORT  CPT_C::CodeBuffer(CHAR * pcBufIn,CHAR * pcBufOut,INT iBufLen) 
  698.    INT iPos; 
  699.  
  700.    for(iPos = 0; iPos < iBufLen; iPos++) 
  701.    { 
  702. #ifdef DEBUG 
  703.       printf("using %d %c  for %d (%c)\n", cBytes[iJob][iC][pcBufIn[iPos]],pCptWA -> 
  704. #endif 
  705.       pcBufOut[iPos] = cBytes[iJob][iC][pcBufIn[iPos]]; 
  706.       if(->iConvolutions > 1) 
  707.          AdjustConvolution(); 
  708.    } 
  709.  
  710.   
  711. //////////////////////////////////////////////////////////////////////// 
  712. //+ 
  713. // Function Name:   Adjust Convolution 
  714. // 
  715. // Class:           CPT_C 
  716. // 
  717. // Security:        Protected 
  718. // 
  719. // Description:     Adjust convolutoin prt as part of buffer coding process 
  720. // 
  721. // Parameters 
  722. //    In:           NONE 
  723. // 
  724. // Return Codes:    SHORT = C_OK = success 
  725. //                         !C_OK = failure 
  726. // 
  727. // Written by:      John Tal 
  728. // 
  729. // 
  730. // Modification History: 
  731. // 
  732. //  Date         Engineer     Mod #          Modification Description 
  733. // 
  734. //  12-Feb-1992  Tal          v 1.0-001      Initial conversion to C++ 
  735. // 
  736. //- 
  737. //////////////////////////////////////////////////////////////////////// 
  738.   
  739. SHORT  AdjustConvolution(CPT_WORK_AREA_P ) 
  740.    C_DEF_MODULE("CPT_C::AdjustConvolution") 
  741.  
  742.    iC++; 
  743.    if(iC >= iConvolutions) 
  744.       iC = 0; 
  745.  
  746.    C_RETURN 
  747.  
  748.   
  749. //////////////////////////////////////////////////////////////////////// 
  750. //+ 
  751. // Function Name:   UsrCode 
  752. // 
  753. // Class:           (Standalone) 
  754. // 
  755. // Security:        N/A 
  756. // 
  757. // Description:     Get Code/decode info from user 
  758. // 
  759. // Parameters 
  760. //    In:           NONE 
  761. // 
  762. // Return Codes:    SHORT = C_OK = success 
  763. //                         !C_OK = failure 
  764. // 
  765. // Written by:      John Tal 
  766. // 
  767. // 
  768. // Modification History: 
  769. // 
  770. //  Date         Engineer     Mod #          Modification Description 
  771. // 
  772. //  12-Feb-1992  Tal          v 1.0-001      Initial conversion to C++ 
  773. // 
  774. //- 
  775. //////////////////////////////////////////////////////////////////////// 
  776.   
  777. SHORT  CptUsrCode(VOID) 
  778.     C_DEF_MODULE("CptUsrCode") 
  779.  
  780.     INT  keynum; 
  781.     CHAR key_str[16]; 
  782.     CHAR job_code[4]; 
  783.  
  784.     if(iJob == CPT_ENCODE) 
  785.        strcpy(job_code,""); 
  786.     else 
  787.        strcpy(job_code,"DE-"); 
  788.  
  789.     printf("\n\n\nYOU must keep trak of which key you used on which file.\n"); 
  790.     printf("\n\nKey Number To Use "); 
  791.     scanf("%d",&keynum); 
  792.     fflush(stdin); 
  793.  
  794.     sprintf(key_str,"%d",keynum); 
  795.     lpad(key_str,4); 
  796.     srep(key_str,' ','0'); 
  797.     strcpy(szKeyFile,"key_"); 
  798.     strcat(szKeyFile,key_str); 
  799.     strcat(szKeyFile,".cpt"); 
  800.  
  801.     printf("\nFile To %sCode ",job_code); 
  802.     gets(szInFile); 
  803.  
  804.     printf("\n\nName For %sCoded Result File ",job_code); 
  805.     gets(szOutFile); 
  806.  
  807.     C_STATUS = CptReadInKeys(); 
  808.  
  809.     if(C_STATUS) 
  810.        C_LEAVE(C_STATUS) 
  811.  
  812.     C_STATUS = CptCodeFile(); 
  813.  
  814. C_MODULE_EXIT: 
  815.  
  816.     C_RETURN 
  817.  
  818.  
  819.  
  820.   
  821. #ifdef TEST 
  822. /****************************************************************************** 
  823. *+ 
  824. **  Cpt Test Function 
  825. ** 
  826. *- 
  827. */ 
  828.  
  829.  
  830. main() 
  831.   INT  pick; 
  832.   CHAR fDone = C_FALSE; 
  833.   CPT_WORK_AREA_T  stCptWA; 
  834.   CPT_WORK_AREA_P  ; 
  835.  
  836.  
  837.   memset(&stCptWA,0,sizeof(CPT_WORK_AREA_T)); 
  838.    = &stCptWA; 
  839.  
  840.   do 
  841.   { 
  842.     pick = 0; 
  843.     printf("\n\n\nWhich Of These Do You Want To Do\n"); 
  844.     printf("  1  Generate Keys\n"); 
  845.     printf("  2  Code File\n"); 
  846.     printf("  3  De-Code File\n\n"); 
  847.     printf("  0  None Of These"); 
  848.      
  849.     scanf("%d",&pick); 
  850.  
  851.     switch(pick){ 
  852.        case 0 : fDone = C_TRUE; 
  853.                 break; 
  854.        case 1 : CptGetKeyData();  
  855.                 CptGenKeys(); 
  856.                 break; 
  857.        case 2 : CptSetJob(,CPT_ENCODE); 
  858.                 CptUsrCode(); 
  859.                 break; 
  860.        case 3 : CptSetJob(,CPT_DECODE); 
  861.                 CptUsrCode(); 
  862.                 break; 
  863.        default: ; 
  864.      } 
  865.   } while (!fDone); 
  866.     
  867.  
  868.  
  869. #endif 
  870.  
  871.