home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / clarion / encrypt.zip / ENCRYPT.CLA < prev    next >
Text File  |  1990-02-04  |  6KB  |  181 lines

  1. ENCRYPT         PROGRAM
  2.  
  3. !=========================================================================!
  4. ! The following String Encryption Demo uses a Password to encrypt a string!
  5. ! by using the Bitwise eXclusive OR function (BXOR). Each character in the!
  6. ! Password String is used to set a mask value by which each character in  !
  7. ! the Target String is XORed. This algorithm will cycle through the      !
  8. ! Password String  using a different character for each BXOR process.      !
  9. ! Therefore, the longer the Password, the better the encryption. A second !
  10. ! XORing is used to make the Cipher Text appear nonrepeating.          !
  11. !                                      !
  12. ! All ASCII characters are supported and the Password is case sensitive.  !
  13. ! We use the same technique in our SECURITY LEM (written in Assembly).      !
  14. ! This demonstration uses a Password of upto 30 characters. However,      !
  15. ! passwords can be upto 255 characters in length. Memo fields of any      !
  16. ! length can be processed by passing upto 255 characters at a time to      !
  17. ! the Encipher()/Decipher() Functions.                      !
  18. !-------------------------------------------------------------------------!
  19. !                   Randy Goodhew                  !
  20. !           PROFESSIONAL TECHNOLOGIES CONSULTANTS          !
  21. !                 508 Greenup Street                  !
  22. !                Covington, KY 41011                  !
  23. !                Phone:(606)491-3020                  !
  24. !                 Fax:(606)491-0176                  !
  25. !=========================================================================!
  26. REJECT_KEY   EQUATE(279)
  27.          MAP
  28.            MODULE('CIPHER')
  29.          FUNC(Encipher),STRING
  30.          FUNC(Decipher),STRING
  31.          . .
  32.  
  33. Screen         SCREEN      PRE(Scr),HUE(7,1)
  34.            ROW(1,1)      STRING('╔═{11}╤═{14}╗'),HUE(15,0)
  35.            ROW(2,1)      REPEAT(3);STRING('║<0{11}>│<0{14}>║'),HUE(15,0) .
  36.            ROW(5,1)      STRING('╚═{11}╧═{14}╝'),HUE(15,0)
  37.            ROW(1,29)  STRING('╔═{50}╗'),ENH
  38.            ROW(2,29)  REPEAT(3);STRING('║<0{50}>║'),ENH .
  39.            ROW(5,29)  STRING('╚═{50}╝'),ENH
  40.            ROW(2,3)      STRING('╔═╦═╦═╦═╕'),HUE(4,7)
  41.            ROW(3,3)      STRING('╠═╝<0>║<0>║'),HUE(4,7)
  42.            ROW(4,3)      STRING('╨<0{3}>╨<0>╚═╛'),HUE(4,7)
  43.            ROW(6,1)      REPEAT(2);STRING('▒{80}') .
  44.            ROW(8,1)      STRING('▒{17}╔═{44}╗▒{17}')
  45.            ROW(9,1)      REPEAT(11);STRING('▒{17}║<0{44}>║<0,0>▒{15}') .
  46.            ROW(20,1)  STRING('▒{17}╟─{44}╢<0,0>▒{15}')
  47.            ROW(21,1)  STRING('▒{17}║<0{44}>║<0,0>▒{15}')
  48.            ROW(22,1)  STRING('▒{17}╚═{44}╝<0,0>▒{15}')
  49.            ROW(23,1)  STRING('▒{19}<0{46}>▒{15}')
  50.            ROW(24,1)  STRING('▒{80}')
  51.            ROW(2,2)      STRING(' '),HUE(4,7)
  52.          COL(12)  STRING(' '),HUE(4,7)
  53.          COL(14)  STRING(' PROFESSIONAL '),HUE(15,4)
  54.            ROW(3,2)      STRING(' '),HUE(4,7)
  55.          COL(6)      STRING(' '),HUE(4,7)
  56.          COL(8)      STRING(' '),HUE(4,7)
  57.          COL(10)  STRING('   '),HUE(4,7)
  58.          COL(14)  STRING(' TECHNOLOGIES '),HUE(1,7)
  59.          COL(44)  STRING('String Encryption Demo'),HUE(14,1)
  60.            ROW(4,2)      STRING(' '),HUE(4,7)
  61.          COL(4)      STRING('   '),HUE(4,7)
  62.          COL(8)      STRING(' '),HUE(4,7)
  63.          COL(12)  STRING(' '),HUE(4,7)
  64.          COL(15)  STRING('CONSULTANTS'),ENH
  65.            ROW(9,64)  STRING('  '),HUE(7,0)
  66.            ROW(10,64) STRING('  '),HUE(7,0)
  67.            ROW(11,64) STRING('  '),HUE(7,0)
  68.            ROW(12,64) STRING('  '),HUE(7,0)
  69.            ROW(13,64) STRING('  '),HUE(7,0)
  70.            ROW(14,20) STRING('CipherText:')
  71.          COL(64)  STRING('  '),HUE(7,0)
  72.            ROW(15,25) STRING('Encipher Elapsed Time:')
  73.          COL(55)  STRING('seconds')
  74.          COL(64)  STRING('  '),HUE(7,0)
  75.            ROW(16,64) STRING('  '),HUE(7,0)
  76.            ROW(17,21) STRING('PlainText:')
  77.          COL(64)  STRING('  '),HUE(7,0)
  78.            ROW(18,25) STRING('Decipher Elapsed Time:')
  79.          COL(55)  STRING('seconds')
  80.          COL(64)  STRING('  '),HUE(7,0)
  81.            ROW(19,64) STRING('  '),HUE(7,0)
  82.            ROW(20,64) STRING('  '),HUE(7,0)
  83.            ROW(21,34) STRING('Ctrl-Esc = Exit'),HUE(12,1)
  84.          COL(64)  STRING('  '),HUE(7,0)
  85.            ROW(22,64) STRING('  '),HUE(7,0)
  86.            ROW(23,20) STRING(' {46}'),HUE(7,0)
  87.            ROW(25,1)  STRING(' {25}'),HUE(1,7)
  88.          COL(56)  STRING(' {25}'),HUE(1,7)
  89. Ciphertext     ROW(14,32) STRING(30),HUE(14,1)
  90. Enciphertime   ROW(15,48) STRING(@N6.2),HUE(14,1)
  91. Plaintext      ROW(17,32) STRING(30),HUE(14,1)
  92. Deciphertime   ROW(18,48) STRING(@N6.2),HUE(14,1)
  93. Prompt           ROW(25,26) STRING(30),HUE(1,7)
  94.            ROW(10,22) STRING('Password:')
  95.          COL(32)  ENTRY(@S30),USE(G:password),HUE(14,1),SEL(1,7)
  96.            ROW(12,23) STRING('Message:')
  97.          COL(32)  ENTRY(@S30),USE(G:message),HUE(14,1),SEL(1,7)
  98.          .
  99.  
  100.        GROUP,PRE(G)                 !Global Variables Group
  101. Password     STRING(30)
  102. Message         STRING(30)
  103. Start         LONG
  104. Stop         LONG
  105.        END !group
  106.  
  107.   CODE
  108.   SETHUE(7,0)
  109.   BLANK
  110.   SETHUE
  111.   OPEN(SCREEN)                     !Open the Screen
  112.   SETCURSOR                     !Turn off any Cursor
  113.   ALERT                         !Reset ALERTed Keys
  114.   ALERT(REJECT_KEY)                 !Alert Screen Reject Key
  115.   LOOP
  116.     LOOP WHILE KEYBOARD()             !Clear Keyboard Buffer
  117.       ASK
  118.     END !loop
  119.  
  120.     Scr:CipherText   = ''             !Erase Screen Variables
  121.     Scr:PlainText    = ''             !
  122.     Scr:EncipherTime = ''             !
  123.     Scr:DecipherTime = ''             !
  124.  
  125.     ERASE                     !Erase USE Variables
  126.  
  127.     Scr:Prompt = CENTER('Enter a Password',30)     !Show Prompt
  128.  
  129.     ACCEPT                     !Read Password
  130.  
  131.     IF KEYCODE() = REJECT_KEY THEN BREAK.     !Exit Program
  132.  
  133.     Scr:Prompt = CENTER('Enter a String to be Encrypted',30)
  134.  
  135.     ACCEPT                     !Read Message
  136.  
  137.     G:Start = CLOCK()
  138.     Scr:CipherText = Encipher(G:Message,G:Password)       !Encrypt Message
  139.     G:Stop = CLOCK()
  140.     Scr:EncipherTime = (G:Stop - G:Start) / 100
  141.  
  142.     G:Start = CLOCK()
  143.     Scr:PlainText = Decipher(Scr:CipherText,G:Password)       !Decrypt Message
  144.     G:Stop = CLOCK()
  145.     Scr:DecipherTime = (G:Stop - G:Start) / 100
  146.  
  147.     Scr:Prompt = CENTER('Press any key to start over',30)
  148.  
  149.     ASK                         !Pause for Key
  150.  
  151.     SELECT(1)                     !Start over
  152.  
  153.   END !loop
  154.   !--------- Special Screen Effect -------------------------
  155.   SETHUE(1,7,0)
  156.   row# = 13
  157.   col# = 37
  158.   rows# = 1
  159.   cols# = 8
  160.   frequency# = 500
  161.   LOOP 13 TIMES
  162.     COLOR(row#,col#,rows#,cols#)
  163.     row#  -= 1
  164.     col#  -= 3
  165.     rows# += 2
  166.     cols# += 6
  167.     LOOP 2 TIMES
  168.       frequency# += 25
  169.       BEEP(frequency#,8)
  170.     END !loop
  171.   END !loop
  172.   LOOP 26 TIMES
  173.     frequency# -= 25
  174.     BEEP(frequency#,8)
  175.   END !loop
  176.   BEEP(0,500)
  177.   SETHUE(7,0,0)
  178.   BLANK
  179.   SETHUE
  180.  
  181.