Skip to content

Instantly share code, notes, and snippets.

@aleksejalex
Created May 3, 2024 10:30
Show Gist options
  • Save aleksejalex/1dad3b249ee314f908707a901c1754d7 to your computer and use it in GitHub Desktop.
Save aleksejalex/1dad3b249ee314f908707a901c1754d7 to your computer and use it in GitHub Desktop.
encrypting_via_img.ipynb
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/aleksejalex/1dad3b249ee314f908707a901c1754d7/encrypting_via_img.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "OWirxiXCAaoM"
},
"source": [
"# Bonus: a funny way to encrypt text\n",
"\n",
" > Do you need to store some very important note/password in visible place and yet still be sure it won't be easily found?\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "fc1E-wVqAaoR"
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "3zzw_nGVAaoV",
"outputId": "4cb7673e-e7df-4851-af20-f4cf3b6bdd92"
},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import cv2\n",
"import numpy as np\n",
"\n",
"text = \"Hello World!\"\n",
"\n",
"# Create a black image\n",
"img = np.zeros((1, len(text), 3), dtype=np.uint8)\n",
"\n",
"# Fill the image with text\n",
"for i in range(len(text)):\n",
" img[0, i] = (ord(text[i]), 0, 0) # ord(letter) returns number of a letter\n",
"\n",
"# Save the image\n",
"cv2.imwrite('out.png', img)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "O176-PWeAaoX",
"outputId": "4f7d43e8-0134-4e4e-aa63-081af42976b7"
},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.image.AxesImage at 0x7fb7fad69250>"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAi8AAABaCAYAAABwpLYfAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8fJSN1AAAACXBIWXMAAA9hAAAPYQGoP6dpAAAPbUlEQVR4nO3df0yU9QMH8Pfd4d2BA1QUjlNRNAt/IConCLp04yapc6NaaVESmq0NCzzXBAuZml7+nFOZSJv1R5LWlqau3Oj0SzNREKS0FNNMmPNAhwLiArrn+f7RvHaDg6Pd48NH36/t2brnPg+8eQKf9557nuejkWVZBhEREZEgtGoHICIiIuoLlhciIiISCssLERERCYXlhYiIiITC8kJERERCYXkhIiIiobC8EBERkVBYXoiIiEgoLC9EREQkFJYXIiIiEopi5aWpqQnp6ekICQnBoEGDsGzZMjx48KDHbebMmQONRuOxvPvuu0pFJCIiIgFplJrbaN68ebh9+zb27duHzs5OZGZmYvr06SgpKfG6zZw5c/Dss89i/fr17nVBQUEICQlRIiIREREJKECJL3r58mWcOHEClZWVsFgsAIDdu3dj/vz52LZtG8xms9dtg4KCYDKZlIhFRERETwBFykt5eTkGDRrkLi4AYLVaodVqce7cObz44otetz1w4AC++OILmEwmLFy4EPn5+QgKCvI6vr29He3t7e7XkiShqakJYWFh0Gg0/vmBiIiISFGyLKO1tRVmsxlabc9XtShSXpxOJ8LDwz2/UUAAhgwZAqfT6XW7119/HaNGjYLZbMYvv/yC1atXo7a2Ft98843Xbex2O9atW+e37ERERKSe+vp6jBgxoscxfSovubm52Lx5c49jLl++3Jcv6eGdd95x/3dsbCwiIyORkpKC69evY+zYsd1uk5eXB5vN5n7d3NyMqKgozIFCzcxPhqsdwEcGtQM8QUS4te87tQP4wNL7kH4hvPchqtOpHcBHnWoH8MFfagfwUZnaAXogAagHEBwc3OvYPh3fV61ahbfeeqvHMWPGjI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ABJRU5ErkJggg==",
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plt.imshow(img)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "SLIsb7j5Aaoa",
"outputId": "fbf69dfe-b7ad-4d8c-d8e1-ee45e7e8744f"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello World!\n"
]
}
],
"source": [
"#decoder\n",
"text = \"\"\n",
"\n",
"# Read the image\n",
"img = cv2.imread('out.png')\n",
"\n",
"# Get the width of the image\n",
"width = img.shape[1]\n",
"\n",
"# Iterate through each pixel in the first row of the image\n",
"for i in range(width):\n",
" # Get the pixel value\n",
" px = img[0, i]\n",
" # Extract the first channel value (red channel)\n",
" channel_value = px[0]\n",
" # Convert the channel value to a character and append it to the text\n",
" text = text + chr(channel_value)\n",
"\n",
"print(text)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "l-uQrKHaAaob"
},
"outputs": [],
"source": [
"# ####################################################################################"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "UDBO76hNAaod"
},
"source": [
"An illustration of `ord()` and `chr()` re-type:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "TMgNh-ncAaod",
"outputId": "62a10487-7362-41d5-a7db-51db3fab92e1"
},
"outputs": [
{
"data": {
"text/plain": [
"97"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ord('a')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "RApypBfiAaof",
"outputId": "8ce0dd66-2e01-4517-c6d7-43d62f22c2d3"
},
"outputs": [
{
"data": {
"text/plain": [
"98"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ord('b')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "iJg7_s9WAaoh",
"outputId": "25df8b9b-ef8b-451e-b805-9bb1bab0bc9d"
},
"outputs": [
{
"data": {
"text/plain": [
"'a'"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"chr(97)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "81ovwBOIAaoi",
"outputId": "352afa3b-16bb-4908-b28f-b7c01ce9ab00"
},
"outputs": [
{
"data": {
"text/plain": [
"'b'"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"chr(98)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "fhof41KsAaoj"
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "GW4e6pDgAaoj"
},
"outputs": [],
"source": [
"# ####################################################################################"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "6S2aOLXDAaok"
},
"source": [
"Same functionality with different library - `PIL`:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "RfLXHaK8Aaok"
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "8kSiBQ7cAaol"
},
"outputs": [],
"source": [
"#package with similar functionality to opencv\n",
"from PIL import Image"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "ggfFiYxvAaol"
},
"outputs": [],
"source": [
"# encoder (string to image)\n",
"text = \"Hello World!\"\n",
"\n",
"img = Image.new(mode = 'RGB', size = (len(text),1))\n",
"\n",
"for i in range(len(text)):\n",
" img.putpixel((i,0), (ord(text[i]),0,0)) # ord(letter) returns number of a letter\n",
"\n",
"img.save('out.png')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "4LlVI-L8Aaol",
"outputId": "cb18de6f-4a21-463a-ec26-97b566497b29"
},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.image.AxesImage at 0x7f17ac06c620>"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0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Fy6dAmnT59WO4qQ6uvrkZ2djdLSUhiNRrXjCEuSJFgsFmzatAkAMHXqVFy6dAlFRUUsL3301Vdf4cCBAygpKcHEiRNRU1ODnJwcmM1m7ktSDD828mLo0KHQ6XRoaGjwWN/Q0ACTyaRSKrGtWLECx48fx6lTpzBixAi14wipqqoKjY2NmDZtGgICAhAQEICysjLs2rULAQEBcLlcakcUQmRkZJfJXsePH4+6ujqVEonrgw8+QG5uLhYvXozY2Fi8+eabWLlyJex2u9rRhPboOMNjUPdYXrzQ6/WIj4+Hw+Fwr5MkCQ6HA0lJSSomE48sy1ixYgUOHz6MkydPIjo6Wu1IwkpJScHFixdRU1PjXiwWC9LT01FTUwOdTqd2RCHMnDmzy+36V69exahRo1RKJK6HDx9Cq/U8lOh0OkiSpFKiJ0N0dDRMJpPHMailpQXnzp3jMQj82KhHNpsNGRkZsFgsSEhIwM6dO9HW1obMzEy1owklKysLJSUl+PbbbxEcHOz+vDY0NBSBgYEqpxNLcHBwl2uFBg4ciLCwMF5D1AcrV65EcnIyNm3ahFdffRUVFRUoLi5GcXGx2tGEs3DhQmzcuBFRUVGYOHEiLly4gB07dmDp0qVqR+v3Hjx4gGvXrrlf37hxAzU1NRgyZAiioqKQk5ODjz/+GOPGjUN0dDTy8/NhNpuRlpamXuj+Qu3bnfq73bt3y1FRUbJer5cTEhLks2fPqh1JOAC6XT777DO1oz0ReKv0f3Ps2DF50qRJssFgkGNiYuTi4mK1IwmppaVFzs7OlqOiomSj0SiPGTNG/vDDD+X29na1o/V7p06d6vbfxoyMDFmW/7ldOj8/X46IiJANBoOckpIi19bWqhu6n9DIMh+DSEREROLgNS9EREQkFJYXIiIiEgrLCxEREQmF5YWIiIiEwvJCREREQmF5ISIiIqGwvBAREZFQWF6IiIhIKCwvREREJBSWFyIiIhIKywsREREJ5f+q1yhEZk4cpAAAAABJRU5ErkJggg==",
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plt.imshow(img)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "ABbGMUE9Aaol",
"outputId": "94a2fc05-9be2-4d04-bfb5-8771eb14f025"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello World!\n"
]
}
],
"source": [
"# decoder\n",
"text = \"\"\n",
"\n",
"img = Image.open('out.png')\n",
"width, height = img.size\n",
"\n",
"for i in range(width):\n",
" px = img.getpixel((i,0))\n",
" text += chr(px[0])\n",
"\n",
"print(text)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "cP3EGy6SAaon"
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.2"
},
"colab": {
"provenance": [],
"include_colab_link": true
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment