Skip to content

Instantly share code, notes, and snippets.

@abionics
Last active October 10, 2024 08:43
Show Gist options
  • Save abionics/1b3edacc5a4ee4afedb13d776858e7f3 to your computer and use it in GitHub Desktop.
Save abionics/1b3edacc5a4ee4afedb13d776858e7f3 to your computer and use it in GitHub Desktop.
feistel-py inconsistent number encryption
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "5394eb87-2328-4eb2-b7b6-8866ad3eb6fe",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Collecting feistel-py\n",
" Downloading feistel_py-0.2.0-py3-none-any.whl.metadata (9.2 kB)\n",
"Collecting pycryptodome>=3.20.0 (from feistel-py)\n",
" Downloading pycryptodome-3.21.0-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (3.4 kB)\n",
"Collecting py-utls>=0.2.0 (from feistel-py)\n",
" Downloading py_utls-0.2.0-py3-none-any.whl.metadata (2.2 kB)\n",
"Downloading feistel_py-0.2.0-py3-none-any.whl (14 kB)\n",
"Downloading py_utls-0.2.0-py3-none-any.whl (3.6 kB)\n",
"Downloading pycryptodome-3.21.0-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.3 MB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.3/2.3 MB\u001b[0m \u001b[31m5.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n",
"\u001b[?25hInstalling collected packages: pycryptodome, py-utls, feistel-py\n",
"Successfully installed feistel-py-0.2.0 py-utls-0.2.0 pycryptodome-3.21.0\n"
]
}
],
"source": [
"! pip install feistel-py"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "0c2cc26a-6f3a-4262-a856-c91b3c3fd7d2",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1403 22826 3451\n"
]
}
],
"source": [
"from feistel import FPECipher, SHA_256\n",
"\n",
"cipher = FPECipher(SHA_256, \"some-32-byte-long-key-to-be-safe\", 128)\n",
"\n",
"number = 1403\n",
"obfuscated = cipher.encrypt_number(number)\n",
"deciphered = cipher.decrypt_number(obfuscated)\n",
"print(number, obfuscated, deciphered)\n",
"# 1403 22826 3451"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.10.14"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment