Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
Smash_pass
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
1
Merge Requests
1
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
Smashpass
Smash_pass
Commits
aec65bef
Commit
aec65bef
authored
Dec 09, 2024
by
Lokmane OUADERHMAN
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
RSA
parent
ed831788
Pipeline
#3053
failed with stages
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
0 deletions
+68
-0
_RSA_ENCRYPTION.py
Encryption Methods/_RSA_ENCRYPTION.py
+68
-0
No files found.
Encryption Methods/_RSA_ENCRYPTION.py
0 → 100644
View file @
aec65bef
#RSA ENCRYPTION
import
random
import
math
def
is_prime
(
number
):
if
number
<
2
:
return
False
for
i
in
range
(
2
,
number
//
2
+
1
):
if
number
%
i
==
0
:
return
False
return
True
def
generated_prime
(
limit
):
n
=
1000
N
=
[]
while
True
:
if
n
<
limit
:
if
is_prime
(
n
):
N
.
append
(
n
)
n
+=
1
else
:
break
return
N
def
mod_inverse
(
e
,
phi
):
for
d
in
range
(
3
,
phi
):
if
(
d
*
e
)
%
phi
==
1
:
return
d
raise
ValueError
(
'mod_inverse invalid'
)
p
,
q
=
random
.
choice
(
generated_prime
(
5000
)),
random
.
choice
(
generated_prime
(
5000
))
while
p
==
q
:
q
=
generated_prime
(
5000
)
n
=
p
*
q
phi_n
=
(
p
-
1
)
*
(
q
-
1
)
e
=
random
.
randint
(
3
,
phi_n
-
1
)
while
math
.
gcd
(
e
,
phi_n
)
!=
1
:
e
=
random
.
randint
(
3
,
phi_n
-
1
)
d
=
mod_inverse
(
e
,
phi_n
)
print
(
'public key is'
,
e
)
print
(
'private key is'
,
d
)
print
(
"n:"
,
n
)
print
(
"Phie of n:"
,
phi_n
)
print
(
"p:"
,
p
)
print
(
"q:"
,
q
)
message
=
'hello world'
message_encoded
=
[
ord
(
c
)
for
c
in
message
]
#(m^e) mod n =c
cipher_text
=
[
pow
(
c
,
e
,
n
)
for
c
in
message_encoded
]
# pow(c, e ,n) ====== > (c^e) mod n
print
(
cipher_text
)
message_encoded
=
[
pow
(
c
,
d
,
n
)
for
c
in
cipher_text
]
message
=
""
.
join
(
chr
(
c
)
for
c
in
message_encoded
)
print
(
message
)
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