{"id":1829,"date":"2024-03-08T14:27:57","date_gmt":"2024-03-08T13:27:57","guid":{"rendered":"https:\/\/blog.univ-angers.fr\/mathsinfo\/?p=1829"},"modified":"2024-03-08T16:36:47","modified_gmt":"2024-03-08T15:36:47","slug":"python-cryptographie-partie-4-chiffre-de-pollux","status":"publish","type":"post","link":"https:\/\/blog.univ-angers.fr\/mathsinfo\/2024\/03\/08\/python-cryptographie-partie-4-chiffre-de-pollux\/","title":{"rendered":"Python &amp; Cryptographie partie 4 : Chiffre de Pollux"},"content":{"rendered":"\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Python &amp; Cryptographie partie 4 : Chiffre de Pollux\" width=\"584\" height=\"329\" src=\"https:\/\/www.youtube.com\/embed\/8L7tlyGE7TY?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>from random import choice\n\n# Initialisation des variables\ncodes = \".-+-...+-.-.+-..+.+..-.+--.+....+..+.---+-.-+.-..+--+-.+---+.--.+--.-+.-.+...+-+..-+...-+.--+-..-+-.--+--..\".split(\"+\")\nchiffres = &#091;chr(v) for v in range(48, 58)]\nalphabet = &#091;chr(v) for v in range(65,91)]\nalphanum = chiffres + alphabet\nmorse = dict(zip(alphabet, codes))\n\ndef dicoChiffrement():\n dico = {'.':&#091;], '-':&#091;], '+':&#091;]}\n cles = '.-+'\n possibilites = list(alphanum)  # Copie de alphanum\n for i in range(36):\n  valeur = choice(possibilites)\n  possibilites.remove(valeur)\n  dico&#091;cles&#091;i % 3]].append(valeur)\n return dico\n\ndef chiffrePollux(phrase:str):\n phrase = phrase.upper()\n dico = dicoChiffrement()     # Cr\u00e9ation du dictionnaire\n chiffre = ''\n for c in phrase:\n  if 'A' &lt;= c &lt;= 'Z':\n   codeMorse = morse&#091;c] + '+'\n   codageLettre = ''\n   for v in codeMorse:\n    codageLettre += choice(dico&#091;v])\n   chiffre += codageLettre\n return chiffre, dico    \n  \ndef dechiffrePollux(chiffre:str, dico):\n # Traduction chiffr\u00e9 vers Morse\n enMorse = chiffre.upper()\n for k, v in dico.items():\n  for c in v: enMorse = enMorse.replace(c, k)\n # Traduction Morse vers message clair\n clair = ''\n cleMorse = list(morse.keys())\n valMorse = list(morse.values())\n for m in enMorse.split('+'):\n   if m != '':\n    clair += cleMorse&#091;valMorse.index(m)]\n return clair \n\ndef enColonne(chiffre):\n for i in range(0, len(chiffre), 5):\n  if i % 4 == 0 and i &gt; 0: print()\n  print(chiffre&#091;i:i + 5], end='\\t')\n  \nmessage = 'rendezvouscesoiravingtheuresplacevictorhugo' \nchiffre, dico = chiffrePollux(message)\nprint('Texte chiffr\u00e9 :')\nenColonne(chiffre)\nprint('\\nDictionnaire utilis\u00e9 :')\nprint(dico)\nprint('D\u00e9chiffrement :')\nprint(dechiffrePollux(chiffre, dico))<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":4913,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1829","post","type-post","status-publish","format-standard","hentry","category-non-classe"],"_links":{"self":[{"href":"https:\/\/blog.univ-angers.fr\/mathsinfo\/wp-json\/wp\/v2\/posts\/1829","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.univ-angers.fr\/mathsinfo\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.univ-angers.fr\/mathsinfo\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.univ-angers.fr\/mathsinfo\/wp-json\/wp\/v2\/users\/4913"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.univ-angers.fr\/mathsinfo\/wp-json\/wp\/v2\/comments?post=1829"}],"version-history":[{"count":2,"href":"https:\/\/blog.univ-angers.fr\/mathsinfo\/wp-json\/wp\/v2\/posts\/1829\/revisions"}],"predecessor-version":[{"id":1831,"href":"https:\/\/blog.univ-angers.fr\/mathsinfo\/wp-json\/wp\/v2\/posts\/1829\/revisions\/1831"}],"wp:attachment":[{"href":"https:\/\/blog.univ-angers.fr\/mathsinfo\/wp-json\/wp\/v2\/media?parent=1829"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.univ-angers.fr\/mathsinfo\/wp-json\/wp\/v2\/categories?post=1829"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.univ-angers.fr\/mathsinfo\/wp-json\/wp\/v2\/tags?post=1829"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}