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
63c4992b
Commit
63c4992b
authored
Nov 13, 2024
by
Almouhannad Hafez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement get_blocks
parent
f0a71ff8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
1 deletion
+57
-1
project.ipynb
project.ipynb
+33
-0
s_des.py
s_des.py
+24
-1
No files found.
project.ipynb
View file @
63c4992b
...
...
@@ -63,6 +63,39 @@
"print(text)\n",
"print(text == original_text)\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['010000010110',\n",
" '110001101101',\n",
" '011011110111',\n",
" '010101101000',\n",
" '011000010110',\n",
" '111001101110',\n",
" '011000010110',\n",
" '010000101110',\n",
" '010010000110',\n",
" '000101100110',\n",
" '011001010111',\n",
" '101000100000',\n",
" '001010110010',\n",
" '000000110001']"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sdes.get_blocks(original_text)"
]
}
],
"metadata": {
...
...
s_des.py
View file @
63c4992b
...
...
@@ -140,4 +140,27 @@ class SDES:
# Convert to string plain text
text
=
''
.
join
(
chr
(
int
(
char
,
2
))
for
char
in
chars
)
return
text
\ No newline at end of file
return
text
def
get_blocks
(
self
,
plain_text
:
str
)
->
list
[
str
]:
"""
Convert plain text into a list of binary strings, each with length of self.block_size
Parameters:
plain_text (str): Text to be converted
Returns:
blocks (list[str]): Binary blocks of the original text
"""
# Type checking
if
not
isinstance
(
plain_text
,
str
):
raise
TypeError
(
f
"'plain_text' must be str, got {type(plain_text).__name__}"
)
# Validation rules
if
len
(
plain_text
)
==
0
:
raise
ValueError
(
"'plain_text' must not be empty"
)
binary_text
=
self
.
text_to_binary
(
plain_text
)
blocks
=
[]
blocks
=
[
binary_text
[
i
:
i
+
self
.
block_size
]
for
i
in
range
(
0
,
len
(
binary_text
),
self
.
block_size
)]
return
blocks
\ No newline at end of file
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