首页 » Web前端 » php凯撒加密技巧_CTFCapture The Flag密码学根本

php凯撒加密技巧_CTFCapture The Flag密码学根本

访客 2024-11-04 0

扫一扫用手机浏览

文章目录 [+]

密码学实在很烧脑,有点偏理论数学,成为合法黑客是一件不随意马虎的事情。
2%的是天赋型选手,类似李白,98%是牛马型选手,比如高适。
纵不雅观20年的黑客发展之路,合法黑客早已成为企业高管,但是欲练此功,必会代码(c、java、python、php多多益善),练练不忘,必有回响(OverTheWire、CTF365、CTFtime、vulnhub),国际认证,势必捷径(GPEN认证、CEH认证、OSCP认证,CISSP认证),加油吧~

ailx10

php凯撒加密技巧_CTFCapture The Flag密码学根本 php凯撒加密技巧_CTFCapture The Flag密码学根本 Web前端

网络安全精良回答者

php凯撒加密技巧_CTFCapture The Flag密码学根本 php凯撒加密技巧_CTFCapture The Flag密码学根本 Web前端
(图片来自网络侵删)

网络安全硕士

去咨询

1、凯撒密码

相传有一位大帝叫 Caesar ,他发明了一种神秘的编码,你能解开这段密文吗?密文内容:mshn{jhlzhy_pz_mbuufek}。
flag格式为flag{字符串}。

凯撒密码是一种更换密码,通过将字母按照一个固定的偏移量进行更换来加密。
根据给出的密文,我们须要考试测验所有可能的偏移量来解密。
利用python编码:

# -- coding: utf-8 --def decrypt_caesar(ciphertext, shift): decrypted = '' for char in ciphertext: if char.isalpha(): shifted = ord(char) - shift if char.islower(): if shifted < ord('a'): shifted += 26 elif char.isupper(): if shifted < ord('A'): shifted += 26 decrypted += chr(shifted) else: decrypted += char return decrypted# 密文ciphertext = "mshn{jhlzhy_pz_mbuufek}"# 考试测验解密并输出所有可能的偏移量结果for i in range(26): decrypted_text = decrypt_caesar(ciphertext, i) print(f"Shift {i}: {decrypted_text}")

2、Rot13加密

加密一次,再来一次,然后回到出发点。
1Ebbg8Vf7Abg3Nyybjrq

rot13是一种大略的更换密码,实际上是凯撒密码的一种分外形式,它的解密过程便是再次运用rot13加密。
利用python编码:

# -- coding: utf-8 --def decrypt_rot13(ciphertext): decrypted = '' for char in ciphertext: if char.isalpha(): # Check if the character is a letter shifted = ord(char) - 13 if char.islower(): if shifted < ord('a'): shifted += 26 elif char.isupper(): if shifted < ord('A'): shifted += 26 decrypted += chr(shifted) else: decrypted += char return decrypted# 密文ciphertext = "1Ebbg8Vf7Abg3Nyybjrq"# 解密rot13并输出结果decrypted_text = decrypt_rot13(ciphertext)print(f"Decrypted text: {decrypted_text}")# Decrypted text: 1Root8Is7Not3Allowed

3、栏栅密码

Caesar 被困住了2333333,13 根栅栏,怎么办? h{igr},aarclietflhf-_peecirroc,eo_fhlels_caifnge

栏栅密码是一种置换密码,它通过在一定规则下将明文的字母写身分歧行形成一种特定模式来加密信息。
解密这种密码须要知道加密时用的行数。
利用python编码:

# -- coding: utf-8 --def decrypt_rail_fence(ciphertext, rails): fence = [['' for _ in range(len(ciphertext))] for _ in range(rails)] direction = -1 # 掌握铁栏的方向,向上或向下 row, column = 0, 0 for char in ciphertext: fence[row][column] = '' if row == 0 or row == rails - 1: direction = -1 # 到达铁栏上端或下端时改变方向 row += direction column += 1 # 根据铁栏的模式重新排列密文 idx = 0 for i in range(rails): for j in range(len(ciphertext)): if fence[i][j] == '' and idx < len(ciphertext): fence[i][j] = ciphertext[idx] idx += 1 # 读取解密后的明文 direction = -1 row, column = 0, 0 plaintext = '' for _ in range(len(ciphertext)): plaintext += fence[row][column] if row == 0 or row == rails - 1: direction = -1 row += direction column += 1 return plaintextciphertext = "h{igr},aarclietflhf-_peecirroc,eo_fhlels_caifnge"for num_rails in range(4,30): # 密文和假设的行数 # 解密栏栅密码并输出结果 decrypted_text = decrypt_rail_fence(ciphertext, num_rails) print(f"Decrypted text: {decrypted_text}")

4、维吉尼亚密码

本日来和 Caesar 学习一点新知识吧: Google下?听说与FLAG这个字符串有关:kwam{atgksprklzojozb}

维吉尼亚密码是一种多表密码,利用一个关键字或短语来加密。
在解密维吉尼亚密码时,我们须要知道利用的密钥。
解密维吉尼亚密码的过程涉及利用密钥对密文进行逆运算,将其还原为原始。
利用python编码:

# -- coding: utf-8 --def vigenere_decrypt(ciphertext, keyword): decrypted = '' keyword = keyword.upper() key_length = len(keyword) non_alpha_count = 0 for i, char in enumerate(ciphertext): if char.isalpha(): shift = ord(keyword[(i - non_alpha_count) % key_length]) - ord('A') if char.islower(): decrypted += chr((ord(char) - ord('a') - shift) % 26 + ord('a')) elif char.isupper(): decrypted += chr((ord(char) - ord('A') - shift) % 26 + ord('A')) else: decrypted += char non_alpha_count += 1 return decrypted# 密文和密钥ciphertext = 'kwam{atgksprklzojozb}'keyword = 'FLAG'# 解密decrypted_text = vigenere_decrypt(ciphertext, keyword)print("Decrypted Text:", decrypted_text)# Decrypted Text: flag{vigeneregoodjob}

发布于 2024-01-06 14:32・IP 属地美国

相关文章

乐高,创意无限,搭建未来的梦想乐园

乐高,这个源自丹麦的品牌,自诞生以来,便以其独特的创意和无限的可能性,吸引了全球无数小朋友和大朋友的热爱。乐高不仅仅是一种玩具,更...

Web前端 2024-12-05 阅读0 评论0