Skip to content

Instantly share code, notes, and snippets.

@l4km47
Last active February 9, 2024 21:28
Show Gist options
  • Save l4km47/c8feb04400d4ec443ebdf5510239e3d2 to your computer and use it in GitHub Desktop.
Save l4km47/c8feb04400d4ec443ebdf5510239e3d2 to your computer and use it in GitHub Desktop.
Kuweni riddle solve
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"authorship_tag": "ABX9TyM+/TAewbMI01cLaKo7k+YD",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/l4km47/c8feb04400d4ec443ebdf5510239e3d2/untitled7.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"source": [
"# prompt: pip install pycrypto\n",
"\n",
"!pip install crypto\n",
"!pip install pycryptodome\n",
"!pip install pycryptodomex\n",
"\n"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "QIgkqfCOaxKS",
"outputId": "6acaf4dc-8950-40a2-f478-e1b8703a1a3d"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Requirement already satisfied: crypto in /usr/local/lib/python3.10/dist-packages (1.4.1)\n",
"Requirement already satisfied: Naked in /usr/local/lib/python3.10/dist-packages (from crypto) (0.1.32)\n",
"Requirement already satisfied: shellescape in /usr/local/lib/python3.10/dist-packages (from crypto) (3.8.1)\n",
"Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from Naked->crypto) (2.31.0)\n",
"Requirement already satisfied: pyyaml in /usr/local/lib/python3.10/dist-packages (from Naked->crypto) (6.0.1)\n",
"Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests->Naked->crypto) (3.3.2)\n",
"Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests->Naked->crypto) (3.6)\n",
"Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests->Naked->crypto) (2.0.7)\n",
"Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests->Naked->crypto) (2024.2.2)\n",
"Requirement already satisfied: pycryptodome in /usr/local/lib/python3.10/dist-packages (3.20.0)\n",
"Requirement already satisfied: pycryptodomex in /usr/local/lib/python3.10/dist-packages (3.20.0)\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"import base64\n",
"from Crypto.Cipher import AES\n",
"from Crypto.Util.Padding import unpad\n",
"\n",
"# The provided encoded data\n",
"encoded_data = \"TPnp6B9wYGSAbWtybLTurkVJV1MNpEGZR66dArftN53qtTUo1bp+QN7l5dS/MGHpMwRAEAzXr5TWhCm3sEQxpZVHcGYmqoySh0hO9e1wgro9nmIOOTuhfbCN2p1sKxgsTeYjqq77ZrnDqlW8AYYx7+iPRIFur7rFRMQapeglwsDvit2NRVxh3JjINhfV9v1SggkwMaw8IevRQqsXFxh3zUJ+lwUUcoiw5VwdoQDxp8kKA32QT/VnaXFblgGaqCcecLNSWp+VNxslRqIqYAW9dRCE6JNgYuFQacx6f/nOB0OTfx6n77BM2eqij/b0zmZBxfZFJFTWjLmDWsrkUj0B5/3hiNOsiu0njfqhQdvanVE=\"\n",
"\n",
"# Attempt to decode the data assuming it's Base64. Due to potential formatting issues (spaces and line breaks),\n",
"# we first need to clean the data.\n",
"clean_encoded_data = encoded_data #.replace(\" \", \"\").replace(\"\\n\", \"\")\n",
"clean_encoded_data"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 70
},
"id": "RSm39Aakaq8q",
"outputId": "d0a7be92-0411-4266-bb9e-f4ffe8f1c64f"
},
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"'TPnp6B9wYGSAbWtybLTurkVJV1MNpEGZR66dArftN53qtTUo1bp+QN7l5dS/MGHpMwRAEAzXr5TWhCm3sEQxpZVHcGYmqoySh0hO9e1wgro9nmIOOTuhfbCN2p1sKxgsTeYjqq77ZrnDqlW8AYYx7+iPRIFur7rFRMQapeglwsDvit2NRVxh3JjINhfV9v1SggkwMaw8IevRQqsXFxh3zUJ+lwUUcoiw5VwdoQDxp8kKA32QT/VnaXFblgGaqCcecLNSWp+VNxslRqIqYAW9dRCE6JNgYuFQacx6f/nOB0OTfx6n77BM2eqij/b0zmZBxfZFJFTWjLmDWsrkUj0B5/3hiNOsiu0njfqhQdvanVE='"
],
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
}
},
"metadata": {},
"execution_count": 36
}
]
},
{
"cell_type": "code",
"source": [
"\n",
"def decode_hex(hex_string):\n",
" try:\n",
" # Convert from hex to bytes\n",
" bytes_data = bytes.fromhex(hex_string)\n",
"\n",
" # Try to decode as UTF-8 text\n",
" try:\n",
" text_data = bytes_data.decode('utf-8')\n",
" return text_data\n",
" except UnicodeDecodeError:\n",
" # If it's not valid UTF-8 text, return the raw bytes\n",
" return bytes_data\n",
" except ValueError as e:\n",
" return f\"Error decoding hex: {str(e)}\"\n"
],
"metadata": {
"id": "YRqxyFUEas2s"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"\n",
"try:\n",
" decoded_data = base64.b64decode(clean_encoded_data)\n",
" print(decoded_data.hex())\n",
" result = decoded_data.hex()\n",
"except Exception as e:\n",
" result = f\"Error decoding: {str(e)}\""
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "VTuSvk2rb9Gv",
"outputId": "d3adb719-2a46-4f4d-e6f6-04a03592af04"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"4cf9e9e81f706064806d6b726cb4eeae454957530da4419947ae9d02b7ed379deab53528d5ba7e40dee5e5d4bf3061e9330440100cd7af94d68429b7b04431a59547706626aa8c9287484ef5ed7082ba3d9e620e393ba17db08dda9d6c2b182c4de623aaaefb66b9c3aa55bc018631efe88f44816eafbac544c41aa5e825c2c0ef8add8d455c61dc98c83617d5f6fd5282093031ac3c21ebd142ab17171877cd427e9705147288b0e55c1da100f1a7c90a037d904ff56769715b96019aa8271e70b3525a9f95371b2546a22a6005bd751084e8936062e15069cc7a7ff9ce0743937f1ea7efb04cd9eaa28ff6f4ce6641c5f6452454d68cb9835acae4523d01e7fde188d3ac8aed278dfaa141dbda9d51\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"encoded_bytes=decode_hex(result)\n",
"encoded_bytes"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "D5zdKp9ab_hA",
"outputId": "0d5afae0-1fbd-4973-81a6-378d474ab59f"
},
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"b\"L\\xf9\\xe9\\xe8\\x1fp`d\\x80mkrl\\xb4\\xee\\xaeEIWS\\r\\xa4A\\x99G\\xae\\x9d\\x02\\xb7\\xed7\\x9d\\xea\\xb55(\\xd5\\xba~@\\xde\\xe5\\xe5\\xd4\\xbf0a\\xe93\\x04@\\x10\\x0c\\xd7\\xaf\\x94\\xd6\\x84)\\xb7\\xb0D1\\xa5\\x95Gpf&\\xaa\\x8c\\x92\\x87HN\\xf5\\xedp\\x82\\xba=\\x9eb\\x0e9;\\xa1}\\xb0\\x8d\\xda\\x9dl+\\x18,M\\xe6#\\xaa\\xae\\xfbf\\xb9\\xc3\\xaaU\\xbc\\x01\\x861\\xef\\xe8\\x8fD\\x81n\\xaf\\xba\\xc5D\\xc4\\x1a\\xa5\\xe8%\\xc2\\xc0\\xef\\x8a\\xdd\\x8dE\\\\a\\xdc\\x98\\xc86\\x17\\xd5\\xf6\\xfdR\\x82\\t01\\xac<!\\xeb\\xd1B\\xab\\x17\\x17\\x18w\\xcdB~\\x97\\x05\\x14r\\x88\\xb0\\xe5\\\\\\x1d\\xa1\\x00\\xf1\\xa7\\xc9\\n\\x03}\\x90O\\xf5giq[\\x96\\x01\\x9a\\xa8'\\x1ep\\xb3RZ\\x9f\\x957\\x1b%F\\xa2*`\\x05\\xbdu\\x10\\x84\\xe8\\x93`b\\xe1Pi\\xccz\\x7f\\xf9\\xce\\x07C\\x93\\x7f\\x1e\\xa7\\xef\\xb0L\\xd9\\xea\\xa2\\x8f\\xf6\\xf4\\xcefA\\xc5\\xf6E$T\\xd6\\x8c\\xb9\\x83Z\\xca\\xe4R=\\x01\\xe7\\xfd\\xe1\\x88\\xd3\\xac\\x8a\\xed'\\x8d\\xfa\\xa1A\\xdb\\xda\\x9dQ\""
]
},
"metadata": {},
"execution_count": 39
}
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "VBwDpeELajdy",
"outputId": "5694db58-fcab-4a5d-a56b-cddf02a8ecfd"
},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"b'\"Yogeshwari\" - A story inspired by the woman who masterfully utilised cyphers in the world of espionage for communication. \\n\\nThere are many such messages to be discovered in the Kuweniverse.\\n\\nA friendly reminder to confirm the source before trusting your eyes and ears.\\x03\\x03\\x03'\n"
]
}
],
"source": [
"\n",
"adjusted_key =b'yoKgUeWsEhNwIari' # b'kuw3n1v3r5equest'\n",
"cipher_ecb = AES.new(adjusted_key, AES.MODE_ECB)\n",
"\n",
"decrypted_data_ecb = cipher_ecb.decrypt(encoded_bytes)\n",
"print(decrypted_data_ecb)"
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment