# 开发时间:2023/3/7 15:25 import pycipher c=pycipher.Caesar(5).encipher('hello word') print(c) p=pycipher.Caesar(5).decipher(c) print(p) txt=input("cipher is:").strip() for key in range(1,26):plain=""for i in txt:if i.isupper():plain+=chr(65+(ord(i)-65-key)%26)elif i.islower():plain+=chr(97+(ord(i)-97-key)%26)else:plain+=i print(plain)
# 开发时间:2023/3/14 18:43 panduan = input('请输入一个数字1|2|3(1.解密|2.加密|3.退出):') if panduan=='1':cipher = input('请输入你要解密的密文:').strip()for key in range(0,26):plain = ''for j in cipher:if j.isupper():plain+=chr(65+(ord(j)-65-key)%26)elif j.islower():plain+=chr(97+(ord(j)-97-key)%26)else:plain+=j# if 'flag' in plain:# print(plain)print(plain) elif panduan == '2':cipher=''plain = input('请输入你要加密的明文:').strip()key=int(input('请输入秘钥:'))for j in plain:if j.isupper():cipher += chr(65 + (ord(j) - 65 + key) % 26)elif j.islower():cipher += chr(97+(ord(j)-97+key)%26)else:cipher+=jprint(cipher) elif panduan == '3':exit('谢谢惠顾!') else:print('请按要求输入!')
# 开发时间:2023/3/7 14:29 txt="""0010 0100 01 110 1111011 11 11111 010 000 0 001101 1010 111 100 0 001101 01111 000 001101 00 10 1 0 010 0 000 1 01111 10 11110 101011 1111101 """ if "." in txt or "-" in txt:table=str.maketrans("01",".-")#设置替换要求:零等于点,1等于-txtanslate(table).split()#进行替换 else:txt=txt.split() key={'01':'A','1000':'B','1010':'C','100':'D','0':'E','0010':'F','110':'G','0000':'H','00':'I','0111':'J','101':'K','0100':'L','11':'M','10':'N','111':'O','0110':'P','1101':'Q','010':'R','000':'S','1':'T','001':'U','0001':'V','011':'W','1001':'X','1011':'Y','1100':'Z','01111':'1','00111':'2','00011':'3','00001':'4','00000':'5','10000':'6','11000':'7','11100':'8','11110':'9','11111':'0','001100':'?','10010':'/','101101':'()','100001':'-','010101':'.','110011':',','011010':'@','111000':':','101010':':','10001':'=','011110':"'",'101011':'!','001101':'_','010010':'"','10110':'(','1111011':'{','1111101':'}'} for i in txt:(i),end="")
# 开发时间:2023/3/14 18:44 panduan=input('请输入一个数字1|2|3(1.解密|2.加密|3.退出):') if panduan=='1':cipher = input('请输入你要解密的密文(可以是01表示的密文)):').strip()zi = {'01': 'A', '1000': 'B', '1010': 'C', '100': 'D', '0': 'E', '0010': 'F','110': 'G', '0000': 'H', '00': 'I', '0111': 'J', '101': 'K', '0100': 'L','11': 'M', '10': 'N', '111': 'O', '0110': 'P', '1101': 'Q', '010': 'R','000': 'S', '1': 'T', '001': 'U', '0001': 'V', '011': 'W', '1001': 'X','1011': 'Y', '1100': 'Z', '01111': '1', '00111': '2', '00011': '3','00001': '4', '00000': '5', '10000': '6', '11000': '7', '11100': '8','11110': '9', '11111': '0', '001100': '?', '10010': '/', '101101': '()','100001': '-', '010101': '.', '110011': ',', '011010': '@', '111000': ':','101010': ':', '10001': '=', '011110': "'", '101011': '!', '001101': '_','010010': '"', '10110': '(', '1111011': '{', '1111101': '}'}if "." in cipher or '-' in cipher:txt=str.maketrans('.-','01')cipheranslate(txt).split()else:cipher=cipher.split()for i in cipher:print(zi[i],end='') elif panduan=='2':plain=input('请输入你要加密的明文:').strip()codes = {'A': '.-', 'B': '-...', 'C': '-.-.', 'D': '-..','E': '.', 'F': '..-.', 'G': '--.', 'H': '....','I': '..', 'J': '.---', 'K': '-.-', 'L': '.-..','M': '--', 'N': '-.', 'O': '---', 'P': '.--.','Q': '--.-', 'R': '.-.', 'S': '...', 'T': '-','U': '..-', 'V': '...-', 'W': '.--', 'X': '-..-','Y': '-.--', 'Z': '--..','0': '-----', '1': '.----', '2': '..---', '3': '...--','4': '....-', '5': '.....', '6': '-....', '7': '--...','8': '---..', '9': '----.','.': '.-.-.-', ':': '---...', ',': '--..--', ';': '-.-.-.','?': '..--..', '=': '-...-', ''': '.----.', '/': '-..-.','!': '-.-.--', '-': '-....-', '_': '..--.-', '"': '.-..-.','(': '-.--.', ')': '-.--.-', '$': '...-..-', '&': '....','@': '.--.-.', '+': '.-.-.'}for i in plain:code(i.upper(),i)print(code,end='') elif panduan=='3':exit('谢谢惠顾!') else:print('请按要求输入!')
def zhalan(txt,key):flag=""for i in range(key):for j in range(i,len(txt),key):flag+=txt[j]return flag if __name__=='__main__':txt=input("请输入明文或者密文:".strip())for m in range(2,len(txt)):if len(txt)%m==0:flag = zhalan(txt, m)print(f'{m}栏:{flag}')
本文发布于:2024-02-02 18:12:30,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170686937445545.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |