.
This commit is contained in:
43
bac1/q1/renforcement/renforcement_2510/ex3.py
Normal file
43
bac1/q1/renforcement/renforcement_2510/ex3.py
Normal file
@ -0,0 +1,43 @@
|
||||
def find_max_count(in_list):
|
||||
max_count = 0
|
||||
for i in in_list:
|
||||
count = 0
|
||||
for j in in_list:
|
||||
if j == i:
|
||||
count += 1
|
||||
if max_count < count:
|
||||
el = i
|
||||
max_count = count
|
||||
return el
|
||||
|
||||
|
||||
def ask_word():
|
||||
word = input('input your encrypted word separated with space ' ' : ')
|
||||
return word.split()
|
||||
|
||||
|
||||
def new_alphabet(translation):
|
||||
alphabet = 'abcdefghijklmnopqrstuvwxyz'
|
||||
ret = alphabet[translation:] + alphabet[:translation]
|
||||
return ret
|
||||
|
||||
|
||||
def decode(to_decode):
|
||||
"""decode en trouvant le e qui est la chaine de character la plus presente
|
||||
|
||||
:to_decode: TODO
|
||||
:returns: TODO
|
||||
|
||||
"""
|
||||
max_char = int(find_max_count(to_decode))
|
||||
decalage = 5 - max_char
|
||||
language = new_alphabet(decalage)
|
||||
decoded = [language[int(i) - 1] for i in to_decode]
|
||||
|
||||
return decoded
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
letters = ask_word()
|
||||
d = decode(letters)
|
||||
[print(i, end='') for i in d]
|
Reference in New Issue
Block a user