Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
D
DS-Project
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
almohanad.hafez
DS-Project
Commits
b87b231b
Commit
b87b231b
authored
Nov 15, 2024
by
Almouhannad Hafez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor code
parent
e26ab76a
Changes
2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
473 additions
and
41 deletions
+473
-41
project.ipynb
project.ipynb
+232
-19
s_des.py
s_des.py
+241
-22
No files found.
project.ipynb
View file @
b87b231b
...
...
@@ -4,7 +4,15 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Setup"
"**Simplified Data Encryption Standard (SDES)** \n",
"***By: Almouhannad Hafez***\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Setup"
]
},
{
...
...
@@ -22,6 +30,13 @@
"%reload_ext autoreload"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Define new instance of SDES class"
]
},
{
"cell_type": "code",
"execution_count": 2,
...
...
@@ -31,16 +46,9 @@
"name": "stdout",
"output_type": "stream",
"text": [
"key:\n",
"10101000000011011100011100110001010011101011010011\n",
"original text:\n",
"Almouhannad.Hafez\n",
"original text in binary:\n",
"010000010110110001101101011011110111010101101000011000010110111001101110011000010110010000101110010010000110000101100110011001010111101000000000\n",
"encrypted:\n",
"001010101011011010111010111001011101000010111000101010000110110000111100101010000110010001000111100001001100000011100001001000101100111000110111\n",
"decrypted:\n",
"Almouhannad.Hafez\n"
"A new instance of SDES was initilized with parameters\n",
"key_length: 50\n",
"rounds_count: 100\n"
]
}
],
...
...
@@ -49,15 +57,220 @@
" key_length = 50,\n",
" rounds_count = 100\n",
")\n",
"\n",
"print(f\"A new instance of SDES was initilized with parameters\\nkey_length: {sdes.key_length}\\nrounds_count: {sdes.rounds_count}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Get a random key"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Radnomly generated key of length 50:\n",
"11100001010100011000010000010000001001111111100001\n"
]
}
],
"source": [
"key = sdes.generate_random_key()\n",
"print(f\"Radnomly generated key of length {sdes.key_length}:\\n{key}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Apply encryption"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Text 'Hello, I'm Almouhannad Hafez' after encryption using sdes:\n",
"010001110101010100101001111001100011001010011110110010000111000010111111011001111001101110110101111001100011111000010000000100010100110010100110111101111000110001001100110110010010110101100100000110101010111000011100001110001011\n"
]
}
],
"source": [
"text = \"Hello, I'm Almouhannad Hafez\"\n",
"encrypted_binary_string = sdes.encrypt(plain_text = text,\n",
" key = key)\n",
"\n",
"print(f\"Text '{text}' after encryption using sdes:\\n{encrypted_binary_string}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Apply decryption\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Decrypted text:\n",
"Hello, I'm Almouhannad Hafez\u0000\n"
]
}
],
"source": [
"decrypted_plain_text = sdes.decrypt(binary_encrypted_input=encrypted_binary_string,\n",
" key = key)\n",
"print(f\"Decrypted text:\\n{decrypted_plain_text}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Let's try other parameters"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"A new instance of SDES was initilized with parameters\n",
"key_length: 9\n",
"rounds_count: 2\n",
"Radnomly generated key of length 9:\n",
"110010000\n",
"Text 'Hello, I'm Almouhannad Hafez' after encryption using sdes:\n",
"111000111100010010010010000101110101110110111011110001100100100110011001101111010011100111000010000101110101101000110111111100101011111010111010010101100101110111100010000011011001110100111111011111101110110101100001000101000011\n",
"Decrypted text:\n",
"Hello, I'm Almouhannad Hafez\u0000\n"
]
}
],
"source": [
"sdes = SDES() # Default params\n",
"print(f\"A new instance of SDES was initilized with parameters\\nkey_length: {sdes.key_length}\\nrounds_count: {sdes.rounds_count}\")\n",
"\n",
"key = sdes.generate_random_key()\n",
"print(f\"key:\\n{key}\")\n",
"text = \"Almouhannad.Hafez\"\n",
"print(f\"original text:\\n{text}\")\n",
"print(f\"original text in binary:\\n{sdes.text_to_binary(text)}\")\n",
"enc = sdes.encrypt(text, key)\n",
"print(f\"encrypted:\\n{enc}\")\n",
"dec = sdes.decrypt(enc, key)\n",
"print(f\"decrypted:\\n{dec}\")\n"
"print(f\"Radnomly generated key of length {sdes.key_length}:\\n{key}\")\n",
"\n",
"text = \"Hello, I'm Almouhannad Hafez\"\n",
"encrypted_binary_string = sdes.encrypt(plain_text = text,\n",
" key = key)\n",
"print(f\"Text '{text}' after encryption using sdes:\\n{encrypted_binary_string}\")\n",
"\n",
"decrypted_plain_text = sdes.decrypt(binary_encrypted_input=encrypted_binary_string,\n",
" key = key)\n",
"print(f\"Decrypted text:\\n{decrypted_plain_text}\")"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"A new instance of SDES was initilized with parameters\n",
"key_length: 10000000\n",
"rounds_count: 2\n",
"Text 'Hello, I'm Almouhannad Hafez' after encryption using sdes:\n",
"100011000111000000011100011100001110001100110101001110011000100111000010111110011100100110110100011100001110100101111110100100111000000110110100101100111110100101101100000000101110110111001011011111111101101100111101111001001101\n",
"Decrypted text:\n",
"Hello, I'm Almouhannad Hafez\u0000\n"
]
}
],
"source": [
"sdes = SDES(key_length=10000000) # Large key\n",
"print(f\"A new instance of SDES was initilized with parameters\\nkey_length: {sdes.key_length}\\nrounds_count: {sdes.rounds_count}\")\n",
"\n",
"key = sdes.generate_random_key()\n",
"# print(f\"Radnomly generated key of length {sdes.key_length}:\\n{key}\")\n",
"\n",
"text = \"Hello, I'm Almouhannad Hafez\"\n",
"encrypted_binary_string = sdes.encrypt(plain_text = text,\n",
" key = key)\n",
"print(f\"Text '{text}' after encryption using sdes:\\n{encrypted_binary_string}\")\n",
"\n",
"decrypted_plain_text = sdes.decrypt(binary_encrypted_input=encrypted_binary_string,\n",
" key = key)\n",
"print(f\"Decrypted text:\\n{decrypted_plain_text}\")"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"A new instance of SDES was initilized with parameters\n",
"key_length: 9\n",
"rounds_count: 10000\n",
"Radnomly generated key of length 9:\n",
"110011101\n",
"Text 'Hello, I'm Almouhannad Hafez' after encryption using sdes:\n",
"000011110100111010111100111000111111101011000001110001111101000001101011011111000101001110010111111000111111010110010000100001111011011001101101101010100001100011000110111000001010011101001110101101101000100100101000000100111111\n",
"Decrypted text:\n",
"Hello, I'm Almouhannad Hafez\u0000\n",
"====================\n",
"Encrpytion time: 1.8319964408874512s\n",
"Decrpytion time: 2.1560163497924805s\n"
]
}
],
"source": [
"import time\n",
"\n",
"sdes = SDES(rounds_count=10000) # Large number of rounds\n",
"key = sdes.generate_random_key()\n",
"text = \"Hello, I'm Almouhannad Hafez\"\n",
"start_encryption_time = time.time()\n",
"encrypted_binary_string = sdes.encrypt(plain_text = text,\n",
" key = key)\n",
"end_encryption_time = time.time()\n",
"decrypted_plain_text = sdes.decrypt(binary_encrypted_input=encrypted_binary_string,\n",
" key = key)\n",
"end_decryption_time = time.time()\n",
"\n",
"print(f\"A new instance of SDES was initilized with parameters\\nkey_length: {sdes.key_length}\\nrounds_count: {sdes.rounds_count}\")\n",
"print(f\"Radnomly generated key of length {sdes.key_length}:\\n{key}\")\n",
"print(f\"Text '{text}' after encryption using sdes:\\n{encrypted_binary_string}\")\n",
"print(f\"Decrypted text:\\n{decrypted_plain_text}\")\n",
"\n",
"# Print exection times:\n",
"print(\"==\"*10)\n",
"print(f\"Encrpytion time: {end_encryption_time-start_encryption_time}s\")\n",
"print(f\"Decrpytion time: {end_decryption_time-end_encryption_time}s\")"
]
}
],
...
...
s_des.py
View file @
b87b231b
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment