Skip to content

Branch test exo2 #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
54 changes: 53 additions & 1 deletion Exercice_1_-_Le_champ_de_Noel/champ.py
Original file line number Diff line number Diff line change
@@ -1 +1,53 @@
# Met ton code ici
#!/usr/bin/env python3

from random import randrange

def main():
# Columns = 7 Lines = 5
TREE = [
" ^",
" ^ ^",
" ( o )",
"( o o )",
" U"
]
NB_TREES = 6

NB_COLUMN = 60 # Min 7+2+2 = 11 (sans les bordures (+2))
NB_LINES = 40 # Min 5+3 = 8 (sans les bordures (+2))

VERTICAL_EDGE = (NB_COLUMN + 2) * '#'
LINE_WO_TREE = '#' + ' ' * (NB_COLUMN) + '#'

TREE_COORD = [(randrange(4, NB_COLUMN + 1 - 3),randrange(5, NB_LINES + 1)) for tree in range(NB_TREES)]

TREE_COORD = sorted(TREE_COORD, key=lambda y: y[1])
X_COORD = [TREE_COORD[tree][0] for tree in range(NB_TREES)]
Y_COORD = [TREE_COORD[tree][1] for tree in range(NB_TREES)]

print(TREE_COORD)
print(X_COORD)
print(Y_COORD, "\n")

# J'ai descendu tout ce qui concernait la forest ici... c'est plus clair
forest = [VERTICAL_EDGE] + [LINE_WO_TREE for i in range(NB_LINES)] + [VERTICAL_EDGE]
for y in range(NB_LINES+2):
forest[y] = list(forest[y].strip())

# La nouvelle double boucle
for i in range(NB_TREES):
TREE_HEIGHT = len(TREE)
X_OFFSET = 3
for tree_line in range(TREE_HEIGHT):
Y = Y_COORD[i] - (TREE_HEIGHT - tree_line - 1)
X_START = X_COORD[i] - X_OFFSET
X_END = X_COORD[i] - X_OFFSET + len(TREE[tree_line])

forest[Y][X_START:X_END] = TREE[tree_line]

for i in range(len(forest)):
print(''.join(forest[i]))
print("\n")

if __name__ == '__main__':
main()
46 changes: 32 additions & 14 deletions Exercice_2_-_Le_chiffre_de_Cesar/caesar.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,39 +81,57 @@
']'
"""

import string

def do_cipher(plain_text: str, key: int) -> str:
# Met ton code ici
return "Il faudrait retourner un vrai truc ;)"

LIM_MIN_DOWN = ord('A')
LIM_MIN_UP = ord('Z')
ALPHABET_LOOP = len(string.ascii_uppercase)

cipher_text = []

plain_text = plain_text.upper()

for i in plain_text:
if i in string.ascii_uppercase:
ascii_value_plain = ord(i)
ascii_value_cipher = ord(i) - key
if key < 0:
if ascii_value_cipher > LIM_MIN_UP:
ascii_value_cipher -= ALPHABET_LOOP
else :
if ascii_value_cipher < LIM_MIN_DOWN:
ascii_value_cipher += ALPHABET_LOOP
cipher_text.append(chr(ascii_value_cipher))
else:
cipher_text.append(i)
cipher_text_string = "".join(cipher_text)
return cipher_text_string

def do_decipher(cipher_text: str, key: int) -> str:
# Met ton code ici
return "Il faudrait retourner un vrai truc ;)"

plain_text_string = do_cipher(cipher_text,-key)
return plain_text_string

def main():
PLAIN_TEXT = "Ave Caesar morituri te salutant"
KEY = 3
KEY = -10

print("************ Caesar's cypher ************\n\n")
print("Plain text :", PLAIN_TEXT)
print("key :", KEY)
print()

print("Let's cipher now!")
print("\nLet's cipher now!")
CIPHER_TEXT = do_cipher(PLAIN_TEXT, KEY)
print("Cipher text :", CIPHER_TEXT)
print()

print("Let's decipher (will it work?!)")
DECIPHER_TEXT = do_decipher(PLAIN_TEXT, KEY)
print("\nLet's decipher (will it work?!)")
DECIPHER_TEXT = do_decipher(CIPHER_TEXT, KEY)
print("Decipher text:", DECIPHER_TEXT)
print()

SUCCESS = PLAIN_TEXT.upper() == DECIPHER_TEXT
print("Did it worked?", "OK :)" if SUCCESS else "Nope :(")



if __name__ == "__main__":
main()