使用蛮力解码凯撒密码

时间:2020-07-26 17:46:49

标签: python cryptography brute-force

我正在研究Ceaser Cphier的解码部分,这就是众所周知的Bruteforce。我正在尝试将加密的单词捕获为字符串。但是即使我使用str也不转换。问题在于变量plaincode。我使用print来查看其中是否有任何内容,但输出为空。你能帮忙吗?

 def main():
#take user word and pass it to the function to encrypt it
  letters='ABCDEFGHIJLMNOPQRSTUVWXYZ'
  userinput=str(input("Enter the word to encrypt:"))
  UserInput = userinput.upper()
  print("You entered:",UserInput)
  key=int(input("Enter the key shift:"))
  sendtoincrypt(UserInput,key)
global key #send the word for incryption
  
def sendtoincrypt(UserInput,key):
  coded_char=[]
  newcode=0
  for each in UserInput:
    x=ord(each) #ord retrive the number of the ASCII of the word
    newcode=x+key
    coded_char.append(newcode)
  displaycodednum(coded_char)
    
def displaycodednum(coded_char):
  print("The coded number is:", coded_char)
  processcodedword(coded_char)

def processcodedword (coded_char):
  coded_word=[]

  # for i, c in enumerate('test'):
   #print i, c
  for each, c in enumerate(coded_char):
    y=chr(c)
    coded_word.append(y)
  displaycodedword(coded_word)

def displaycodedword(coded_word):
  print("The coded word is:",*coded_word, sep='')
  plaincode=print(*coded_word, sep='')
  str(plaincode) #-------------------------<< trying to convert it to text
  print("Converted to string:", plaincode) #--<<The out put is "None" which means its not converted...why?
  dycrypt(plaincode)

def dycrypt(plaincode):
  str(plaincode)
  decoded_word=[]
  for each, c in enumerate(plaincode): #<<---The error is here "not iratable ...because its not converted to text
    z=chr(c)
    decoded_word.append(z)
  displaydecodedword(decoded_word)

def displaydecodedword(decoded_word):
  print("The coded word is:",*decoded_word, sep='')
  plaincode=print(*decoded_word, sep='')

1 个答案:

答案 0 :(得分:0)

暴力破解凯撒密码的通常方法是获取加密的文本并尝试25种可能的密钥中的每一种。它被称为“降低字母”。

NBCM CM UH YRUGJFY
nbcm cm uh yrugjfy
ocdn dn vi zsvhkgz
pdeo eo wj atwilha
qefp fp xk buxjmib
rfgq gq yl cvyknjc
sghr hr zm dwzlokd
this is an example
uijt jt bo fybnqmf
vjku ku cp gzcorng
wklv lv dq hadpsoh
xlmw mw er ibeqtpi
ymnx nx fs jcfruqj
znoy oy gt kdgsvrk
aopz pz hu lehtwsl
bpqa qa iv mfiuxtm
cqrb rb jw ngjvyun
drsc sc kx ohkwzvo
estd td ly pilxawp
ftue ue mz qjmybxq
guvf vf na rknzcyr
hvwg wg ob sloadzs
iwxh xh pc tmpbeat
jxyi yi qd unqcfbu
kyzj zj re vordgcv
lzak ak sf wpsehdw
mabl bl tg xqtfiex
nbcm cm uh yrugjfy

然后,您必须从列出的可能性中选择正确的解密。

相关问题