pc = prpcrypt('keyskeyskeyskeys') # 初始化密钥 e = pc.encrypt("0123456789ABCDEF") # 对输入明文进行加密 d = pc.decrypt(e) # 解密密文操作 print(e, d) e = pc.encrypt("00000000000000000000000000") d = pc.decrypt(e) print(e, d)
import sys import glob import time import serial import serial.tools.list_ports 8 defserial_ports(): """ Lists serial port names :raises EnvironmentError: On unsupported or unknown platforms :returns: A list of the serial ports available on the system """ # 如果是 windows 平台的系统,对应的串口号形式 if sys.platform.startswith('win'): ports = ['COM%s' % (i + 1) for i inrange(256)] # 如果是 Linux 平台的系统,对应的串口号形式 elif sys.platform.startswith('linux') or sys.platform.startswith('cygwin'): # this excludes your current terminal "/dev/tty" ports = glob.glob('/dev/tty[A-Za-z]*') # 如果是 OS X 的系统,对应的串口号形式 elif sys.platform.startswith('darwin'): ports = glob.glob('/dev/tty.*') else: raise EnvironmentError('Unsupported platform') result = [] # 可以通过 Serial 函数对每一个串口进行控制其操作 for port in ports: try: s = serial.Serial(port) s.close() result.append(port) except (OSError, serial.SerialException): pass return result # 这句命令可以在终端打印出所有的串口设备 print(list(serial.tools.list_ports.comports())) if __name__ == '__main__': print(serial_ports())