【发布时间】:2019-05-18 12:17:21
【问题描述】:
我试图将暴力破解阶段 (3) 中的解密限制在 ASCII 32 和 ASCII 126 之间。在前两个阶段我已经成功了,但是在暴力破解期间我在实现它时遇到了一些麻烦,所以我的结果回来准确。所需的输出是:
*** Menu ***
1. Encrypt string
2. Decrypt string
3. Brute force decryption
4. Quit
What would you like to do [1,2,3,4]? 3
Please enter string to decrypt: ykixkz&yw{oxxkr
Offset: 1 = Decrypted string: xjhwjy%xvznwwjq
Offset: 2 = Decrypted string: wigvix$wuymvvip
Offset: 3 = Decrypted string: vhfuhw#vtxluuho
Offset: 4 = Decrypted string: ugetgv"uswkttgn
Offset: 5 = Decrypted string: tfdsfu!trvjssfm
Offset: 6 = Decrypted string: secret squirrel
Offset: 7 = Decrypted string: rdbqds~rpthqqdk
Offset: 8 = Decrypted string: qcapcr}qosgppcj
Offset: 9 = Decrypted string: pb`obq|pnrfoobi
Offset: 10 = Decrypted string: oa_nap{omqennah
如你所见,它需要产生“秘密松鼠”。
在暴力破解中,我不知道在哪里执行
for char in stringEncrypt:
x = ord(char)
x = x + offsetValue
while x < 32:
x += 95
while x > 126:
x -= 95
total += chr(x)
所以我还可以实现从 ASCII 32 解密为 ASCII 126 的输出。
任何帮助将不胜感激。
我已尝试将其制成一个 while 循环,并将其放在代码中的不同位置。
print("*** Menu ***")
print(" ")
print("1. Encrypt string")
print("2. Decrypt string")
print("3. Brute force decryption")
print("4. Quit")
print(" ")
selection = int(input("What would you like to do [1,2,3,4]? "))
while selection == 1:
stringEncrypt = input("Please enter string to encrypt: ")
offsetValue = int(input("Please enter offset value (1 to 94): "))
total = ""
for char in stringEncrypt:
x = ord(char)
x = x + offsetValue
while x < 32:
x += 95
while x > 126:
x -= 95
total += chr(x)
print(" ")
print("Encrypted string:")
print(total)
print(" ")
print("*** Menu ***")
print(" ")
print("1. Encrypt string")
print("2. Decrypt string")
print("3. Brute force decryption")
print("4. Quit")
print(" ")
selection = int(input("What would you like to do [1,2,3,4]? "))
while selection == 2:
stringDecrypt = input("Please enter string to decrypt: ")
offsetValue = int(input("Please enter offset value (1 to 94): "))
total = ""
for char in stringDecrypt:
x = ord(char)
x = x - offsetValue
while x < 32:
x += 95
while x > 126:
x -= 95
total += chr(x)
print(" ")
print("Decrypted string:")
print(total)
print(" ")
print("*** Menu ***")
print(" ")
print("1. Encrypt string")
print("2. Decrypt string")
print("3. Brute force decryption")
print("4. Quit")
print(" ")
selection = int(input("What would you like to do [1,2,3,4]? "))
while selection == 3:
stringDecrypt = input("Please enter string to decrypt: ")
decryptList = list(stringDecrypt)
offsetValue = 0
decryptIndex = 0
for offsetValue in range(1, 95, 1):
for decryptIndex in range(len(decryptList)):
shifting = (ord(decryptList[decryptIndex]) - ord(" ") - offsetValue) % 95
chrDecrypt = chr(shifting + ord(" "))
decryptList[decryptIndex] = chrDecrypt
decryptIndex += 1
stringDecrypt = ''.join(decryptList)
print("Offset", offsetValue, " = Decrypted string:", stringDecrypt)
print(" ")
print("*** Menu ***")
print(" ")
print("1. Encrypt string")
print("2. Decrypt string")
print("3. Brute force decryption")
print("4. Quit")
print(" ")
selection = int(input("What would you like to do [1,2,3,4]?"))
if selection == 4:
print("Goodbye.")
我希望输出是,输入 ykixkz&yw{oxxkr:
Offset: 1 = Decrypted string: xjhwjy%xvznwwjq
Offset: 2 = Decrypted string: wigvix$wuymvvip
Offset: 3 = Decrypted string: vhfuhw#vtxluuho
Offset: 4 = Decrypted string: ugetgv"uswkttgn
Offset: 5 = Decrypted string: tfdsfu!trvjssfm
Offset: 6 = Decrypted string: secret squirrel
Offset: 7 = Decrypted string: rdbqds~rpthqqdk
Offset: 8 = Decrypted string: qcapcr}qosgppcj
Offset: 9 = Decrypted string: pb`obq|pnrfoobi
Offset: 10 = Decrypted string: oa_nap{omqennah
但我得到了:
Offset 1 = Decrypted string: xjhwjy%xvznwwjq
Offset 2 = Decrypted string: vhfuhw#vtxluuho
Offset 3 = Decrypted string: secret squirrel
Offset 4 = Decrypted string: oa_nap{omqennah
Offset 5 = Decrypted string: j\Zi\kvjhl`ii\c
Offset 6 = Decrypted string: dVTcVepdbfZccV]
Offset 7 = Decrypted string: ]OM\O^i][_S\\OV
Offset 8 = Decrypted string: UGETGVaUSWKTTGN
Offset 9 = Decrypted string: L><K>MXLJNBKK>E
Offset 10 = Decrypted string: B42A4CNB@D8AA4;
(最多 94 个)。
【问题讨论】:
-
这是一个引人入胜且写得很好的第一个问题,尽管我认为更具体的标题会有所帮助。
-
已修订。这样更好吗?
-
看起来你至少用负值解密。你的凯撒密码似乎走错了方向。
-
@MaartenBodewes 你知道这是在哪里发生的吗?
-
不,因为您没有向我们展示复制问题的完整代码。
标签: python encryption cryptography ascii