import base64 # 先把字母调换A换成Z,z换成a,然后倒序逐个字符转为二进制,在将二进制倒序逐步放⼊密文中 # 加密函数 defencode(): withopen('test1.txt','r') as f: result = '' for char in f.read(): if char.isalpha(): if char.islower(): result += chr(122 - ord(char) + 97) else: result += chr(90 - ord(char) + 65) else: result += char # 保留⾮字⺟字符 encrypted_text = ''.join(format(ord(char), '08b')[::-1] for char in result[::-1]) text = ''.join(chr(int(encrypted_text[i:i + 8], 2)) for i inrange(0, len(encrypted_text), 8)) withopen('m.txt','w',encoding='utf-8') as w: w.write(text) # 解密函数 defdecode(): withopen ('m.txt','r',encoding='utf-8') as f: binary_encoding = ''.join(format(ord(char), '08b') for char in f.read()) decrypted_text = ''.join(chr(int(binary_encoding[i:i + 8][::-1], 2)) for i inrange(0, len(binary_encoding), 8)) result = "" for char in decrypted_text[::-1]: if char.isalpha(): # 仅处理字母字符 if char.islower(): result += chr(122 - ord(char) + 97) else: result += chr(90 - ord(char) + 65) else: result += char # 保留非字母字符 return result # 测试 encode() print(decode())
strr='BAAAACBAAAACBAAAACBABACBAAAACABBBBCBAAAACBBAAACBBAAACBAAACBAAAACAAABBCBAAAACA ABACBAAAACACBAAAACBBAAACBBAAACAABBBCBAAAACABBBBCBBAAACAAAABCBBAAACAAAAACBAAAACBABAC BAAAACABBBBCBBAAACAAAABCBAAAACBBBBACBAAAACAABACBAAAACACBBAAACAAABBCAABBBCBAACBAAAAC AAABBCBAAAACABBBBCBAAAACAAABBCBBAAACABCBBAAACBBBAACBAAAACAAABBCBBAAACABCBAAAACBAAAA CBAAAACAABACBBAAACBBAAACBBAAACBAA' p='' for item in strr.split('C'): for i in item: if i=='A': p+='.' if i=='B': p+='-' p+=' ' print(p)
defq1(): # 奇怪的随机 random.seed(int(time.time())) for i in flag1: key = random.randint(0, 255) print(hex(key ^ i)[2:], end='') print()
defq2(): # 好像是RSA耶 p = getPrime(768) q = getPrime(768) n = p * q e = 65537 c = pow(int.from_bytes(flag2, 'big'), e, n) print('n =', n) print('c =', c) print('gift = ', p^q)
defq3(): # 好欸,gift会帮你大忙 p = getPrime(1024) q = getPrime(1024) n = p * q e = 65537 c = pow(int.from_bytes(flag3, 'big'), e, n) print('n =', n) print('c =', c) print('gift = ', p>>128<<128)
defq4(): # 好像是仿射密码O.o? whileTrue: a = random.randint(1, 255) if gmpy2.gcd(a, 256) == 1: break b = random.randint(1, 255) for i in flag4: print(hex((a * i + b) % 256)[2:], end='') print()
if __name__ == '__main__': q1() q2() q3() q4()
以下是输出哦
1 2 3 4 5 6 7 8
2751f014111e3b6c99ee0c1ffdb n = 1314967568472111655011215741611204058445271915416828628976948574202708111113415916782529564877904510060100803618784633689042321638758890645109937974712421243866535532456352916950588338339187646436203001238668325551347997600131482407828109866095656006182698438881347920478482748383266084375469393195026344711785310217699668578201163056580472767419018903528661196463556987391507948440998062000579441372864166820211363778622151084978457148816155840807309523468514737 c = 714823142050694444798764890363987288553278765888515447347831293603591520430161682430297132349376978132042520437327068469772693958392477696379693493642863620785374026864080575939701745789140360488363320872736223330713870595633123116802744486276013405587197268990549236382568387872542676495602480646325253629669013709107520366724483033424481299421502754615414281425593755447617407229874129642080822627133940004511103227817223979099305528104304426752826435278744203 gift = 694528314614597200478964686223773661923043423469284409313765066401043617480074529594821605533148713125208795494551521792270222854272201394082237861960338619535572344777791563055216095704867407678882350444988644328937569643241544288 n = 20101595147488798389289868752077592121180253794961350303684476074373382651162731030012542663577893620308907070951746061694810120788982509030822305454034643552610490056731682663813203862472113551826607640566795678610949455082852245033866512073384496721650061160969170378452907296185135402960957516973093880566693353802761058535651054861356890198762625906274359149366964537600779463809503980853549061147727380608568295775123554356803159242239358725074252375272854601903195327695079676359178192820686851184017376039555552976394457195879284582630650973305825663350399524155712775283354061399128621452790374630281212763003 c = 12916869040409779953862249590282734760889861257156464352877117728249327035935827174031177155628087674873344162482162598075083427663045411953253215416066596951253127182274293689595996627589876729221669619649677597183487460364944967147487385650490911248852929910928587491029306263562185263950606812592475864353923466852485771147419452880303553179714475139219893582609435132350841035206708438665812448813540495655049342336073923165823699487070835934846037597897302098717779471902780411938252727074409684431893731139714331370842123964447381194512912853698166082589121848926068491107342775937301790556130418367711223242288 gift = 155273709359681889478466954690933897871319254905155359883381942077328267407476770359318044347630379957553960166391859807222785247670601013189925775520199087524163394638865369160945885653041774469602670214007577290385646748614938981814185337538533954972019132315963866996273805444698616794987042402666683564032 4d9a25e42e9128de650722bde9dfe
from Crypto.Cipher import AES import random from gmpy2 import * defgenerate_random_bytes(length): returnbytes([random.randint(0, 255) for _ inrange(length)]) defmain(): enc_flag = b"\x189\xdb\x11t\xb8\xc5\xe8\xe5\xa8n\x04'XH\x13\x9c9\xe8\x88\x0c>\xe7\xde\t\xa0\xad\x7f\xb4u\x1f\xc1" hex_key_str ="d567b916876527d891b14d536be997e8d567b916876527d891b14d536be997e8" hex_iv_str = "33a4235ea4d294c113c5ff98447c927a" key = bytes.fromhex(hex_key_str) iv = bytes.fromhex(hex_iv_str) aes = AES.new(key, AES.MODE_CBC, iv) print(aes.decrypt(enc_flag))
if __name__ == "__main__": main() # flag{O.o_y0u_can_so1v3_AES_now!}
低头看看手机和电脑?
根据题目和A、B很明显的键盘密码,其中A是26键(两种不同形式),B是9键可知B为key,A为virginia,又提示密文是经过维吉尼亚密码进行加密而且密钥也给出了,也就是`virginia 解密即可 flag{Congratulations!You already know the keyboard and the Virginia!}
1 2 3 4 5 6 7 8 9 10 11 12
1.键盘密码(Keyboard Cipher)特征/特点:利⽤键盘的特性制作的密码,常见有计算机的键盘和⼿机的键盘,加密的⽅式有坐标法和顺序法。 1)坐标法: Y轴:1 QWE RTY UIOP 2 ASD FGH JKL 3 ZXC VBN M X轴:12345678910 eq:密文:2251914161 对应明文:story 2)顺序法:Q W E R T Y U I O P 1 2 3 4 5 6 7 8 9 10 A S D F G H J K L 11 12 13 14 15 16 17 18 19 Z X C V B N M 20 21 22 23 24 25 26 eq:密⽂:125947对应明⽂:story 2.手机九宫格键盘密码特征特点:密⽂⽤数字0-9表示a-z的字符集字母不区分大小写 密文:21222331323341424351525361626371727381828391929394 明文:abcdefghijklmnopqrtuvwxyz 3.维吉尼亚密码(Vigenère Cipher)特征特点:维吉尼亚密码(Vigenère Cipher)是在单⼀恺撒密码的基础上扩展出多表代换密码,根据密钥(当密钥长度⼩于明文长度时可以循环使⽤)来决定用哪一行的密表来进行替换,以此来对抗字频统计
仔细观察,注意加粗部分单词,组合后得到句子。 If you can read this sentence, look at the key again, by transforming you become to the answer. 翻译⼀下:如果你能读懂这句话,再看一遍密钥,通过转变你会接近答案。