К вам попал зашифрованный текст, означающий большую истину для многих программистов на Python. Напишите программу, которая реализует алгоритм дешифровки этого текста. Расшифруйте текст с помощью своей программы, а затем найдите его в интернете.
vujgvmCfb tj ufscfu ouib z/vhm jdjuFyqm jt fscfuu uibo jdju/jnqm fTjnqm tj scfuuf ibou fy/dpnqm yDpnqmf jt cfuufs boui dbufe/dpnqmj uGmb tj fuufsc ouib oftufe/ bstfTq jt uufscf uibo otf/ef uzSfbebcjmj vout/dp djbmTqf dbtft (ubsfo djbmtqf hifopv up csfbl ifu t/svmf ipvhiBmu zqsbdujdbmju fbutc uz/qvsj Fsspst tipvme wfsof qbtt foumz/tjm omfttV mjdjumzfyq odfe/tjmf Jo fui dfgb pg hvjuz-bncj gvtfsf fui ubujpoufnq up ftt/hv Uifsf vmetip fc pof.. boe sbcmzqsfgf zpom pof pvt..pcwj xbz pu pe ju/ Bmuipvhi uibu bzx bzn puo cf wjpvtpc bu jstug ttvomf sfzpv( i/Evud xOp tj scfuuf ibou /ofwfs uipvhiBm fsofw jt fopgu cfuufs boui iu++sjh x/op gJ ifu nfoubujpojnqmf tj eibs pu mbjo-fyq tju( b bec /jefb Jg fui foubujpojnqmfn jt fbtz up bjo-fyqm ju znb cf b hppe jefb/ bnftqbdftO bsf pof ipoljoh sfbuh efbj .. fu(tm pe psfn gp tf"uip
Python
Интересная задача на PYTHON?
За что забанил правильный ответ? Zen of Python. Ни разу не интересно
cyberforum.ru/python-beginners/thread2827632.html
cyberforum.ru/python-beginners/thread2827632.html
а это оказался хеш зашифрованный в одну сторону, и ты потратил 1000 лет на его дешифровку
Павел Пичугин
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practically it beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one and preferably only one obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than right now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea let's do
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practically it beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one and preferably only one obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than right now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea let's do
def decryption(messenge):
````translated = ""
````for i_word in messenge:
````````if i_word in letters:
````````````num_index = letters.find(i_word)
````````````translated += letters[num_index - 1]
````````else:
````````````translated += i_word
````return translated
def shift(text, key):
````word_ln = len(text)
````shift = key % word_ln
````text = text[-shift:] + text[:-shift]
````return text
text = 'vujgvmCfb tj ufscfu ouib z/vhm jdjuFyqm jt fscfuu uibo jdju/jnqm fTjnqm tj scfuuf ibou fy/' \
'dpnqm yDpnqmf jt cfuufs boui dbufe/dpnqmj uGmb tj fuufsc ouib oftufe/ bstfTq jt uufscf uibo otf/' \
'ef uzSfbebcjmj vout/dp djbmTqf dbtft (ubsfo djbmtqf hifopv up csfbl ifu t/svmf ipvhiBmu zqsbdujdbmju fbutc uz/' \
'qvsj Fsspst tipvme wfsof qbtt foumz/tjm omfttV mjdjumzfyq odfe/tjmf Jo fui dfgb pg hvjuz-bncj gvtfsf fui ubujpoufnq up ftt/' \
'hv Uifsf vmetip fc pof.. boe sbcmzqsfgf zpom pof pvt..pcwj xbz pu pe ju/ ' \
'Bmuipvhi uibu bzx bzn puo cf wjpvtpc bu jstug ttvomf sfzpv( i/Evud xOp tj scfuuf ibou /' \
'ofwfs uipvhiBm fsofw jt fopgu cfuufs boui iu++sjh x/op gJ ifu nfoubujpojnqmf tj eibs pu mbjo-fyq tju( b bec /' \
'jefb Jg fui foubujpojnqmfn jt fbtz up bjo-fyqm ju znb cf b hppe jefb/ ' \
'bnftqbdftO bsf pof ipoljoh sfbuh efbj .. fu(tm pe psfn gp tf"uip'.split()
letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
text_2 = []
key = 3
for i_word in text:
````text_decryption = decryption(i_word)
````shift_text = shift(text_decryption, key)
````if shift_text.endswith("/"):
````````key += 1
````````text_2.append(shift_text)
````else:
````````text_2.append(shift_text)
text_2 = " ".join(text_2)
text_2 = text_2.replace("+", "*")
text_2 = text_2.replace("-", ",")
text_2 = text_2.replace("(", "'")
text_2 = text_2.replace("..", "--")
text_2 = text_2.replace('"', "!")
text_2 = text_2.replace("/", ".\n")
print(text_2)
````translated = ""
````for i_word in messenge:
````````if i_word in letters:
````````````num_index = letters.find(i_word)
````````````translated += letters[num_index - 1]
````````else:
````````````translated += i_word
````return translated
def shift(text, key):
````word_ln = len(text)
````shift = key % word_ln
````text = text[-shift:] + text[:-shift]
````return text
text = 'vujgvmCfb tj ufscfu ouib z/vhm jdjuFyqm jt fscfuu uibo jdju/jnqm fTjnqm tj scfuuf ibou fy/' \
'dpnqm yDpnqmf jt cfuufs boui dbufe/dpnqmj uGmb tj fuufsc ouib oftufe/ bstfTq jt uufscf uibo otf/' \
'ef uzSfbebcjmj vout/dp djbmTqf dbtft (ubsfo djbmtqf hifopv up csfbl ifu t/svmf ipvhiBmu zqsbdujdbmju fbutc uz/' \
'qvsj Fsspst tipvme wfsof qbtt foumz/tjm omfttV mjdjumzfyq odfe/tjmf Jo fui dfgb pg hvjuz-bncj gvtfsf fui ubujpoufnq up ftt/' \
'hv Uifsf vmetip fc pof.. boe sbcmzqsfgf zpom pof pvt..pcwj xbz pu pe ju/ ' \
'Bmuipvhi uibu bzx bzn puo cf wjpvtpc bu jstug ttvomf sfzpv( i/Evud xOp tj scfuuf ibou /' \
'ofwfs uipvhiBm fsofw jt fopgu cfuufs boui iu++sjh x/op gJ ifu nfoubujpojnqmf tj eibs pu mbjo-fyq tju( b bec /' \
'jefb Jg fui foubujpojnqmfn jt fbtz up bjo-fyqm ju znb cf b hppe jefb/ ' \
'bnftqbdftO bsf pof ipoljoh sfbuh efbj .. fu(tm pe psfn gp tf"uip'.split()
letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
text_2 = []
key = 3
for i_word in text:
````text_decryption = decryption(i_word)
````shift_text = shift(text_decryption, key)
````if shift_text.endswith("/"):
````````key += 1
````````text_2.append(shift_text)
````else:
````````text_2.append(shift_text)
text_2 = " ".join(text_2)
text_2 = text_2.replace("+", "*")
text_2 = text_2.replace("-", ",")
text_2 = text_2.replace("(", "'")
text_2 = text_2.replace("..", "--")
text_2 = text_2.replace('"', "!")
text_2 = text_2.replace("/", ".\n")
print(text_2)
Сергей Ворожцов
ПЦ! Браво. Только начал догадываться и то лишь поэтапно, а тут Андрей Мустафин выложил "на блюдечке" решение. Мое искреннее браво!
def caesar_minus_one(encrypted_list):
letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
output_list = []
for word in encrypted_list:
corrected_word = ''.join([letters[letters.index(i) - 1] if i in letters else i for i in word])
output_list.append(corrected_word)
return output_list
def correct_word(encrypted_list):
output_list = []
delta = 3
for word in encrypted_list:
corrected_word = ''.join([word[-delta % len(word):], word[:-delta % len(word)]])
output_list.append(corrected_word)
if '/' in corrected_word:
delta += 1
return output_list
def replaces(encrypted_text):
encrypted_text = encrypted_text.replace("+", "*")
encrypted_text = encrypted_text.replace("-", ",")
encrypted_text = encrypted_text.replace("(", "'")
encrypted_text = encrypted_text.replace("..", "--")
encrypted_text = encrypted_text.replace('"', "!")
encrypted_text = encrypted_text.replace("/", ".\n")
return encrypted_text
text = input('Введите текст: ').split()
decrypted_text = ' '.join(caesar_minus_one(correct_word(text)))
print('\nРасшифрованный текст:\n', replaces(decrypted_text))
# Самое элегантное и полное решение, которое нашёл вот здесь:
https://pastebin.com/LvSfGBC4
def step1(encrypted_list):
# здесь сделаем так, чтобы большая буква всегда была вначале слова
# для этого будем смещать символы каждого слова вправо
# смещение в первом предложении = 3, во втором = 4 и так далее
# признак конца предложения: / (он тоже окажется на своём месте после работы алгоритма - в конце слова)
output_list = []
delta = 3
for word in encrypted_list:
corrected_word = ''.join(
[
word[-delta % len(word):], word[:-delta % len(word)]
]
)
output_list.append(corrected_word)
if '/' in corrected_word:
delta += 1
return output_list
def step2(encrypted_list):
# здесь применим алгоритм Цезаря со смещением -1
abc = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
output_list = []
for word in encrypted_list:
corrected_word = ''.join(
[abc[abc.index(s) - 1] if s in abc else s for s in word]
)
output_list.append(corrected_word)
return output_list
input_str = 'vujgvmCfb tj ufscfu ouib z/vhm jdjuFyqm jt fscfuu uibo jdju/jnqm fTjnqm tj scfuuf ibou fy/dpnqm ' \
'yDpnqmf jt cfuufs boui dbufe/dpnqmj uGmb tj fuufsc ouib oftufe/ bstfTq jt uufscf uibo otf/ef ' \
'uzSfbebcjmj vout/dp djbmTqf dbtft (ubsfo djbmtqf hifopv up csfbl ifu t/svmf ipvhiBmu ' \
'zqsbdujdbmju fbutc uz/qvsj Fsspst tipvme wfsof qbtt foumz/tjm omfttV mjdjumzfyq odfe/tjmf ' \
'Jo fui dfgb pg hvjuz-bncj gvtfsf fui ubujpoufnq up ftt/hv Uifsf vmetip fc pof.. ' \
'boe sbcmzqsfgf zpom pof pvt..pcwj xbz pu pe ju/ Bmuipvhi uibu bzx bzn puo cf wjpvtpc bu jstug ' \
'ttvomf sfzpv( i/Evud xOp tj scfuuf ibou /ofwfs uipvhiBm fsofw jt fopgu cfuufs boui ' \
'iu++sjh x/op gJ ifu nfoubujpojnqmf tj eibs pu mbjo-fyq tju( b bec /jefb Jg fui foubujpojnqmfn jt ' \
'fbtz up bjo-fyqm ju znb cf b hppe jefb/ bnftqbdftO bsf pof ipoljoh sfbuh efbj .. fu(tm pe psfn gp tf"uip'
input_list = input_str.split()
print(
' '.join(
step2(step1(input_list))
).replace('/', '\n')
)
https://pastebin.com/LvSfGBC4
def step1(encrypted_list):
# здесь сделаем так, чтобы большая буква всегда была вначале слова
# для этого будем смещать символы каждого слова вправо
# смещение в первом предложении = 3, во втором = 4 и так далее
# признак конца предложения: / (он тоже окажется на своём месте после работы алгоритма - в конце слова)
output_list = []
delta = 3
for word in encrypted_list:
corrected_word = ''.join(
[
word[-delta % len(word):], word[:-delta % len(word)]
]
)
output_list.append(corrected_word)
if '/' in corrected_word:
delta += 1
return output_list
def step2(encrypted_list):
# здесь применим алгоритм Цезаря со смещением -1
abc = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
output_list = []
for word in encrypted_list:
corrected_word = ''.join(
[abc[abc.index(s) - 1] if s in abc else s for s in word]
)
output_list.append(corrected_word)
return output_list
input_str = 'vujgvmCfb tj ufscfu ouib z/vhm jdjuFyqm jt fscfuu uibo jdju/jnqm fTjnqm tj scfuuf ibou fy/dpnqm ' \
'yDpnqmf jt cfuufs boui dbufe/dpnqmj uGmb tj fuufsc ouib oftufe/ bstfTq jt uufscf uibo otf/ef ' \
'uzSfbebcjmj vout/dp djbmTqf dbtft (ubsfo djbmtqf hifopv up csfbl ifu t/svmf ipvhiBmu ' \
'zqsbdujdbmju fbutc uz/qvsj Fsspst tipvme wfsof qbtt foumz/tjm omfttV mjdjumzfyq odfe/tjmf ' \
'Jo fui dfgb pg hvjuz-bncj gvtfsf fui ubujpoufnq up ftt/hv Uifsf vmetip fc pof.. ' \
'boe sbcmzqsfgf zpom pof pvt..pcwj xbz pu pe ju/ Bmuipvhi uibu bzx bzn puo cf wjpvtpc bu jstug ' \
'ttvomf sfzpv( i/Evud xOp tj scfuuf ibou /ofwfs uipvhiBm fsofw jt fopgu cfuufs boui ' \
'iu++sjh x/op gJ ifu nfoubujpojnqmf tj eibs pu mbjo-fyq tju( b bec /jefb Jg fui foubujpojnqmfn jt ' \
'fbtz up bjo-fyqm ju znb cf b hppe jefb/ bnftqbdftO bsf pof ipoljoh sfbuh efbj .. fu(tm pe psfn gp tf"uip'
input_list = input_str.split()
print(
' '.join(
step2(step1(input_list))
).replace('/', '\n')
)
Дима Гришин
Код хорош, спасибо автору. Но малость не доработан
Похожие вопросы
- Решение задач по python
- Нужно решить задачу на Python
- Помогите решить задачу на Python. Никак не могу решить задачу, больше дня не могу найти ответ! Никакой код не работает.
- Python# Можно помощь с задачей на Python
- Еще одна задача в Python
- Пожалуйста, помогите решить задачу на Python. Упражнения 57,58,59,60.
- Задача на Python
- Пожалуйста, помогите решить задачу на Python. Упражнение 124, 125, 146
- Помогите пожалуйста с задачей на Python.
- Помогите пж с задачей по Python.
В забанином ответе, нет конкретного кода!
Просто задача интересная, и возможно есть ещё другие методы её решения, которые я не знаю.
Тот код, на который вы ссылаетесь, с ошибкой. Там не определена переменная. А может я чего-то и не понял, так разъясните, вы же - Высший разум!