Mise en pratique

1. Décryptage

Énoncé

Nous avons cette phrase :

nkxtg uwt nc ugewtkvg kphqtocvkswg gv ng gvjkecn jcemkpi : vqwv kphqtocvkekgp ugpukdknkug cw eqpegrv fg nc ugewtkvg kphqtocvkswg ocku- pqxkeg qw fgdwvcpv fcpu ng fqockpg fg nc ugewtkvg fgu uauvgogu f’kphqtocvkqpu. Sqp cfcig guv crrtgpftg ngu cvvcswgu rqwt okgwz ug fghgpftg.

Créez un script qui la décrypte.

Correction


import string 
cyphertext = "nkxtg uwt nc ugewtkvg kphqtocvkswg gv ng gvjkecn 
jcemkpi : vqwv kphqtocvkekgp ugpukdknkug cw eqpegrv fg nc ugewtkvg 
kphqtocvkswg ocku pqxkeg qw fgdwvcpv fcpu ng fqockpg fg nc 
ugewtkvg fgu uauvgogu f'kphqtocvkqpu. Sqp cfcig guv crrtgpftg ngu 
cvvcswgu rqwt okgwz ug fghgpftg." 
 
fromlist = "abcdefghijklmnopqrstuvwxyz" 
tolist = "cdefghijklmnopqrstuvwxyzab" 
 
transtable = string.maketrans(fromlist, tolist) 
 
print string.translate(cyphertext, transtable)
 

2. OCR

Énoncé

Vous trouverez en téléchargement depuis la page Informations générales un fichier texte nommé ocr.txt.

Un mot y est caché et chacune de ses lettres est très « rare » dans le fichier. Recherchez les lettres qui n’apparaissent qu’une seule fois.

Correction


mess = open("ocr.txt").read() 
dict = {} 
for ch in mess: 
        dict[ch] = dict.get(ch, 0) + 1 
print "".join(ch for ch in mess if dict[ch] == 1)
 

Le résultat...

couv_EP2HAFO.png

Découvrez 

le livre :

Aussi inclus dans nos :

Précédent
Retrouver les éléments supprimés (dans la corbeille)
Suivant
Bibliographie