issue80:python_-_partie_50
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédente | |||
issue80:python_-_partie_50 [2014/05/04 21:19] – fredphil91 | issue80:python_-_partie_50 [2014/05/07 10:55] (Version actuelle) – auntiee | ||
---|---|---|---|
Ligne 4: | Ligne 4: | ||
s = str.translate(table[, | s = str.translate(table[, | ||
- | **Ce mois-ci , je vais vous parler de deux fonctions un peu moins connues : maketrans et translate. Nous allons commencer par la méthode translate. La méthode translate retourne une copie d'une chaîne, avec tous les caractères de la table translate remplacés (traduits) ou bien avec des caractères supprimés de la chaîne, s'ils sont contenus dans ' | + | **Ce mois-ci , je vais parler de deux fonctions un peu moins connues : maketrans et translate. Nous allons commencer par la méthode translate. La méthode translate retourne une copie d'une chaîne, avec tous les caractères de la table translate remplacés (traduits) ou bien avec des caractères supprimés de la chaîne, s'ils sont contenus dans ' |
s = str.translate(table[, | s = str.translate(table[, | ||
Ligne 19: | Ligne 19: | ||
“Th tm hs cm” | “Th tm hs cm” | ||
- | **Avant de passer à la partie ' | + | **Avant de passer à la partie ' |
astr = "The time has come" | astr = "The time has come" | ||
Ligne 59: | Ligne 59: | ||
So now it should be making sense. | So now it should be making sense. | ||
- | **Si vous regardez encore de plus près, vous verrez qu'il y a effectivement 256 entrées, en commençant par « \x00 » et en se terminant par « \xff ». Ainsi, le tableau contient l' | + | **Si vous regardez encore de plus près, vous verrez qu'il y a effectivement 256 entrées, en commençant par « \x00 » et en se terminant par « \xff ». Ainsi, le tableau contient l' |
Maintenant, vous devez commencer à comprendre.** | Maintenant, vous devez commencer à comprendre.** | ||
Ligne 71: | Ligne 71: | ||
While this seems very simple by today’s standards, when I was a school kid, we used this all the time to send messages to each other. We used a different index into the string to start the encryption string, the logic behind it was the same. | While this seems very simple by today’s standards, when I was a school kid, we used this all the time to send messages to each other. We used a different index into the string to start the encryption string, the logic behind it was the same. | ||
- | **Alors | + | **Alors, à quoi tout cela peut-il servir ? Faites un retour en arrière et pensez à la période où vous avez étudié le personnage de Jules César à l' |
cela se transformait en : DEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABC | cela se transformait en : DEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABC | ||
Ligne 103: | Ligne 103: | ||
Just like back in school. But let’s flesh it out just a bit to make it a bit more usable. The code is almost the same with a few exceptions. First, we have added a space to the end of the intab string and in between the “Z” and the “A” in the outtab string. This helps keep the actual words from being too obvious in the encrypted string. The next change is where we ask if the user wants to encode or decode the string. Finally we added an if statement to control what we print (shown bottom right). | Just like back in school. But let’s flesh it out just a bit to make it a bit more usable. The code is almost the same with a few exceptions. First, we have added a space to the end of the intab string and in between the “Z” and the “A” in the outtab string. This helps keep the actual words from being too obvious in the encrypted string. The next change is where we ask if the user wants to encode or decode the string. Finally we added an if statement to control what we print (shown bottom right). | ||
- | **Voilà, c'est comme si nous étions retournés | + | **Voilà, c'est comme à l' |
** | ** | ||
issue80/python_-_partie_50.1399231186.txt.gz · Dernière modification : 2014/05/04 21:19 de fredphil91