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
0e050e1e
You need to sign in or sign up before continuing.
Commit
0e050e1e
authored
Nov 13, 2024
by
Almouhannad Hafez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement process_block, binary_strings_xor
parent
63c4992b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
2 deletions
+20
-2
s_des.py
s_des.py
+20
-2
No files found.
s_des.py
View file @
0e050e1e
...
@@ -11,7 +11,6 @@ class SDES:
...
@@ -11,7 +11,6 @@ class SDES:
key_length (int): Length of keys that will be used for encryption/decryption
key_length (int): Length of keys that will be used for encryption/decryption
"""
"""
# SDES is a block-cipher algorithm, uses blocks of size 12 bits
# SDES is a block-cipher algorithm, uses blocks of size 12 bits
# You can change this default value from here directly, and it'll applied to the whole code
self
.
block_size
=
12
self
.
block_size
=
12
# SDED uses a fixed-length key (8bits- key) for each iteration
# SDED uses a fixed-length key (8bits- key) for each iteration
...
@@ -163,4 +162,23 @@ class SDES:
...
@@ -163,4 +162,23 @@ class SDES:
binary_text
=
self
.
text_to_binary
(
plain_text
)
binary_text
=
self
.
text_to_binary
(
plain_text
)
blocks
=
[]
blocks
=
[]
blocks
=
[
binary_text
[
i
:
i
+
self
.
block_size
]
for
i
in
range
(
0
,
len
(
binary_text
),
self
.
block_size
)]
blocks
=
[
binary_text
[
i
:
i
+
self
.
block_size
]
for
i
in
range
(
0
,
len
(
binary_text
),
self
.
block_size
)]
return
blocks
return
blocks
\ No newline at end of file
def
process_block
(
self
,
key
:
str
,
round_number
:
int
,
old_block
:
str
)
->
str
:
L_old
,
R_old
=
old_block
[
0
:
self
.
block_size
/
2
,
self
.
block_size
/
2
,
self
.
block_size
]
L_new
=
R_old
round_key
=
self
.
get_round_key
(
key
,
round_number
)
R_new
=
self
.
f
(
round_key
,
R_old
)
R_new
=
self
.
binary_strings_xor
(
R_new
,
L_old
)
new_block
=
''
new_block
+=
L_new
new_block
+=
R_new
return
new_block
def
binary_strings_xor
(
self
,
binary_string_1
:
str
,
binary_string_2
:
str
)
->
str
:
num1
=
int
(
binary_string_1
,
2
)
num2
=
int
(
binary_string_2
,
2
)
xor_result
=
num1
^
num2
xor_result_str
=
bin
(
xor_result
)[
2
:]
xor_result_str
=
xor_result_str
.
zfill
(
len
(
binary_string_1
))
return
xor_result_str
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