查看此代码,如果我希望此代码从wordlist中随机获取字词,直到获得名为flag的内容,我该怎么办?
from Crypto.Cipher import AES
import base64
import os
BLOCK_SIZE = 32
PADDING = '{'
# Encrypted text to decrypt
encrypted = "Z5p+ZK9f8m9z+wVHw2SsvS0qT0DtqiTY1+yStCzXvP4="
DecodeAES = lambda c, e: c.decrypt(base64.b64decode(e)).rstrip(PADDING)
secrets = #here you need to open words.txt
for secret in secrets:
if (secret[-1:] == "\n"):
print("Error, new line character at the end of the string. This will not match!")
elif (len(secret) >= 32):
print ("Error, string too long. Must be less than 32 characters.")
else:
# create a cipher object using the secret
cipher = AES.new(secret + (BLOCK_SIZE - len(secret) % BLOCK_SIZE) * PADDING)
# decode the encoded string
decoded = DecodeAES(cipher, encrypted)
if (decoded.startswith('FLAG:')):
print ("\n")
print ("Success: "+secret+"\n")
print (decoded+"\n")
else:
print ('Wrong password')
我尝试使用模块导入它并仍然遇到同样的问题
答案 0 :(得分:0)
当您说secrets
时,您将获得所有可能性,因为文本文件中的每一行都将以换行符结尾。您可以将其取出并将[line.strip() for line in open("secrets.txt")]
定义为import javax.swing.JOptionPane;
import java.util.Date;
import java.text.*;
public class JOptionQuestionTen
{
public static void main(String[] args)
{
String input = JOptionPane.showInputDialog("Insert Date in Form MM/dd/yy");
DateFormat inputFormat = new SimpleDateFormat("MM/dd/yy");
DateFormat outputFormat = new SimpleDateFormat("dd.MM.yy");
Date date = inputFormat.parse(input);
String formattedDate = outputFormat.format(date);
JOptionPane.showMessageDialog(null, formattedDate);
}
}
答案 1 :(得分:0)
我假设您知道如何打开和阅读文件;在许多在线资料中找到这些都是微不足道的。
请注意,您的代码会按顺序遍历单词列表。要随机获取条目,请尝试以下操作:
import random
word_list = [
"apple",
"baker",
"cat",
"FLAG:",
"gorilla"
]
word = random.choice(word_list)
while not word.startswith("FLAG:"):
print word
word = random.choice(word_list)
一次长跑的输出:
cat
apple
apple
gorilla
cat
cat
baker
cat
FLAG: stop here
DONE