您好,登錄后才能下訂單哦!
本篇文章為大家展示了怎樣用常規密碼學解加密python腳本,內容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細介紹希望你能有所收獲。
def change(c,i): c = c.lower() num = ord(c) if num >= 97 and num <= 122: num = 97 + ((num - 97) + i) % 26 return chr(num) def kaisa_jiami(string,i): string_new = '' for s in string: string_new += change(s,i) print(string_new) return string_new def kaisa_jiemi(string): for i in range(25): print('\n', i, '\n') i += 1 kaisa_jiami(string,i) def main(): print('請選擇需要的操作:') print('1:凱撒加密') print('2:凱撒解密') choice = input() if choice == '1': string = input('請輸入需要加密的字符串:') num = int(input('請輸入需要偏移的位數:')) kaisa_jiami(string,num) elif choice == '2': string = input('請輸入需要解密的字符串:') kaisa_jiemi(string) else: print('輸入錯誤,請重試!') main() if __name__ == '__main__': main()
import base64 readfile = open('base.txt','r') writefile = open('flag.txt','w') txt = readfile.readlines()[0] while True: try: txt = base64.b32decode(txt) except: txt = base64.b64decode(txt) finally: print(txt) writefile.write(txt) writefile.write('\n') writefile.close() readfile.close()
def get_text(): text=input('輸入明文:') return text def get_key(): key='' active=True while active: key=input('輸入密鑰:') if key == '': print('密鑰不能為空,請重新輸入!') else: active=False return key def init(key): s=list(range(256)) j=0 for i in range(256): j=(j+s[i]+ord(key[i%len(key)]))%256 s[i],s[j] =s[j],s[i] print('s初始置換數組為:') print(s) return s def trans_stream(message,s_box): result=[] i=j=0 for s in message: i=(i+1)%256 j=(j+s_box[i])%256 s_box[i],s_box[j]=s_box[j],s_box[i] t=(s_box[i]+s_box[j])%256 k=s_box[t] result.append(chr(ord(s)^k)) print('密文為:') print(''.join(result)) def start(): print('歡迎使用RC-4加密!')text=get_text() key=get_key() print('明文為:'+text) print('密鑰為:'+key) s=init(key) trans_stream(text,s) temp=input('回車結束程序。') start()
msg1 = 0x9a9a9a6a9aa9656699a699a566995956996a996aa6a965aa9a6aa596a699665a9aa699655a696569655a9a9a9a595a6965569a59665566955a6965a9596a99aa9a9566a699aa9a969969669aa6969a9559596669 s = bin(msg1)[2:] print s r = "" tmp = 0 for i in xrange(len(s) / 2): c = s[i * 2] if c == s[i * 2 - 1]: r += '1' else: r += '0' print hex(int(r, 2))[2:-1].decode('hex')
from __future__ import print_function while 1: a = input("input the string:") s = a.split(" ") dict = {'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 item in s: print (dict[item],end='') print("\n")
def zhalan(e): elen = len(e) field = [] for i in range(2, elen): if (elen % i == 0): field.append(i) for f in field: b = elen // f result = {x: '' for x in range(b)} for i in range(elen): a = i % b; result.update({a: result[a] + e[i]}) d = '' for i in range(b): d = d + result[i] print(d) d.lower() if __name__ == '__main__': e = 'qddpqwnp-cplen%prqwn_{_zz*d@gq}' zhalan(e)
# 五、柵欄密碼解密 ```c def zhalan(e): elen = len(e) field = [] for i in range(2, elen): if (elen % i == 0): field.append(i) for f in field: b = elen // f result = {x: '' for x in range(b)} for i in range(elen): a = i % b; result.update({a: result[a] + e[i]}) d = '' for i in range(b): d = d + result[i] print(d) d.lower() if __name__ == '__main__': e = 'qddpqwnp-cplen%prqwn_{_zz*d@gq}' zhalan(e)
n=['33DB76A7C594BFC3','CD36C2E32A371480', '8CEE9FF3933365BC','57373FE3C783A78F', '59B322834BB73B59','423719DD973C6AD3', 'C858FBEABF480DA3','3CC8C789BA7B8135'] #func1 a=1;b=2 f1={} for i in range(3,100): t=a+b f1[hex(t)[-16:]]=str(str(i)) a,b=b,t #func2 a=1;b=2;c=3 f2={} for i in range(4,100): t=a+b+c f2[hex(t)[-16:]]=str(str(i)) a,b,c=b,c,t #func3 a=1;b=2;c=3;d=4 f3={} for i in range(5,100): t=a+b+c+d f3[hex(t)[-16:]]=str(str(i)) a,b,c,d=b,c,d,t #func-4 a=1;b=2;c=3;d=4;e=5 f4={} for i in range(6,100): t=a+b+c+d+e f4[hex(t)[-16:]]=str(str(i)) a,b,c,d,e=b,c,d,e,t flag='flag{' for i in range(0,8): n[i]=n[i].lower() if n[i] in f1.keys(): flag=flag+f1[n[i]]+"_" elif n[i] in f2.keys(): flag=flag+f2[n[i]]+"_" elif n[i] in f3.keys(): flag=flag+f3[n[i]]+"_" elif n[i] in f4.keys(): flag=flag+f4[n[i]]+"_" flag=flag[:-1]+'}' print(flag)
#! /usr/bin/env python #coding=utf-8 a="8842101220480224404014224202480122" a=a.split("0") flag='' for i in range(0,len(a)): str = a[i] list=[] sum=0 for j in str: list.append(j) length = len(list) for k in range(0,length): sum+=int(list[k]) flag+=chr(sum+64) print flag
上述內容就是怎樣用常規密碼學解加密python腳本,你們學到知識或技能了嗎?如果還想學到更多技能或者豐富自己的知識儲備,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。