Skip to content

Conversation

@dzhav
Copy link
Owner

@dzhav dzhav commented Apr 5, 2022

No description provided.

@dzhav dzhav requested a review from yulian-gilyazev April 5, 2022 21:02
dev/main.py Outdated
f.close()
sample_freqs = count_frequencies(sample_text)

if sys.argv[1] == "encode":
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если парсишь аргументы командной строки то лучше использовать argparse или что то подобное

dev/main.py Outdated
return ''.join(result_text)


def decode_vigenere(text, k):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

decode = shift с другим ключем. Не стоит несколько раз писать один и тот же код как и для цезаря

error = 0
for i in range(26):
error += abs(frequencies1[i] - frequencies2[i])
return error
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше отнормировать на 26

dev/main.py Outdated
def L2_MSE(frequencies1, frequencies2):
error = 0
for i in range(26):
error += abs(frequencies1[i] - frequencies2[i])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

это L1 мера, а не L2 и MAE, а не MSE) И MSE в своем названии подразумевает что метрика считается в L2 пространстве, и выходит что в названии некоторая тавтология. Лучше переименуй. Например просто в MAE

dev/main.py Outdated
print(shift_text(input_txt, k, "stc"))
else:
input_1 = open(sys.argv[7])
input_1 = open(arguments.input_file)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лучше считывать и записывать в файл из отдельной функции

dev/main.py Outdated
input_1.close()
output_1 = open(sys.argv[9], "w")
output_1.write(shift_text_caesar(input_txt, k))
output_1 = open(arguments.output_file, "w")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with open лучше

dev/main.py Outdated
return shift_text(text, 26 - min_k, "stc")


f = open('War_and_Peace.txt')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лучше это делать только если тебя попросили взломать текст

dev/main.py Outdated
freqs = count_frequencies(shift_text_caesar(text, 26 - k))
if L2_MSE(freqs, sample) < min_error:
min_error = L2_MSE(freqs, sample)
freqs = count_frequencies(shift_text(text, 26 - k, "stc"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

26 непонятно что это, посмотри весь код

dev/main.py Outdated
result_text = ['a' for i in range(len(text))]
for i in range(len(text)):
result_text[i] = shift(text[i], k)
if type == "stc":
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type == 'stc' совершенно непонятно. Лучше уж передавать сразу два аргумента шифр и дейтсвие

dev/main.py Outdated
if sys.argv[3] == "caesar":
k = int(sys.argv[5])

pasrsing = argparse.ArgumentParser()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лучше добавить subparser под каждое из твоих возможных действий

dev/main.py Outdated
if sys.argv[3] == "caesar":
k = int(sys.argv[5])

pasrsing = argparse.ArgumentParser()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

стоит запускать в __name__ == '__main__':

dev/main.py Outdated
k = int(sys.argv[5])

pasrsing = argparse.ArgumentParser()
pasrsing.add_argument("action", type=str, help="decode/encode/decode-without-key")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

желательно вынести парсинг аргументов в отдельную функию

@yulian-gilyazev
Copy link
Collaborator

ок

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants