我正在尝试让我的塞萨尔密码回绕。不幸的是,我不知道如何去实施它。这里是我的代码,因为它是目前:塞萨尔密码绕回
maximum_character = unciphered_text[0]
maximum_count = unciphered_text.count(unciphered_text[0])
for char in unciphered_text:
if char is not " ":
if unciphered_text.count(char) > maximum_count:
maximum_character = char
print("The most frequent character used is: ", maximum_character)
ASCII_maximum = maximum_character.lower()
ASCII_number = ord(ASCII_maximum)
print(ASCII_number)
shift_distance = ord('e')-ASCII_number
print("The shift distance is: ", shift_distance)
def caesar_cipher(unciphered_text, shift_distance):
ciphered_text = ""
for char in unciphered_text:
if char.isalpha():
cipher_process = ord(char)+shift_distance
if cipher_process > ord('z'):
cipher_process -= 26
post_translation = chr(cipher_process)
ciphered_text += post_translation
return ciphered_text
answer = caesar_cipher(unciphered_text, shift_distance)
print(answer)
虽然它最终消除在这个过程中的空间和适当的标点符号我的代码可以翻译输入到的东西可读。
Input: Frzdugv glh pdqb wlphv ehiruh wkhlu ghdwkv; Wkh ydoldqw qhyhu wdvwh ri ghdwk exw rqfh. Ri doo wkh zrqghuv wkdw L bhw kdyh khdug, Lw vhhpv wr ph prvw vwudqjh wkdw phq vkrxog ihdu; Vhhlqj wkdw ghdwk, d qhfhvvdub hqg, Zloo frph zkhq lw zloo frph
Output: Cowardsdieman_timesbeforetheirdeathsThevaliantnevertasteofdeathbutonceOfallthewondersthatI_ethaveheardItseemstomemoststrangethatmenshouldfearSeeingthatdeathanecessar_endWillcomewhenitwillcome
Desired Output: COWARDS DIE MANY TIMES BEFORE THEIR DEATHS; THE VALIANT NEVER TASTE
OF DEATH BUT ONCE. OF ALL THE WONDERS THAT I YET HAVE HEARD, IT
SEEMS TO ME MOST STRANGE THAT MEN SHOULD FEAR; SEEING THAT DEATH, A
NECESSARY END, WILL COME WHEN IT WILL COME.
所以,你想知道如何使它跳过非字母字符?你能发布一些输入,电流输出和所需的输出吗? – TemporalWolf