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

  1. /******************************************************************************
  2. *+
  3. ** Function Name:   Data EnCryPTion Functions - CPT 
  4. **
  5. ** Description:   Functions to encrypt data.
  6. **                Method is 255 byte swap with optional convolutions
  7. **                to increase strength of encryption.
  8. **
  9. **                Can be used on any file (text, binary, etc.)
  10. **
  11. **                NOTE:  Although this method will keep most people and
  12. **                       most hackers from decoding your data,
  13. **                       it is NOT intended for use on government or
  14. **                       DoD data which requires specific security
  15. **                       performance.  
  16. **
  17. ** Written by:  John Tal
  18. **
  19. **
  20. ** Modification History:
  21. **
  22. ** Date          Engineer        Mod#     Modification
  23. ** ---------------------------------------------------------------------------
  24. ** 12-FEB-1992   J. Tal          V1.0-000 New
  25. **
  26. *-
  27. */
  28.  
  29.  
  30. /****************************************************
  31.  
  32.   Approach
  33.  
  34.   CPT uses the full 255 byte substition method which yields an extremely high 
  35.   number of possible ways to encrypt a file.
  36.  
  37.   The following code fragment demonstrates the number of combinations based on
  38.   N (=256):
  39.  
  40.   Comb = 1;
  41.   FOR I = 1 TO N-1
  42.     Comb = Comb + I*Comb;
  43.  
  44.  
  45.   For added security, a convolution metric is available which will multiply
  46.   the above number by the number of convolutions you supply.
  47.  
  48.   Here is a sample run of CPT functions.   
  49.  
  50.       1.   Create key set.
  51.            Take the numbers 0 thru 255 and sort them into random order.
  52.       2.   Write key set to disk.
  53.            The key set values are written out as ascii text.
  54.       3.   Encode a file.
  55.            If input is ABC, then key positions [65], [66], and [67] are
  56.            checked to see what random values they contain.   Output
  57.            for ABC could be *D@. (Unprintable characters are also
  58.            used.)
  59.       4.   Decode a file.
  60.            The key set values are read from disk and reversed.
  61.            (e.g. Key position '*' gets value 'A'.)
  62.            Input *D@ is translated back to ABC.
  63.  
  64.       If a convolution value of 5 is used then an input before
  65.       encoding of AAAAA could result in output of 4Pd-3.  Use of convolutions
  66.       can dramatically slow down any unauthorized attempt to 
  67.       decode your data.
  68.        
  69.  
  70.  
  71.   Application Usage
  72.  
  73.   If you want to incorporate CPT functions into your application, there
  74.   are four routines you need to call.
  75.  
  76.       CptGenKeys - To Create a new key set
  77.       CptSetJob - To set mode (CPT_ENCODE or CPT_DECODE)
  78.       CptReadInKeys - To read a key set into memory
  79.       CptCodeFile - To encode or decode a file
  80.  
  81.   Once a key set has been created using CptGenKeys, the same key set can
  82.   be used on multiple files.   
  83.  
  84.   Note:     Since there are only four Cpt functions, no man pages
  85.             were created for CPT.  
  86.  
  87.   WARNING:  To decrypt a file requires the EXACT same key set as was
  88.             used to encrypt.  
  89.             If you have lost the key set then you are stuck. 
  90.             I have no way to reconstruct your key set or decode
  91.             decode any file you encrypt.
  92.  
  93. ****************************************************/
  94.  
  95. #include <stdio.h>
  96. #ifdef C_ANSI
  97. #include <stdlib.h>
  98. #include <string.h>
  99. #endif
  100.  
  101. #include <memincs.h>
  102.  
  103. #include <cpt.h>
  104.  
  105.  
  106.  
  107.  
  108. /*
  109. **  A couple of CHAR array utility functions
  110. */
  111.  
  112.  
  113. /* 
  114. **  Left pad an array with blanks
  115. */
  116.  
  117. #ifdef C_ANSI
  118. VOID APIENTRY lpad(CHAR * str,INT width)
  119. #else
  120. VOID APIENTRY lpad(str,width)
  121. CHAR *str;
  122. INT width;
  123. #endif
  124. {
  125.     INT i,w;
  126.  
  127.     w = strlen(str);
  128.  
  129.     /****************************************
  130.           if needs padding
  131.     ****************************************/
  132.     if(width > w)
  133.     {
  134.        /*  move bytes */
  135.        /*
  136.            123
  137.            12    3
  138.            1    23
  139.                123
  140.        */
  141.        for(i = 0; i < w; i++)
  142.           str[width-i-1] = str[w-i-1];
  143.  
  144.        /*  pad with spaces */
  145.        for(i = 0; i < (width - w); i++)
  146.           str[i] = ' ';
  147.  
  148.        /*  mark end */
  149.        str[width] = '\0';
  150.     }
  151.  
  152.     /****************************************
  153.           if needs truncating
  154.     ****************************************/
  155.     if(width < w)   
  156.        str[width] = '\0';
  157.  
  158.  
  159. }
  160.  
  161. /*
  162. **  A string replacement function
  163. **  Replace all characters dh in string ch with character eh
  164. */
  165.  
  166. #ifdef C_ANSI
  167. VOID APIENTRY srep(CHAR * ch,CHAR dh,CHAR eh)
  168. #else
  169. VOID APIENTRY srep(ch,dh,eh)
  170. CHAR *ch;
  171. CHAR dh;
  172. CHAR eh;
  173. #endif
  174. {
  175.    INT i;
  176.  
  177.    for(i = 0; i < strlen(ch); i++)
  178.       if(ch[i] == dh)
  179.          ch[i] = eh;
  180. }
  181.  
  182.  
  183.  
  184. /******************************************************************************
  185. *+
  186. ** Function Name:   CptSetJob
  187. **
  188. ** Description:   Get the Cpt Job to CPT_CODE or CPT_DECODE
  189. **
  190. ** Return Codes:
  191. **               C_OK
  192. **
  193. ** Written by:  John Tal
  194. **
  195. **
  196. ** Modification History:
  197. **
  198. ** Date          Engineer        Mod#     Modification
  199. ** ---------------------------------------------------------------------------
  200. ** 12-FEB-1992   J. Tal          V1.0-000 New
  201. **
  202. *-
  203. */
  204.  
  205. #ifdef C_ANSI
  206. SHORT APIENTRY CptSetJob(CPT_WORK_AREA_P pCptWA,INT iJob)
  207. #else
  208. SHORT APIENTRY CptSetJob(pCptWA,iJob)
  209. CPT_WORK_AREA_P pCptWA;
  210. INT iJob;
  211. #endif
  212. {
  213.    C_DEF_MODULE("CptSetJob")
  214.  
  215.    pCptWA -> iJob = iJob;
  216.  
  217.    C_RETURN
  218. }
  219.  
  220.  
  221. /******************************************************************************
  222. *+
  223. ** Function Name:   CptKeyGen
  224. **
  225. ** Description:   Generate a Key Set in memory.
  226. **
  227. ** Return Codes:
  228. **               C_OK
  229. **
  230. ** Written by:  John Tal
  231. **
  232. **
  233. ** Modification History:
  234. **
  235. ** Date          Engineer        Mod#     Modification
  236. ** ---------------------------------------------------------------------------
  237. ** 12-FEB-1992   J. Tal          V1.0-000 New
  238. **
  239. *-
  240. */
  241.  
  242. #ifdef C_ANSI
  243. SHORT APIENTRY CptKeyGen(CPT_WORK_AREA_P pCptWA,INT iSet)
  244. #else
  245. SHORT APIENTRY CptKeyGen(pCptWA,iSet)
  246. CPT_WORK_AREA_P pCptWA;
  247. INT iSet;
  248. #endif
  249. {
  250.    C_DEF_MODULE("CptKeyGen")
  251.  
  252.    unsigned top;
  253.    INT f;
  254.    INT i;
  255.    UCHAR  hold_area[256];
  256.  
  257. #ifdef ANNOUNCE
  258.    if(iSet == 0)
  259.      printf("\nGenerating Keys - Please Stand By");
  260. #endif
  261.  
  262.    for(i = 0; i < ASCIIBYTES+1; i++)
  263.    {
  264.       hold_area[i] = (UCHAR) i;
  265.       pCptWA -> cCptCodes[CPT_ENCODE][iSet][i] = -1;
  266.    }
  267.  
  268.    srand(iSet);
  269.  
  270.    /*
  271.    **  Use 'quick' randomizer
  272.    **  It copies the top element that has not been selected when
  273.    **  a duplicate random number is found.
  274.    */
  275.  
  276.    for(top = 256; top > 0; top--)
  277.    {
  278.        f = (rand() % top); /* was 256 */
  279.        pCptWA -> cCptCodes[CPT_ENCODE][iSet][top-1] = hold_area[f];
  280.        if(f != top-1)
  281.           hold_area[f] = hold_area[top-1];
  282.    }
  283.  
  284.    C_RETURN
  285. }
  286.  
  287. /******************************************************************************
  288. *+
  289. ** Function Name:   CptGetKeyData
  290. **
  291. ** Description:   Get Parameters for key set from user.
  292. **
  293. ** Return Codes:
  294. **               C_OK
  295. **
  296. ** Written by:  John Tal
  297. **
  298. **
  299. ** Modification History:
  300. **
  301. ** Date          Engineer        Mod#     Modification
  302. ** ---------------------------------------------------------------------------
  303. ** 12-FEB-1992   J. Tal          V1.0-000 New
  304. **
  305. *-
  306. */
  307.  
  308. #ifdef C_ANSI
  309. SHORT APIENTRY CptGetKeyData(CPT_WORK_AREA_P pCptWA)
  310. #else
  311. SHORT APIENTRY CptGetKeyData(pCptWA)
  312. CPT_WORK_AREA_P pCptWA;
  313. #endif
  314. {
  315.    C_DEF_MODULE("CptGetKeyData")
  316.  
  317.    INT i;
  318.  
  319.    printf("\n\n\nEnter Reference Number For This Key ");
  320.    scanf("%d",&i);
  321.    sprintf(pCptWA -> szKeyStr,"%d",i);
  322.    lpad(pCptWA -> szKeyStr,4);
  323.    srep(pCptWA -> szKeyStr,' ','0');
  324.    strcpy(pCptWA -> szKeyFile,"key_");
  325.    strcat(pCptWA -> szKeyFile,pCptWA -> szKeyStr);
  326.    strcat(pCptWA -> szKeyFile,".cpt");
  327.  
  328.    printf("\nEnter Convolutions (Usally 1, higher = tighter security) ");
  329.    scanf("%d",&pCptWA -> iCptConvolutions);
  330.  
  331.    C_RETURN
  332. }
  333.  
  334. /******************************************************************************
  335. *+
  336. ** Function Name:   CptGenKeys
  337. **
  338. ** Description:   Create keys and write key file.
  339. **
  340. ** Return Codes:
  341. **               C_OK
  342. **
  343. ** Written by:  John Tal
  344. **
  345. **
  346. ** Modification History:
  347. **
  348. ** Date          Engineer        Mod#     Modification
  349. ** ---------------------------------------------------------------------------
  350. ** 12-FEB-1992   J. Tal          V1.0-000 New
  351. **
  352. *-
  353. */
  354.  
  355. #ifdef C_ANSI
  356. SHORT APIENTRY CptGenKeys(CPT_WORK_AREA_P pCptWA)
  357. #else
  358. SHORT APIENTRY CptGenKeys(pCptWA)
  359. CPT_WORK_AREA_P pCptWA;
  360. #endif
  361. {
  362.    C_DEF_MODULE("CptGenKeys")
  363.  
  364.    INT i,iC;
  365.  
  366.    if(pCptWA -> iCptConvolutions > MAX_CONVOLUTIONS)
  367.       pCptWA -> iCptConvolutions = MAX_CONVOLUTIONS;
  368.    
  369.    for(i = 0; i < pCptWA -> iCptConvolutions; i++)
  370.       CptKeyGen(pCptWA,i);
  371.  
  372.    pCptWA -> KeyFile = fopen(pCptWA -> szKeyFile,"w+");
  373.    if(pCptWA -> KeyFile == NULL)
  374.       C_LEAVE(C_NOTOK)
  375.    
  376.    fprintf(pCptWA -> KeyFile,"%s %s %s %d\n", 
  377.            CPT_ID, CPT_VER, pCptWA -> szKeyStr, pCptWA -> iCptConvolutions);
  378.  
  379.    for(iC = 0; iC < pCptWA -> iCptConvolutions; iC++)
  380.    {
  381.      for(i = 0; i < ASCIIBYTES+1; i++)
  382.        fprintf(pCptWA -> KeyFile,"%d\n",pCptWA -> cCptCodes[CPT_ENCODE][iC][i]);
  383.    }
  384.  
  385.    fclose(pCptWA -> KeyFile);
  386.  
  387. C_MODULE_EXIT:
  388.  
  389.    C_RETURN
  390. }
  391.  
  392. /******************************************************************************
  393. *+
  394. ** Function Name:   CptReadInKeys
  395. **
  396. ** Description:   Read in key data from file.
  397. **         
  398. **                Note: pCptWA -> iJob must be set to CPT_CODE or CPT_DECODE
  399. **                      before calling this function.
  400. **
  401. ** Return Codes:
  402. **               C_OK
  403. **
  404. ** Written by:  John Tal
  405. **
  406. **
  407. ** Modification History:
  408. **
  409. ** Date          Engineer        Mod#     Modification
  410. ** ---------------------------------------------------------------------------
  411. ** 12-FEB-1992   J. Tal          V1.0-000 New
  412. **
  413. *-
  414. */
  415.  
  416. #ifdef C_ANSI
  417. SHORT APIENTRY CptReadInKeys(CPT_WORK_AREA_P pCptWA)
  418. #else
  419. SHORT APIENTRY CptReadInKeys(pCptWA)
  420. CPT_WORK_AREA_P pCptWA;
  421. #endif
  422. {
  423.    C_DEF_MODULE("CptReadInKeys")
  424.  
  425.    CHAR data[5];
  426.    INT i,i2,iC;
  427.  
  428.    pCptWA -> KeyFile = fopen(pCptWA -> szKeyFile,"r");
  429.    if(pCptWA -> KeyFile == NULL)
  430.       C_LEAVE(C_NOTOK)
  431.  
  432.    fscanf(pCptWA -> KeyFile,"%s %s %s %d\n",
  433.           pCptWA -> szCptId,
  434.           pCptWA -> szCptVers,
  435.           pCptWA -> szCptKeyId,
  436.           &pCptWA -> iCptConvolutions);
  437.  
  438.    for(iC = 0; iC < pCptWA -> iCptConvolutions; iC++)
  439.    {
  440.      for(i = 0; i < ASCIIBYTES+1; i++)
  441.      {
  442.         fgets(data,5,pCptWA -> KeyFile);
  443.         i2 = atoi(data);
  444. #ifdef DEBUG
  445.         printf("Read %d (%c) at %d (%c)\n", i2,i2,i,i);
  446. #endif
  447.         pCptWA -> cCptCodes[CPT_ENCODE][iC][i] = (unsigned char) i2;
  448.      }
  449.    }   
  450.    
  451.    if(pCptWA -> iJob == CPT_DECODE)
  452.       CptReverseKeys(pCptWA);
  453.  
  454. C_MODULE_EXIT:
  455.  
  456.    if(pCptWA -> KeyFile != NULL)
  457.       fclose(pCptWA -> KeyFile);
  458.  
  459.    C_RETURN
  460.  
  461. }
  462.  
  463. /******************************************************************************
  464. *+
  465. ** Function Name:   CptReverseKeys
  466. **
  467. ** Description:   Reverse key codes in memory for decoding operation.
  468. **
  469. ** Return Codes:
  470. **               C_OK
  471. **
  472. ** Written by:  John Tal
  473. **
  474. **
  475. ** Modification History:
  476. **
  477. ** Date          Engineer        Mod#     Modification
  478. ** ---------------------------------------------------------------------------
  479. ** 12-FEB-1992   J. Tal          V1.0-000 New
  480. **
  481. *-
  482. */
  483.  
  484. #ifdef C_ANSI
  485. SHORT APIENTRY CptReverseKeys(CPT_WORK_AREA_P pCptWA)
  486. #else
  487. SHORT APIENTRY CptReverseKeys(pCptWA)
  488. CPT_WORK_AREA_P pCptWA;
  489. #endif
  490. {
  491.     C_DEF_MODULE("CptReverseKeys")
  492.  
  493.     INT i,scan,iC;
  494.  
  495.     for(iC = 0; iC < pCptWA -> iCptConvolutions; iC++)
  496.     for(i = 0; i < ASCIIBYTES+1; i++)
  497.        for(scan = 0; scan < ASCIIBYTES+1; scan++)
  498.           if(pCptWA -> cCptCodes[CPT_ENCODE][iC][scan] == (UCHAR) i)
  499.           {
  500.              pCptWA -> cCptCodes[CPT_DECODE][iC][i] = (UCHAR) scan;
  501. #ifdef DEBUG
  502.              printf("%d (%c) used at %d (%c)\n",scan,scan,i,i);
  503. #endif
  504.           }
  505.  
  506.     C_RETURN
  507. }
  508.  
  509. /******************************************************************************
  510. *+
  511. ** Function Name:   CptCodeFile
  512. **
  513. ** Description:   Apply keys in conversion from input file to output file.
  514. **                Is called for both encoding and decoding.
  515. **
  516. ** Return Codes:
  517. **               C_OK
  518. **
  519. ** Written by:  John Tal
  520. **
  521. **
  522. ** Modification History:
  523. **
  524. ** Date          Engineer        Mod#     Modification
  525. ** ---------------------------------------------------------------------------
  526. ** 12-FEB-1992   J. Tal          V1.0-000 New
  527. **
  528. *-
  529. */
  530.  
  531. #ifdef C_ANSI
  532. SHORT APIENTRY CptCodeFile(CPT_WORK_AREA_P pCptWA)
  533. #else
  534. SHORT APIENTRY CptCodeFile(pCptWA)
  535. CPT_WORK_AREA_P pCptWA;
  536. #endif
  537. {
  538.     C_DEF_MODULE("CptCodeFile")
  539.  
  540.     INT iBytesRead;
  541.     static UCHAR szBuffer[BUFSIZE + 1]; /* keep off the stack */
  542.  
  543.     pCptWA -> OutFile = NULL;
  544.  
  545.     pCptWA -> InFile = fopen(pCptWA -> szInFile,"rb");
  546.     if(pCptWA -> InFile == NULL)
  547.        C_LEAVE(C_NOTOK)
  548.  
  549.     pCptWA -> OutFile = fopen(pCptWA -> szOutFile,"wb");
  550.     if(pCptWA -> OutFile == NULL)
  551.        C_LEAVE(C_NOTOK) 
  552.     
  553.     /*
  554.     **  Reset convolution ptr
  555.     */
  556.  
  557.     pCptWA -> iC = 0;
  558.  
  559.     do
  560.     {
  561.        iBytesRead = fread(szBuffer,1,BUFSIZE,pCptWA -> InFile);
  562.        if(iBytesRead > 0)
  563.        {
  564.           CptCodeBuffer(pCptWA,szBuffer,szBuffer,iBytesRead);
  565.           fwrite(szBuffer,1,iBytesRead,pCptWA -> OutFile);
  566.        }
  567.  
  568.     } while(iBytesRead != 0);
  569.  
  570. C_MODULE_EXIT:
  571.  
  572.     if(pCptWA -> InFile != NULL)
  573.        fclose(pCptWA -> InFile);
  574.     if(pCptWA -> OutFile != NULL)
  575.        fclose(pCptWA -> OutFile);
  576.  
  577.     C_RETURN
  578. }
  579.  
  580. /******************************************************************************
  581. *+
  582. ** Function Name:   CptCodeBuffer
  583. **
  584. ** Description:   Apply key translation/coding on buffer
  585. **
  586. ** Return Codes:
  587. **               C_OK
  588. **
  589. ** Written by:  John Tal
  590. **
  591. **
  592. ** Modification History:
  593. **
  594. ** Date          Engineer        Mod#     Modification
  595. ** ---------------------------------------------------------------------------
  596. ** 12-FEB-1992   J. Tal          V1.0-000 New
  597. **
  598. *-
  599. */
  600.  
  601. #ifdef C_ANSI
  602. SHORT APIENTRY CptCodeBuffer(CPT_WORK_AREA_P pCptWA,UCHAR * pcBufIn,UCHAR * pcBufOut,INT iBufLen)
  603. #else
  604. SHORT APIENTRY CptCodeBuffer(pCptWA,pcBufIn,pcBufOut,iBufLen)
  605. CPT_WORK_AREA_P pCptWA;
  606. UCHAR * pcBufIn;
  607. UCHAR * pcBufOut;
  608. INT iBufLen;
  609. #endif
  610. {
  611.    C_DEF_MODULE("CptCodeBuffer")
  612.  
  613.    INT iPos;
  614.  
  615.    for(iPos = 0; iPos < iBufLen; iPos++)
  616.    {
  617. #ifdef DEBUG
  618.       printf("using %d %c  for %d (%c)\n", pCptWA -> cCptCodes[pCptWA->iJob][pCptWA->iC][pcBufIn[iPos]],pCptWA -> cCptCodes[pCptWA->iJob][pCptWA->iC][pcBufIn[iPos]],pcBufIn[iPos],pcBufIn[iPos]);
  619. #endif
  620.       pcBufOut[iPos] = pCptWA -> cCptCodes[pCptWA->iJob][pCptWA->iC][pcBufIn[iPos]];
  621.       if(pCptWA->iCptConvolutions > 1)
  622.          CptAdjustConvolution(pCptWA);
  623.    }
  624.  
  625.    C_RETURN
  626. }
  627.  
  628.  
  629. /******************************************************************************
  630. *+
  631. ** Function Name:   CptAdjustConvolution
  632. **
  633. ** Description:   Adjust convolution ptr as part of buffer coding process
  634. **
  635. ** Return Codes:
  636. **               C_OK
  637. **
  638. ** Written by:  John Tal
  639. **
  640. **
  641. ** Modification History:
  642. **
  643. ** Date          Engineer        Mod#     Modification
  644. ** ---------------------------------------------------------------------------
  645. ** 12-FEB-1992   J. Tal          V1.0-000 New
  646. **
  647. *-
  648. */
  649.  
  650. #ifdef C_ANSI
  651. SHORT APIENTRY CptAdjustConvolution(CPT_WORK_AREA_P pCptWA)
  652. #else
  653. SHORT APIENTRY CptAdjustConvolution(pCptWA)
  654. CPT_WORK_AREA_P pCptWA;
  655. #endif
  656. {
  657.    C_DEF_MODULE("CptAdjustConvolution")
  658.  
  659.    pCptWA -> iC++;
  660.    if(pCptWA -> iC >= pCptWA -> iCptConvolutions)
  661.       pCptWA -> iC = 0;
  662.  
  663.    C_RETURN
  664. }
  665.  
  666.  
  667. /******************************************************************************
  668. *+
  669. ** Function Name:   CptUsrCode
  670. **
  671. ** Description:   Get Code or decode info from user
  672. **
  673. ** Return Codes:
  674. **               C_OK
  675. **
  676. ** Written by:  John Tal
  677. **
  678. **
  679. ** Modification History:
  680. **
  681. ** Date          Engineer        Mod#     Modification
  682. ** ---------------------------------------------------------------------------
  683. ** 12-FEB-1992   J. Tal          V1.0-000 New
  684. **
  685. *-
  686. */
  687.  
  688. #ifdef C_ANSI
  689. SHORT APIENTRY CptUsrCode(CPT_WORK_AREA_P pCptWA)
  690. #else
  691. SHORT APIENTRY CptUsrCode(pCptWA)
  692. CPT_WORK_AREA_P pCptWA;
  693. #endif
  694. {
  695.     C_DEF_MODULE("CptUsrCode")
  696.  
  697.     INT  keynum;
  698.     CHAR key_str[16];
  699.     CHAR job_code[4];
  700.  
  701.     if(pCptWA -> iJob == CPT_ENCODE)
  702.        strcpy(job_code,"");
  703.     else
  704.        strcpy(job_code,"DE-");
  705.  
  706.     printf("\n\n\nYOU must keep trak of which key you used on which file.\n");
  707.     printf("\n\nKey Number To Use ");
  708.     scanf("%d",&keynum);
  709.     fflush(stdin);
  710.  
  711.     sprintf(key_str,"%d",keynum);
  712.     lpad(key_str,4);
  713.     srep(key_str,' ','0');
  714.     strcpy(pCptWA -> szKeyFile,"key_");
  715.     strcat(pCptWA -> szKeyFile,key_str);
  716.     strcat(pCptWA -> szKeyFile,".cpt");
  717.  
  718.     printf("\nFile To %sCode ",job_code);
  719.     gets(pCptWA -> szInFile);
  720.  
  721.     printf("\n\nName For %sCoded Result File ",job_code);
  722.     gets(pCptWA -> szOutFile);
  723.  
  724.     C_STATUS = CptReadInKeys(pCptWA);
  725.  
  726.     if(C_STATUS)
  727.        C_LEAVE(C_STATUS)
  728.  
  729.     C_STATUS = CptCodeFile(pCptWA);
  730.  
  731. C_MODULE_EXIT:
  732.  
  733.     C_RETURN
  734.  
  735. }
  736.  
  737.  
  738.  
  739. #ifdef TEST
  740. /******************************************************************************
  741. *+
  742. **  Cpt Test Function
  743. **
  744. *-
  745. */
  746.  
  747.  
  748. main()
  749. {
  750.   INT  pick;
  751.   CHAR fDone = C_FALSE;
  752.   CPT_WORK_AREA_T  stCptWA;
  753.   CPT_WORK_AREA_P  pCptWA;
  754.  
  755.  
  756.   memset(&stCptWA,0,sizeof(CPT_WORK_AREA_T));
  757.   pCptWA = &stCptWA;
  758.  
  759.   do
  760.   {
  761.     pick = 0;
  762.     printf("\n\n\nWhich Of These Do You Want To Do\n");
  763.     printf("  1  Generate Keys\n");
  764.     printf("  2  Code File\n");
  765.     printf("  3  De-Code File\n\n");
  766.     printf("  0  None Of These");
  767.     
  768.     scanf("%d",&pick);
  769.  
  770.     switch(pick){
  771.        case 0 : fDone = C_TRUE;
  772.                 break;
  773.        case 1 : CptGetKeyData(pCptWA); 
  774.                 CptGenKeys(pCptWA);
  775.                 break;
  776.        case 2 : CptSetJob(pCptWA,CPT_ENCODE);
  777.                 CptUsrCode(pCptWA);
  778.                 break;
  779.        case 3 : CptSetJob(pCptWA,CPT_DECODE);
  780.                 CptUsrCode(pCptWA);
  781.                 break;
  782.        default: ;
  783.      }
  784.   } while (!fDone);
  785.    
  786. }
  787.  
  788.  
  789. #endif
  790.  
  791.  
  792.