001: * Test on Universe's Encryption / Decryption process
002: * Ernie Evans
003: * 02/22/06
004: *
005: * Test subroutine to des-ecb 56-bit Encrypt data
006: *
007: OPEN 'CF' TO FILE.CF ELSE STOP 201,'CF'
008: CRT ; CRT "TEST ENCRYPT.IT LOGIC:" ; CRT
009: DATA.TO.ENCRYPT = " *" ; GOSUB ENCRYPT.IT
010: CRT "DATA IN :"

ATA.TO.ENCRYPT
011: CRT "DATA OUT:":ENCRYPTED.DATA
012: CRT ; CRT
013: * DATA.IS.ENCRYPT = ENCRYPTED.DATA ; * For testing DECRYPT.IT
014: * WRITEV ENCRYPTED.DATA ON FILE.CF,"ENCRYPTED.TEMP.DATA",1
015: *
016: * Now to test how it will Decrypt the data
017: *
018: CRT ; CRT "TEST DECRYPT.IT LOGIC:" ; CRT
019: CRT "Enter what to decrypt:": ; INPUT DATA.IS.ENCRYPT
020: DATA.IS.ENCRYPT := CHAR(10):CHAR(13)
021: * READV DATA.IS.ENCRYPT FROM FILE.CF,"ENCRYPTED.TEMP.DATA",1 ELSE STOP
022: ENCRYPTED.DATA = DATA.IS.ENCRYPT ; GOSUB DECRYPT.IT
023: CRT "DATA IN :":ENCRYPTED.DATA
024: CRT "DATA OUT:"

ECRYPTED.DATA
025: STOP
026: *
027: * Subroutines
028: *
029: *
030: ENCRYPT.IT: ; * Encrypt data
031: *
032: ENCPLAINTEXT = DATA.TO.ENCRYPT ; * Source that is to be encrypted.
033: ENCALGORITHM = "des-ede3-cbc" ; * Use 168-bit Three key triple DES EDE in CBC mode algorithm.
034: ENCACTION = 2 ; * Base64 encode after encryption.
035: ENCDATALOC = 1 ; * Data included here in string.
036: ENCKEYPASS = "$#@10 Whatever 24 char.!" ; * Key (as a pass phrase).
037: ENCKEYLOC = 1 ; * Key is in data string.
038: ENCKEYACTION = 1 ; * Use actual key.
039: ENCSALT = '' ; * Default (make your own) Salt.
040: ENCIVKEY = '' ; * Default IV.
041: ENCRESULTCD = '' ; * Initialize the Result Code.
042: ENCRESULTLOC = 1 ; * Return Result as string.
043: *
044: ENCRETURNCD = ENCRYPT(ENCALGORITHM,ENCACTION,ENCPLAINTEXT,ENCDAT ALOC,ENCKEYPASS,ENCKEYLOC,ENCKEYACTION,ENCSALT,ENC IVKEY,ENCRESU
LTCD,ENCRESULTLOC)
045: IF ENCRETURNCD # "0" THEN ENCRESULTCD = "THERE WAS AN ERROR (":ENCRETURNCD:") IN ENCRYPTION"
046: ENCRYPTED.DATA = ENCRESULTCD
047: RETURN
048: ENCKEYPASS = "$#@10 Whatever 24 char.!" ; ALGORITHM = "des-ede3-cbc" ; ENCRYPTED = ''
049: ENCERR = ENCRYPT(ALGORITHM,2," ":TOENCRYPT,1,ENCKEYPASS,1,1,'','',ENCRYPTED,1 )
050: IF ENCERR # 0 THEN ENCRYPTED = "Error # ":ENCERR:" trying to Encrypt!"
051: *
052: DECRYPT.IT: ; * DeEncrypt data
053: *
054: DECPLAINTEXT = ENCRYPTED.DATA ; * Source that is to be dencrypted.
055: DECALGORITHM = "des-ede3-cbc" ; * Use 168-bit Three key triple DES EDE in CBC mode algorithm.
056: DECACTION = 4 ; * Base64 decode before decryption.
057: DECDATALOC = 1 ; * Data included here in string.
058: DECKEYPASS = "$#@10 Snake Oil is Good!" ; * Key (as a pass phrase).
059: DECKEYLOC = 1 ; * Key is in data string.
060: DECKEYACTION = 1 ; * Use actual key.
061: DECSALT = '' ; * Default (make its own) Salt.
062: DECIVKEY = '' ; * Default IV.
063: DECRESULTCD = '' ; * Initialize the Result Code.
064: DECRESULTLOC = 1 ; * Return Result as string.
065: *
066: DECRETURNCD = ENCRYPT(DECALGORITHM,DECACTION,DECPLAINTEXT,DECDAT ALOC,DECKEYPASS,DECKEYLOC,DECKEYACTION,DECSALT,DEC IVKEY,DECRESU
LTCD,DECRESULTLOC)
067: *IF DECRETURNCD # "0" THEN DECRESULTCD = "THERE WAS AN ERROR ("

ECRETURNCD:") IN DECRYPTION"
068: DECRYPTED.DATA = DECRESULTCD
069: RETURN
070: ENCKEYPASS = "$#@10 Snake Oil is Good!" ; ALGORITHM = "des-ede3-cbc" ; DECRYPTED = ''
071: DECERR = ENCRYPT(ALGORITHM,4,TODECRYPT:CHAR(10):CHAR(13),1, ENCKEYPASS,1,1,'','',DECRYPTED,1)
072: IF DECERR # 0 THEN DECRYPTED = "Error # "

ECERR:" trying to Decrypt!"
Bottom.