Last active
June 7, 2021 16:17
-
-
Save mibi88/a3cbf412a24895dd63fa70cfd9ecb60c to your computer and use it in GitHub Desktop.
Untitled0.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "Untitled0.ipynb", | |
"provenance": [], | |
"collapsed_sections": [], | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
}, | |
"language_info": { | |
"name": "python" | |
}, | |
"widgets": { | |
"application/vnd.jupyter.widget-state+json": { | |
"a8289e758fdc4ba69265aa50b5e265cc": { | |
"model_module": "@jupyter-widgets/controls", | |
"model_name": "TextareaModel", | |
"state": { | |
"_view_name": "TextareaView", | |
"style": "IPY_MODEL_8f7419fc79be463aae1003ff5f624dc4", | |
"rows": null, | |
"_dom_classes": [], | |
"description": "À encoder/décoder", | |
"_model_name": "TextareaModel", | |
"placeholder": "Entrez le texte à encoder/décoder", | |
"_view_module": "@jupyter-widgets/controls", | |
"_model_module_version": "1.5.0", | |
"value": "Vgzvg", | |
"_view_count": null, | |
"disabled": false, | |
"_view_module_version": "1.5.0", | |
"continuous_update": true, | |
"description_tooltip": null, | |
"_model_module": "@jupyter-widgets/controls", | |
"layout": "IPY_MODEL_8ff304606caa4249830cb5c44591e16c" | |
} | |
}, | |
"8f7419fc79be463aae1003ff5f624dc4": { | |
"model_module": "@jupyter-widgets/controls", | |
"model_name": "DescriptionStyleModel", | |
"state": { | |
"_view_name": "StyleView", | |
"_model_name": "DescriptionStyleModel", | |
"description_width": "", | |
"_view_module": "@jupyter-widgets/base", | |
"_model_module_version": "1.5.0", | |
"_view_count": null, | |
"_view_module_version": "1.2.0", | |
"_model_module": "@jupyter-widgets/controls" | |
} | |
}, | |
"8ff304606caa4249830cb5c44591e16c": { | |
"model_module": "@jupyter-widgets/base", | |
"model_name": "LayoutModel", | |
"state": { | |
"_view_name": "LayoutView", | |
"grid_template_rows": null, | |
"right": null, | |
"justify_content": null, | |
"_view_module": "@jupyter-widgets/base", | |
"overflow": null, | |
"_model_module_version": "1.2.0", | |
"_view_count": null, | |
"flex_flow": null, | |
"width": null, | |
"min_width": null, | |
"border": null, | |
"align_items": null, | |
"bottom": null, | |
"_model_module": "@jupyter-widgets/base", | |
"top": null, | |
"grid_column": null, | |
"overflow_y": null, | |
"overflow_x": null, | |
"grid_auto_flow": null, | |
"grid_area": null, | |
"grid_template_columns": null, | |
"flex": null, | |
"_model_name": "LayoutModel", | |
"justify_items": null, | |
"grid_row": null, | |
"max_height": null, | |
"align_content": null, | |
"visibility": null, | |
"align_self": null, | |
"height": null, | |
"min_height": null, | |
"padding": null, | |
"grid_auto_rows": null, | |
"grid_gap": null, | |
"max_width": null, | |
"order": null, | |
"_view_module_version": "1.2.0", | |
"grid_template_areas": null, | |
"object_position": null, | |
"object_fit": null, | |
"grid_auto_columns": null, | |
"margin": null, | |
"display": null, | |
"left": null | |
} | |
}, | |
"f7fad7c8e1c743b79fd2332b86e05394": { | |
"model_module": "@jupyter-widgets/controls", | |
"model_name": "TextareaModel", | |
"state": { | |
"_view_name": "TextareaView", | |
"style": "IPY_MODEL_9807067fa933448c9642f8747d708ec9", | |
"rows": null, | |
"_dom_classes": [], | |
"description": "Encodé/décodé", | |
"_model_name": "TextareaModel", | |
"placeholder": "Texte encodé/décodé", | |
"_view_module": "@jupyter-widgets/controls", | |
"_model_module_version": "1.5.0", | |
"value": "Texte", | |
"_view_count": null, | |
"disabled": true, | |
"_view_module_version": "1.5.0", | |
"continuous_update": true, | |
"description_tooltip": null, | |
"_model_module": "@jupyter-widgets/controls", | |
"layout": "IPY_MODEL_17609c5edc304e4396322780086ef917" | |
} | |
}, | |
"9807067fa933448c9642f8747d708ec9": { | |
"model_module": "@jupyter-widgets/controls", | |
"model_name": "DescriptionStyleModel", | |
"state": { | |
"_view_name": "StyleView", | |
"_model_name": "DescriptionStyleModel", | |
"description_width": "", | |
"_view_module": "@jupyter-widgets/base", | |
"_model_module_version": "1.5.0", | |
"_view_count": null, | |
"_view_module_version": "1.2.0", | |
"_model_module": "@jupyter-widgets/controls" | |
} | |
}, | |
"17609c5edc304e4396322780086ef917": { | |
"model_module": "@jupyter-widgets/base", | |
"model_name": "LayoutModel", | |
"state": { | |
"_view_name": "LayoutView", | |
"grid_template_rows": null, | |
"right": null, | |
"justify_content": null, | |
"_view_module": "@jupyter-widgets/base", | |
"overflow": null, | |
"_model_module_version": "1.2.0", | |
"_view_count": null, | |
"flex_flow": null, | |
"width": null, | |
"min_width": null, | |
"border": null, | |
"align_items": null, | |
"bottom": null, | |
"_model_module": "@jupyter-widgets/base", | |
"top": null, | |
"grid_column": null, | |
"overflow_y": null, | |
"overflow_x": null, | |
"grid_auto_flow": null, | |
"grid_area": null, | |
"grid_template_columns": null, | |
"flex": null, | |
"_model_name": "LayoutModel", | |
"justify_items": null, | |
"grid_row": null, | |
"max_height": null, | |
"align_content": null, | |
"visibility": null, | |
"align_self": null, | |
"height": null, | |
"min_height": null, | |
"padding": null, | |
"grid_auto_rows": null, | |
"grid_gap": null, | |
"max_width": null, | |
"order": null, | |
"_view_module_version": "1.2.0", | |
"grid_template_areas": null, | |
"object_position": null, | |
"object_fit": null, | |
"grid_auto_columns": null, | |
"margin": null, | |
"display": null, | |
"left": null | |
} | |
}, | |
"a43371efc6184928a010e348b8fd92f7": { | |
"model_module": "@jupyter-widgets/controls", | |
"model_name": "TextModel", | |
"state": { | |
"_view_name": "TextView", | |
"style": "IPY_MODEL_1648aa3efd4342a08480d1e3007ba2b8", | |
"_dom_classes": [], | |
"description": "", | |
"_model_name": "TextModel", | |
"placeholder": "Clé", | |
"_view_module": "@jupyter-widgets/controls", | |
"_model_module_version": "1.5.0", | |
"value": "CLE", | |
"_view_count": null, | |
"disabled": false, | |
"_view_module_version": "1.5.0", | |
"continuous_update": true, | |
"description_tooltip": null, | |
"_model_module": "@jupyter-widgets/controls", | |
"layout": "IPY_MODEL_49241bc654914c67b11e37c8cbf65950" | |
} | |
}, | |
"1648aa3efd4342a08480d1e3007ba2b8": { | |
"model_module": "@jupyter-widgets/controls", | |
"model_name": "DescriptionStyleModel", | |
"state": { | |
"_view_name": "StyleView", | |
"_model_name": "DescriptionStyleModel", | |
"description_width": "", | |
"_view_module": "@jupyter-widgets/base", | |
"_model_module_version": "1.5.0", | |
"_view_count": null, | |
"_view_module_version": "1.2.0", | |
"_model_module": "@jupyter-widgets/controls" | |
} | |
}, | |
"49241bc654914c67b11e37c8cbf65950": { | |
"model_module": "@jupyter-widgets/base", | |
"model_name": "LayoutModel", | |
"state": { | |
"_view_name": "LayoutView", | |
"grid_template_rows": null, | |
"right": null, | |
"justify_content": null, | |
"_view_module": "@jupyter-widgets/base", | |
"overflow": null, | |
"_model_module_version": "1.2.0", | |
"_view_count": null, | |
"flex_flow": null, | |
"width": null, | |
"min_width": null, | |
"border": null, | |
"align_items": null, | |
"bottom": null, | |
"_model_module": "@jupyter-widgets/base", | |
"top": null, | |
"grid_column": null, | |
"overflow_y": null, | |
"overflow_x": null, | |
"grid_auto_flow": null, | |
"grid_area": null, | |
"grid_template_columns": null, | |
"flex": null, | |
"_model_name": "LayoutModel", | |
"justify_items": null, | |
"grid_row": null, | |
"max_height": null, | |
"align_content": null, | |
"visibility": null, | |
"align_self": null, | |
"height": null, | |
"min_height": null, | |
"padding": null, | |
"grid_auto_rows": null, | |
"grid_gap": null, | |
"max_width": null, | |
"order": null, | |
"_view_module_version": "1.2.0", | |
"grid_template_areas": null, | |
"object_position": null, | |
"object_fit": null, | |
"grid_auto_columns": null, | |
"margin": null, | |
"display": null, | |
"left": null | |
} | |
}, | |
"e6dbb97b1e6d4bd0ad322b065c513e35": { | |
"model_module": "@jupyter-widgets/controls", | |
"model_name": "TextModel", | |
"state": { | |
"_view_name": "TextView", | |
"style": "IPY_MODEL_96abe8be4bb8410e8798a889ac51950a", | |
"_dom_classes": [], | |
"description": "", | |
"_model_name": "TextModel", | |
"placeholder": "Table de charactères", | |
"_view_module": "@jupyter-widgets/controls", | |
"_model_module_version": "1.5.0", | |
"value": "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", | |
"_view_count": null, | |
"disabled": false, | |
"_view_module_version": "1.5.0", | |
"continuous_update": true, | |
"description_tooltip": null, | |
"_model_module": "@jupyter-widgets/controls", | |
"layout": "IPY_MODEL_2912eba918d644f4b41988d9a4a5bf1c" | |
} | |
}, | |
"96abe8be4bb8410e8798a889ac51950a": { | |
"model_module": "@jupyter-widgets/controls", | |
"model_name": "DescriptionStyleModel", | |
"state": { | |
"_view_name": "StyleView", | |
"_model_name": "DescriptionStyleModel", | |
"description_width": "", | |
"_view_module": "@jupyter-widgets/base", | |
"_model_module_version": "1.5.0", | |
"_view_count": null, | |
"_view_module_version": "1.2.0", | |
"_model_module": "@jupyter-widgets/controls" | |
} | |
}, | |
"2912eba918d644f4b41988d9a4a5bf1c": { | |
"model_module": "@jupyter-widgets/base", | |
"model_name": "LayoutModel", | |
"state": { | |
"_view_name": "LayoutView", | |
"grid_template_rows": null, | |
"right": null, | |
"justify_content": null, | |
"_view_module": "@jupyter-widgets/base", | |
"overflow": null, | |
"_model_module_version": "1.2.0", | |
"_view_count": null, | |
"flex_flow": null, | |
"width": null, | |
"min_width": null, | |
"border": null, | |
"align_items": null, | |
"bottom": null, | |
"_model_module": "@jupyter-widgets/base", | |
"top": null, | |
"grid_column": null, | |
"overflow_y": null, | |
"overflow_x": null, | |
"grid_auto_flow": null, | |
"grid_area": null, | |
"grid_template_columns": null, | |
"flex": null, | |
"_model_name": "LayoutModel", | |
"justify_items": null, | |
"grid_row": null, | |
"max_height": null, | |
"align_content": null, | |
"visibility": null, | |
"align_self": null, | |
"height": null, | |
"min_height": null, | |
"padding": null, | |
"grid_auto_rows": null, | |
"grid_gap": null, | |
"max_width": null, | |
"order": null, | |
"_view_module_version": "1.2.0", | |
"grid_template_areas": null, | |
"object_position": null, | |
"object_fit": null, | |
"grid_auto_columns": null, | |
"margin": null, | |
"display": null, | |
"left": null | |
} | |
}, | |
"271e17beee464a0392c24fc1c3605ca4": { | |
"model_module": "@jupyter-widgets/controls", | |
"model_name": "ButtonModel", | |
"state": { | |
"_view_name": "ButtonView", | |
"style": "IPY_MODEL_11bbe41c4d8f4555b67e93d3f5299d46", | |
"_dom_classes": [], | |
"description": "Encoder", | |
"_model_name": "ButtonModel", | |
"button_style": "success", | |
"_view_module": "@jupyter-widgets/controls", | |
"_model_module_version": "1.5.0", | |
"tooltip": "Encoder", | |
"_view_count": null, | |
"disabled": false, | |
"_view_module_version": "1.5.0", | |
"layout": "IPY_MODEL_6c7a9ed62cc7462383aa59795ba1320b", | |
"_model_module": "@jupyter-widgets/controls", | |
"icon": "key" | |
} | |
}, | |
"11bbe41c4d8f4555b67e93d3f5299d46": { | |
"model_module": "@jupyter-widgets/controls", | |
"model_name": "ButtonStyleModel", | |
"state": { | |
"_view_name": "StyleView", | |
"_model_name": "ButtonStyleModel", | |
"_view_module": "@jupyter-widgets/base", | |
"_model_module_version": "1.5.0", | |
"_view_count": null, | |
"button_color": null, | |
"font_weight": "", | |
"_view_module_version": "1.2.0", | |
"_model_module": "@jupyter-widgets/controls" | |
} | |
}, | |
"6c7a9ed62cc7462383aa59795ba1320b": { | |
"model_module": "@jupyter-widgets/base", | |
"model_name": "LayoutModel", | |
"state": { | |
"_view_name": "LayoutView", | |
"grid_template_rows": null, | |
"right": null, | |
"justify_content": null, | |
"_view_module": "@jupyter-widgets/base", | |
"overflow": null, | |
"_model_module_version": "1.2.0", | |
"_view_count": null, | |
"flex_flow": null, | |
"width": null, | |
"min_width": null, | |
"border": null, | |
"align_items": null, | |
"bottom": null, | |
"_model_module": "@jupyter-widgets/base", | |
"top": null, | |
"grid_column": null, | |
"overflow_y": null, | |
"overflow_x": null, | |
"grid_auto_flow": null, | |
"grid_area": null, | |
"grid_template_columns": null, | |
"flex": null, | |
"_model_name": "LayoutModel", | |
"justify_items": null, | |
"grid_row": null, | |
"max_height": null, | |
"align_content": null, | |
"visibility": null, | |
"align_self": null, | |
"height": null, | |
"min_height": null, | |
"padding": null, | |
"grid_auto_rows": null, | |
"grid_gap": null, | |
"max_width": null, | |
"order": null, | |
"_view_module_version": "1.2.0", | |
"grid_template_areas": null, | |
"object_position": null, | |
"object_fit": null, | |
"grid_auto_columns": null, | |
"margin": null, | |
"display": null, | |
"left": null | |
} | |
}, | |
"5d3c8d0360b34f7380369a347e34b63c": { | |
"model_module": "@jupyter-widgets/controls", | |
"model_name": "ButtonModel", | |
"state": { | |
"_view_name": "ButtonView", | |
"style": "IPY_MODEL_1c8a2760eed947aba65fd8d9ffef5555", | |
"_dom_classes": [], | |
"description": "Décoder", | |
"_model_name": "ButtonModel", | |
"button_style": "success", | |
"_view_module": "@jupyter-widgets/controls", | |
"_model_module_version": "1.5.0", | |
"tooltip": "Décoder", | |
"_view_count": null, | |
"disabled": false, | |
"_view_module_version": "1.5.0", | |
"layout": "IPY_MODEL_a5dd84b9d39040339742db1b724a11ca", | |
"_model_module": "@jupyter-widgets/controls", | |
"icon": "key" | |
} | |
}, | |
"1c8a2760eed947aba65fd8d9ffef5555": { | |
"model_module": "@jupyter-widgets/controls", | |
"model_name": "ButtonStyleModel", | |
"state": { | |
"_view_name": "StyleView", | |
"_model_name": "ButtonStyleModel", | |
"_view_module": "@jupyter-widgets/base", | |
"_model_module_version": "1.5.0", | |
"_view_count": null, | |
"button_color": null, | |
"font_weight": "", | |
"_view_module_version": "1.2.0", | |
"_model_module": "@jupyter-widgets/controls" | |
} | |
}, | |
"a5dd84b9d39040339742db1b724a11ca": { | |
"model_module": "@jupyter-widgets/base", | |
"model_name": "LayoutModel", | |
"state": { | |
"_view_name": "LayoutView", | |
"grid_template_rows": null, | |
"right": null, | |
"justify_content": null, | |
"_view_module": "@jupyter-widgets/base", | |
"overflow": null, | |
"_model_module_version": "1.2.0", | |
"_view_count": null, | |
"flex_flow": null, | |
"width": null, | |
"min_width": null, | |
"border": null, | |
"align_items": null, | |
"bottom": null, | |
"_model_module": "@jupyter-widgets/base", | |
"top": null, | |
"grid_column": null, | |
"overflow_y": null, | |
"overflow_x": null, | |
"grid_auto_flow": null, | |
"grid_area": null, | |
"grid_template_columns": null, | |
"flex": null, | |
"_model_name": "LayoutModel", | |
"justify_items": null, | |
"grid_row": null, | |
"max_height": null, | |
"align_content": null, | |
"visibility": null, | |
"align_self": null, | |
"height": null, | |
"min_height": null, | |
"padding": null, | |
"grid_auto_rows": null, | |
"grid_gap": null, | |
"max_width": null, | |
"order": null, | |
"_view_module_version": "1.2.0", | |
"grid_template_areas": null, | |
"object_position": null, | |
"object_fit": null, | |
"grid_auto_columns": null, | |
"margin": null, | |
"display": null, | |
"left": null | |
} | |
} | |
} | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/mibi88/a3cbf412a24895dd63fa70cfd9ecb60c/untitled0.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 1000, | |
"referenced_widgets": [ | |
"a8289e758fdc4ba69265aa50b5e265cc", | |
"8f7419fc79be463aae1003ff5f624dc4", | |
"8ff304606caa4249830cb5c44591e16c", | |
"f7fad7c8e1c743b79fd2332b86e05394", | |
"9807067fa933448c9642f8747d708ec9", | |
"17609c5edc304e4396322780086ef917", | |
"a43371efc6184928a010e348b8fd92f7", | |
"1648aa3efd4342a08480d1e3007ba2b8", | |
"49241bc654914c67b11e37c8cbf65950", | |
"e6dbb97b1e6d4bd0ad322b065c513e35", | |
"96abe8be4bb8410e8798a889ac51950a", | |
"2912eba918d644f4b41988d9a4a5bf1c", | |
"271e17beee464a0392c24fc1c3605ca4", | |
"11bbe41c4d8f4555b67e93d3f5299d46", | |
"6c7a9ed62cc7462383aa59795ba1320b", | |
"5d3c8d0360b34f7380369a347e34b63c", | |
"1c8a2760eed947aba65fd8d9ffef5555", | |
"a5dd84b9d39040339742db1b724a11ca" | |
] | |
}, | |
"id": "556clCM7WhmF", | |
"outputId": "4f355092-70c1-4bfb-e1f6-b7d8b462c4d6" | |
}, | |
"source": [ | |
"import ipywidgets as widgets\n", | |
"from IPython.display import display\n", | |
"\n", | |
"text1 = widgets.Textarea(\n", | |
" value='Texte à encoder/décoder',\n", | |
" placeholder='Entrez le texte à encoder/décoder',\n", | |
" description='À encoder/décoder',\n", | |
" disabled=False\n", | |
")\n", | |
"text2 = widgets.Textarea(\n", | |
" value='',\n", | |
" placeholder='Texte encodé/décodé',\n", | |
" description='Encodé/décodé',\n", | |
" disabled=True\n", | |
")\n", | |
"key_e = widgets.Text(\n", | |
" value='',\n", | |
" placeholder='Clé',\n", | |
" description='',\n", | |
" disabled=False\n", | |
")\n", | |
"charmap_e = widgets.Text(\n", | |
" value='ABCDEFGHIJKLMNOPQRSTUVWXYZ',\n", | |
" placeholder='Table de charactères',\n", | |
" description='',\n", | |
" disabled=False\n", | |
")\n", | |
"def encode(string, key, chars):\n", | |
" charlist = []\n", | |
" for letter in chars:\n", | |
" print(letter)\n", | |
" charlist.append(letter)\n", | |
" print(charlist)\n", | |
" lenght = len(string)\n", | |
" keystr = buildkey(key, lenght, string, chars)\n", | |
" genstring = \"\"\n", | |
" i = 0\n", | |
" for letter in string:\n", | |
" keyletter = keystr[i:i + 1]\n", | |
" genstring += getletter1(letter, keyletter, charlist, chars)\n", | |
" return genstring\n", | |
"def buildkey(key, lenght, orgstring, chars):\n", | |
" i = 0\n", | |
" i_a = 0\n", | |
" i_a_max = len(key)\n", | |
" string = \"\"\n", | |
" while i != lenght:\n", | |
" #print(i)\n", | |
" if i_a == i_a_max:\n", | |
" i_a = 0\n", | |
" letter = orgstring[i:i + 1]\n", | |
" if not letter in chars:\n", | |
" string += letter\n", | |
" else:\n", | |
" string += key[i_a:i_a + 1]\n", | |
" i_a += 1\n", | |
" i += 1\n", | |
" print(string)\n", | |
" return string\n", | |
"def getletter1(stringletter, keyletter, charlist, chars):\n", | |
" #if stringletter in chars:\n", | |
" try:\n", | |
" startpos = charlist.index(stringletter)\n", | |
" i = 0\n", | |
" i_a = startpos\n", | |
" lenght = len(charlist)\n", | |
" result = \"\"\n", | |
" maxi = lenght - startpos\n", | |
" while i != lenght:\n", | |
" if i == maxi:\n", | |
" i_a = 0\n", | |
" result += charlist[i_a]\n", | |
" i += 1\n", | |
" i_a += 1\n", | |
" print(result)\n", | |
" resultlist = []\n", | |
" for letter in result:\n", | |
" resultlist.append(letter)\n", | |
" letteritem = charlist.index(keyletter)\n", | |
" char = resultlist[letteritem]\n", | |
" print(char)\n", | |
" except ValueError:\n", | |
" char = stringletter\n", | |
" return char\n", | |
"#print(encode(string = \"MA STRING QUI ME PASSIONNE !!! VIVE VIGENERE !!!\", key = \"GRANDMISTERE\", chars = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"))\n", | |
"def decode(string, key, chars):\n", | |
" charlist = []\n", | |
" for letter in chars:\n", | |
" print(letter)\n", | |
" charlist.append(letter)\n", | |
" print(charlist)\n", | |
" lenght = len(string)\n", | |
" keystr = buildkey(key, lenght, string, chars)\n", | |
" genstring = \"\"\n", | |
" i = 0\n", | |
" for letter in string:\n", | |
" keyletter = keystr[i:i + 1]\n", | |
" genstring += getletter2(letter, keyletter, charlist, chars)\n", | |
" return genstring\n", | |
"def getletter2(stringletter, keyletter, charlist, chars):\n", | |
" #if stringletter in chars:\n", | |
" try:\n", | |
" startpos = charlist.index(keyletter)\n", | |
" i = 0\n", | |
" i_a = startpos\n", | |
" lenght = len(charlist)\n", | |
" result = \"\"\n", | |
" maxi = lenght - startpos\n", | |
" while i != lenght:\n", | |
" if i == maxi:\n", | |
" i_a = 0\n", | |
" result += charlist[i_a]\n", | |
" i += 1\n", | |
" i_a += 1\n", | |
" print(result)\n", | |
" resultlist = []\n", | |
" for letter in result:\n", | |
" resultlist.append(letter)\n", | |
" letteritem = resultlist.index(stringletter)\n", | |
" char = charlist[letteritem]\n", | |
" print(char)\n", | |
" except ValueError:\n", | |
" char = stringletter\n", | |
" return char\n", | |
"def enc_f(b):\n", | |
" string = text1.value\n", | |
" key = key_e.value\n", | |
" chars = charmap_e.value\n", | |
" charlist = []\n", | |
" for letter in chars:\n", | |
" charlist.append(letter)\n", | |
" badkey = False\n", | |
" for letter in key:\n", | |
" if letter in charlist:\n", | |
" pass\n", | |
" else:\n", | |
" badkey = True\n", | |
" if badkey == True:\n", | |
" text2.value = \"Error : Bad key.\"\n", | |
" else:\n", | |
" text = encode(string, key, chars)\n", | |
" text2.value = text\n", | |
"def dec_f(b):\n", | |
" string = text1.value\n", | |
" key = key_e.value\n", | |
" chars = charmap_e.value\n", | |
" charlist = []\n", | |
" for letter in chars:\n", | |
" charlist.append(letter)\n", | |
" badkey = False\n", | |
" for letter in key:\n", | |
" if letter in charlist:\n", | |
" pass\n", | |
" else:\n", | |
" badkey = True\n", | |
" if badkey == True:\n", | |
" text2.value = \"Bad key\"\n", | |
" else:\n", | |
" text = decode(string, key, chars)\n", | |
" text2.value = text\n", | |
"encb = widgets.Button(\n", | |
" description='Encoder',\n", | |
" disabled=False,\n", | |
" button_style='success',\n", | |
" tooltip='Encoder',\n", | |
" icon='key'\n", | |
")\n", | |
"decb = widgets.Button(\n", | |
" description='Décoder',\n", | |
" disabled=False,\n", | |
" button_style='success',\n", | |
" tooltip='Décoder',\n", | |
" icon='key'\n", | |
")\n", | |
"display(text1)\n", | |
"display(text2)\n", | |
"display(key_e)\n", | |
"display(charmap_e)\n", | |
"display(encb)\n", | |
"display(decb)\n", | |
"encb.on_click(enc_f)\n", | |
"decb.on_click(dec_f)" | |
], | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "a8289e758fdc4ba69265aa50b5e265cc", | |
"version_minor": 0, | |
"version_major": 2 | |
}, | |
"text/plain": [ | |
"Textarea(value='Texte à encoder/décoder', description='À encoder/décoder', placeholder='Entrez le texte à enco…" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "f7fad7c8e1c743b79fd2332b86e05394", | |
"version_minor": 0, | |
"version_major": 2 | |
}, | |
"text/plain": [ | |
"Textarea(value='', description='Encodé/décodé', disabled=True, placeholder='Texte encodé/décodé')" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "a43371efc6184928a010e348b8fd92f7", | |
"version_minor": 0, | |
"version_major": 2 | |
}, | |
"text/plain": [ | |
"Text(value='', placeholder='Clé')" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "e6dbb97b1e6d4bd0ad322b065c513e35", | |
"version_minor": 0, | |
"version_major": 2 | |
}, | |
"text/plain": [ | |
"Text(value='ABCDEFGHIJKLMNOPQRSTUVWXYZ', placeholder='Table de charactères')" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "271e17beee464a0392c24fc1c3605ca4", | |
"version_minor": 0, | |
"version_major": 2 | |
}, | |
"text/plain": [ | |
"Button(button_style='success', description='Encoder', icon='key', style=ButtonStyle(), tooltip='Encoder')" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "5d3c8d0360b34f7380369a347e34b63c", | |
"version_minor": 0, | |
"version_major": 2 | |
}, | |
"text/plain": [ | |
"Button(button_style='success', description='Décoder', icon='key', style=ButtonStyle(), tooltip='Décoder')" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
}, | |
{ | |
"output_type": "stream", | |
"text": [ | |
"A\n", | |
"B\n", | |
"C\n", | |
"D\n", | |
"E\n", | |
"F\n", | |
"G\n", | |
"H\n", | |
"I\n", | |
"J\n", | |
"K\n", | |
"L\n", | |
"M\n", | |
"N\n", | |
"O\n", | |
"P\n", | |
"Q\n", | |
"R\n", | |
"S\n", | |
"T\n", | |
"U\n", | |
"V\n", | |
"W\n", | |
"X\n", | |
"Y\n", | |
"Z\n", | |
"a\n", | |
"b\n", | |
"c\n", | |
"d\n", | |
"e\n", | |
"f\n", | |
"g\n", | |
"h\n", | |
"i\n", | |
"j\n", | |
"k\n", | |
"l\n", | |
"m\n", | |
"n\n", | |
"o\n", | |
"p\n", | |
"q\n", | |
"r\n", | |
"s\n", | |
"t\n", | |
"u\n", | |
"v\n", | |
"w\n", | |
"x\n", | |
"y\n", | |
"z\n", | |
"['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']\n", | |
"\n", | |
"TUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRS\n", | |
"efghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcd\n", | |
"xyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw\n", | |
"tuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrs\n", | |
"efghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcd\n", | |
"A\n", | |
"B\n", | |
"C\n", | |
"D\n", | |
"E\n", | |
"F\n", | |
"G\n", | |
"H\n", | |
"I\n", | |
"J\n", | |
"K\n", | |
"L\n", | |
"M\n", | |
"N\n", | |
"O\n", | |
"P\n", | |
"Q\n", | |
"R\n", | |
"S\n", | |
"T\n", | |
"U\n", | |
"V\n", | |
"W\n", | |
"X\n", | |
"Y\n", | |
"Z\n", | |
"a\n", | |
"b\n", | |
"c\n", | |
"d\n", | |
"e\n", | |
"f\n", | |
"g\n", | |
"h\n", | |
"i\n", | |
"j\n", | |
"k\n", | |
"l\n", | |
"m\n", | |
"n\n", | |
"o\n", | |
"p\n", | |
"q\n", | |
"r\n", | |
"s\n", | |
"t\n", | |
"u\n", | |
"v\n", | |
"w\n", | |
"x\n", | |
"y\n", | |
"z\n", | |
"['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']\n", | |
"CLECL\n", | |
"TUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRS\n", | |
"V\n", | |
"efghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcd\n", | |
"g\n", | |
"xyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw\n", | |
"z\n", | |
"tuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrs\n", | |
"v\n", | |
"efghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcd\n", | |
"g\n", | |
"A\n", | |
"B\n", | |
"C\n", | |
"D\n", | |
"E\n", | |
"F\n", | |
"G\n", | |
"H\n", | |
"I\n", | |
"J\n", | |
"K\n", | |
"L\n", | |
"M\n", | |
"N\n", | |
"O\n", | |
"P\n", | |
"Q\n", | |
"R\n", | |
"S\n", | |
"T\n", | |
"U\n", | |
"V\n", | |
"W\n", | |
"X\n", | |
"Y\n", | |
"Z\n", | |
"a\n", | |
"b\n", | |
"c\n", | |
"d\n", | |
"e\n", | |
"f\n", | |
"g\n", | |
"h\n", | |
"i\n", | |
"j\n", | |
"k\n", | |
"l\n", | |
"m\n", | |
"n\n", | |
"o\n", | |
"p\n", | |
"q\n", | |
"r\n", | |
"s\n", | |
"t\n", | |
"u\n", | |
"v\n", | |
"w\n", | |
"x\n", | |
"y\n", | |
"z\n", | |
"['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']\n", | |
"CLECL\n", | |
"CDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzAB\n", | |
"T\n", | |
"CDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzAB\n", | |
"e\n", | |
"CDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzAB\n", | |
"x\n", | |
"CDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzAB\n", | |
"t\n", | |
"CDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzAB\n", | |
"e\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "yrw51SKtGOym" | |
}, | |
"source": [ | |
"import ipywidgets as widgets\n", | |
"from IPython.display import display\n", | |
"\n", | |
"text1 = widgets.Textarea(\n", | |
" value='Texte à encoder/décoder',\n", | |
" placeholder='Entrez le texte à encoder/décoder',\n", | |
" description='À encoder/décoder',\n", | |
" disabled=False\n", | |
")\n", | |
"text2 = widgets.Textarea(\n", | |
" value='',\n", | |
" placeholder='Texte encodé/décodé',\n", | |
" description='Encodé/décodé',\n", | |
" disabled=True\n", | |
")\n", | |
"key_e = widgets.Text(\n", | |
" value='',\n", | |
" placeholder='Clé',\n", | |
" description='',\n", | |
" disabled=False\n", | |
")\n", | |
"charmap_e = widgets.Text(\n", | |
" value='ABCDEFGHIJKLMNOPQRSTUVWXYZ',\n", | |
" placeholder='Table de charactères',\n", | |
" description='',\n", | |
" disabled=False\n", | |
")\n", | |
"def encode(string, key, chars):\n", | |
" charlist = []\n", | |
" for letter in chars:\n", | |
" print(letter)\n", | |
" charlist.append(letter)\n", | |
" print(charlist)\n", | |
" lenght = len(string)\n", | |
" keystr = buildkey(key, lenght, string, chars)\n", | |
" genstring = \"\"\n", | |
" i = 0\n", | |
" for letter in string:\n", | |
" keyletter = keystr[i:i + 1]\n", | |
" genstring += getletter1(letter, keyletter, charlist, chars)\n", | |
" return genstring\n", | |
"def buildkey(key, lenght, orgstring, chars):\n", | |
" i = 0\n", | |
" i_a = 0\n", | |
" i_a_max = len(key)\n", | |
" string = \"\"\n", | |
" while i != lenght:\n", | |
" #print(i)\n", | |
" if i_a == i_a_max:\n", | |
" i_a = 0\n", | |
" letter = orgstring[i:i + 1]\n", | |
" if not letter in chars:\n", | |
" string += letter\n", | |
" else:\n", | |
" string += key[i_a:i_a + 1]\n", | |
" i_a += 1\n", | |
" i += 1\n", | |
" print(string)\n", | |
" return string\n", | |
"def getletter1(stringletter, keyletter, charlist, chars):\n", | |
" #if stringletter in chars:\n", | |
" try:\n", | |
" startpos = charlist.index(stringletter)\n", | |
" i = 0\n", | |
" i_a = startpos\n", | |
" lenght = len(charlist)\n", | |
" result = \"\"\n", | |
" maxi = lenght - startpos\n", | |
" while i != lenght:\n", | |
" if i == maxi:\n", | |
" i_a = 0\n", | |
" result += charlist[i_a]\n", | |
" i += 1\n", | |
" i_a += 1\n", | |
" print(result)\n", | |
" resultlist = []\n", | |
" for letter in result:\n", | |
" resultlist.append(letter)\n", | |
" letteritem = charlist.index(keyletter)\n", | |
" char = resultlist[letteritem]\n", | |
" print(char)\n", | |
" except ValueError:\n", | |
" char = stringletter\n", | |
" return char\n", | |
"#print(encode(string = \"MA STRING QUI ME PASSIONNE !!! VIVE VIGENERE !!!\", key = \"GRANDMISTERE\", chars = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"))\n", | |
"def decode(string, key, chars):\n", | |
" charlist = []\n", | |
" for letter in chars:\n", | |
" print(letter)\n", | |
" charlist.append(letter)\n", | |
" print(charlist)\n", | |
" lenght = len(string)\n", | |
" keystr = buildkey(key, lenght, string, chars)\n", | |
" genstring = \"\"\n", | |
" i = 0\n", | |
" for letter in string:\n", | |
" keyletter = keystr[i:i + 1]\n", | |
" genstring += getletter2(letter, keyletter, charlist, chars)\n", | |
" return genstring\n", | |
"def getletter2(stringletter, keyletter, charlist, chars):\n", | |
" #if stringletter in chars:\n", | |
" try:\n", | |
" startpos = charlist.index(keyletter)\n", | |
" i = 0\n", | |
" i_a = startpos\n", | |
" lenght = len(charlist)\n", | |
" result = \"\"\n", | |
" maxi = lenght - startpos\n", | |
" while i != lenght:\n", | |
" if i == maxi:\n", | |
" i_a = 0\n", | |
" result += charlist[i_a]\n", | |
" i += 1\n", | |
" i_a += 1\n", | |
" print(result)\n", | |
" resultlist = []\n", | |
" for letter in result:\n", | |
" resultlist.append(letter)\n", | |
" letteritem = resultlist.index(stringletter)\n", | |
" char = charlist[letteritem]\n", | |
" print(char)\n", | |
" except ValueError:\n", | |
" char = stringletter\n", | |
" return char\n", | |
"def enc_f(b):\n", | |
" string = text1.value\n", | |
" key = key_e.value\n", | |
" chars = charmap_e.value\n", | |
" charlist = []\n", | |
" for letter in chars:\n", | |
" charlist.append(letter)\n", | |
" badkey = False\n", | |
" for letter in key:\n", | |
" if letter in charlist:\n", | |
" pass\n", | |
" else:\n", | |
" badkey = True\n", | |
" if badkey == True:\n", | |
" text2.value = \"Error : Bad key.\"\n", | |
" else:\n", | |
" text = encode(string, key, chars)\n", | |
" text2.value = text\n", | |
"def dec_f(b):\n", | |
" string = text1.value\n", | |
" key = key_e.value\n", | |
" chars = charmap_e.value\n", | |
" charlist = []\n", | |
" for letter in chars:\n", | |
" charlist.append(letter)\n", | |
" badkey = False\n", | |
" for letter in key:\n", | |
" if letter in charlist:\n", | |
" pass\n", | |
" else:\n", | |
" badkey = True\n", | |
" if badkey == True:\n", | |
" text2.value = \"Bad key\"\n", | |
" else:\n", | |
" text = decode(string, key, chars)\n", | |
" text2.value = text\n", | |
"encb = widgets.Button(\n", | |
" description='Encoder',\n", | |
" disabled=False,\n", | |
" button_style='success',\n", | |
" tooltip='Encoder',\n", | |
" icon='key'\n", | |
")\n", | |
"decb = widgets.Button(\n", | |
" description='Décoder',\n", | |
" disabled=False,\n", | |
" button_style='success',\n", | |
" tooltip='Décoder',\n", | |
" icon='key'\n", | |
")\n", | |
"display(text1)\n", | |
"display(text2)\n", | |
"display(key_e)\n", | |
"display(charmap_e)\n", | |
"display(encb)\n", | |
"display(decb)\n", | |
"encb.on_click(enc_f)\n", | |
"decb.on_click(dec_f)" | |
], | |
"execution_count": null, | |
"outputs": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment