An unlocked terminal is displaying the following:
Encryption complete, ENC(???,T0pS3cre7key) = Bot kmws mikferuigmzf rmfrxrwqe abs perudsf! Nvm kda ut ab8bv_w4ue0_ab8v_DDUYou poke around and find this interesting file.
Từ đoạn encrypt đã cho:
#!/usr/bin/env python
import sys
alphaL = "abcdefghijklnmopqrstuvqxyz"
alphaU = "ABCDEFGHIJKLMNOPQRSTUVQXYZ"
num = "0123456789"
keychars = num+alphaL+alphaU
if len(sys.argv) != 3:
print "Usage: %s SECRET_KEY PLAINTEXT"%(sys.argv[0])
sys.exit()
key = sys.argv[1]
if not key.isalnum():
print "Your key is invalid, it may only be alphanumeric characters"
sys.exit()
plaintext = sys.argv[2]
ciphertext = ""
for i in range(len(plaintext)):
rotate_amount = keychars.index(key[i%len(key)])
if plaintext[i] in alphaL:
enc_char = ord('a') + (ord(plaintext[i])-ord('a')+rotate_amount)%26
elif plaintext[i] in alphaU:
enc_char = ord('A') + (ord(plaintext[i])-ord('A')+rotate_amount)%26
elif plaintext[i] in num:
enc_char = ord('0') + (ord(plaintext[i])-ord('0')+rotate_amount)%10
else:
enc_char = ord(plaintext[i])
ciphertext = ciphertext + chr(enc_char)
print "Encryption complete, ENC(%s,%s) = %s"%(plaintext,key,ciphertext)
Ta sửa lại 1 xíu là được, cho key và plaintext vào luôn
#!/usr/bin/env pythonimport sysalphaL = "abcdefghijklnmopqrstuvqxyz"alphaU = "ABCDEFGHIJKLMNOPQRSTUVQXYZ"num = "0123456789"keychars = num+alphaL+alphaUkey = "T0pS3cre7key"plaintext = "Bot kmws mikferuigmzf rmfrxrwqe abs perudsf! Nvm kda ut ab8bv_w4ue0_ab8v_DDU"ciphertext = ""for i in range(len(plaintext)):rotate_amount = keychars.index(key[i%len(key)])if plaintext[i] in alphaL:enc_char = ord('a') + (ord(plaintext[i])-ord('a')-rotate_amount)%26elif plaintext[i] in alphaU:enc_char = ord('A') + (ord(plaintext[i])-ord('A')-rotate_amount)%26elif plaintext[i] in num:enc_char = ord('0') + (ord(plaintext[i])-ord('0')-rotate_amount)%10else:enc_char = ord(plaintext[i])ciphertext = ciphertext + chr(enc_char)print "Encryption complete, ENC(%s,%s) = %s"%(plaintext,key,ciphertext)user_submitted = raw_input("Wait")
C:\Users\WIN7>C:\Python27\python.exe "E:\CTF\picoctf 2013\encrypt2.py"
Encryption complete, ENC(Bot kmws mikferuigmzf rmfrxrwqe abs perudsf! Nvm kda ut
ab8bv_w4ue0_ab8v_DDU,T0pS3cre7key) = You hawe successfully decrypwed the messag
e! The key is th4ts_w0rs3_th4n_DES
Key là: th4ts_w0rs3_th4n_DES

0 nhận xét:
Đăng nhận xét