TDs 24 octobre

parent 134ed4d1
#!/usr/bin/python3
import socket,os
port_serveur = 7890
adresse_serveur = socket.gethostbyname('localhost')
ma_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
ma_socket.connect((adresse_serveur,port_serveur))
pid = os.fork()
if not pid:
# je suis l'enfant
while 1:
message = input('>').encode('utf8')
message = ma_socket.sendall(message)
else:
while 1:
message = ma_socket.recv(1024)
print (message.decode('utf8'))
#!/usr/bin/python3
import socket,os
port_serveur = 7890
ma_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
ma_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR,1)
ma_socket.bind(('',port_serveur))
ma_socket.listen(socket.SOMAXCONN)
(nouvelle_connexion,tsap_client) = ma_socket.accept()
pid = os.fork()
if not pid:
# je suis l'enfant
while 1:
message = input('>').encode('utf8')
nouvelle_connexion.sendall(message)
else :
while 1:
message = nouvelle_connexion.recv(1024)
print(message.decode('utf8'))
#!/usr/bin/python3
mon_texte_chiffre = "BULML TTLWH ZZHKB ULTHP UMHZA BLBZL ZVBSL CHUAI HSHUJ HUASL MLZAV ULASV BYSLA"
def creer_dico_substitution(decalage):
dico_substitution = {}
alphabet_chiffre = 'abcdefghijklmnopqrstuvwxyz' # on peut ajouter des lettres accentuées
alphabet_clair = alphabet_chiffre.upper()
alphabet_substitution = alphabet_chiffre[-decalage:]+alphabet_chiffre[:-decalage]
liste_association = list(zip(list(alphabet_clair),list(alphabet_substitution)))
# print(liste_association)
dico_substitution = dict(liste_association)
return dico_substitution
def calcul_occurences(texte):
dico_occurences = {}
for c in texte:
if c in dico_occurences:
dico_occurences[c] += 1
else:
dico_occurences[c] = 1
liste_occurences = list(dico_occurences.items())
liste_occurences = sorted(liste_occurences,key=lambda t:t[1])
liste_occurences.reverse()
return liste_occurences
def dechiffre(dico_substitution,texte_chiffre):
texte_clair = ""
for c in texte_chiffre:
if c in dico_substitution:
texte_clair += dico_substitution[c]
else:
texte_clair += c
return texte_clair
for i in range(1,26):
print(dechiffre(creer_dico_substitution(i),mon_texte_chiffre))
#!/usr/bin/python3
texte_clair = 'help me I am under attack'
texte_clair_sans_espace = ''.join([c for c in texte_clair if c != ' '])
nb_colonnes = int(input('Donnez le nombre de colonnes :'))
if (len(texte_clair_sans_espace)%nb_colonnes) != 0:
texte = texte_clair_sans_espace + (nb_colonnes - (len(texte_clair_sans_espace) % nb_colonnes))*'.'
else:
texte = texte_clair_sans_espace
print(texte)
tableau = []
for t in range(0,len(texte),nb_colonnes):
tableau.append(texte[t:t+nb_colonnes])
print(tableau)
texte_chiffre = ''
for i in range(0,nb_colonnes):
for j in range(0,len(tableau)):
texte_chiffre += tableau[j][i]
print(texte_chiffre)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment