%ENCRYPT()% function
Return value value type 1st arg. character string type Currently only "DES_CBC" 2nd arg. character string type CBC initial value. 8 byte length ASCII string. 3rd arg. character string type DES key string. 8, 16, 24, 32 byte length ASCII string. 4th arg. character string type Character string to encrypt. # Start Python script.
import base64
from pyDes import des, CBC, PAD_NORMAL
# In this script, encrypted_string is the data sent from CsvToWebRec.
b64_dec = base64.b64decode(encrypted_string)
# 'ABCDEFGH' as a CDC initial bvalue, 'IJKLMNOP' as a DES key.
decryptor = des('IJKLMNOP'.encode(), CBC, 'ABCDEFGH'.encode(), pad = None, padmode = PAD_NORMAL)
decrypted_string = decryptor.decrypt(b64_dec)
# Base64 includes character string terminater NULL, so we will remove it.
unicode_string = unicode(decrypted_string, 'utf-8')
new_length = 0
old_length = len(unicode_string)
for i in range(old_length):
if ord(unicode_string[i]) == 0:# result of ord() == 0 means NULL character.
break # NULL has found.
new_length = new_length + 1
if new_length != old_length:
unicode_string = unicode_string[0:new_length] # we've successfully removed NULL.