PROGRAM-ID. ENCRYPTION. WORKING-STORAGE SECTION. copy "isgui.def". copy "iscrt.def". 77 crt-status special-names crt status pic 9(5). 77 hWin handle of window. 77 close-win pic 9 value 0. 77 source-str pic x any length. 77 decrypted-data pic x any length. * The encryption key must be <= 16 bytes 77 source-key pic x(16). * The encrypted data item must be "any length" so that after * calling A$ENCRYPT, it will have the exact size expected by * A$DECRYPT. 77 encrypted-data pic x any length. 77 encrypted-data-len pic 9(4) comp. 77 ind pic 9(4) comp. 77 res-str pic x(128). 77 res-ind pic 9(4) comp. 77 x-to-comp-x-item pic x. 77 comp-x-item pic x comp-x redefines x-to-comp-x-item. SCREEN SECTION. 01 Mask. 03 label line 2 col 2 size 22 cells color 3 title "Data to encrypt:" . 03 entry-field line 2 col 27 size 50 cells value source-str . 03 label line 4 col 2 size 22 cells color 3 title "Encryption Key:" . 03 entry-field line 4 col 27 size 50 cells value source-key . 03 push-button line 6 col 2 size 10 cells title "Encrypt" exception-value 101 . 03 label line 8 col 2 size 22 cells color 3 title "Encrypted data (hex):" . 03 entry-field line 8 col 27 size 50 cells value res-str . 03 push-button line 10 col 2 size 10 cells title "Decrypt" exception-value 102 . PROCEDURE DIVISION. MAIN. display independent graphical window color 65793 with system menu title "Data Encription Routines" handle hWin event WIN-EVT display Mask perform until crt-status = 27 or close-win = 1 accept Mask on exception continue end-accept evaluate crt-status when 101 perform ENCRYPT when 102 perform DECRYPT end-evaluate end-perform destroy Mask destroy hWin goback . ENCRYPT. call "A$ENCRYPT" using source-str, source-key, encrypted-data * Display the encrypted binary data as hexidecimal characters perform convert-result display Mask . DECRYPT. call "A$DECRYPT" using encrypted-data, source-key, decrypted-data display message decrypted-data title "A$DECRYPT" . WIN-EVT. if event-type = cmd-close move 1 to close-win end-if . CONVERT-RESULT. initialize res-str. move length of encrypted-data to encrypted-data-len. perform varying ind from 1 by 1 until ind > encrypted-data-len move encrypted-data(ind:1) to x-to-comp-x-item compute res-ind = 1+(ind - 1)*2 move function dec2hex(comp-x-item) TO res-str(res-ind:2) if res-str(res-ind + 1:1) = space move res-str(res-ind:1) to res-str(res-ind + 1:1) move '0' to res-str(res-ind:1) end-if end-perform