FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
TheAlgorithms-Python/ciphers/onepad_cipher.py at master · windNight/TheAlgorithms-Python · GitHub
windNight
/
TheAlgorithms-Python
Public
forked from
TheAlgorithms/Python
Notifications
You must be signed in to change notification settings
Fork
1
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
TheAlgorithms-Python
/
ciphers
/
onepad_cipher.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
30 lines (25 loc) · 849 Bytes
Breadcrumbs
TheAlgorithms-Python
/
ciphers
/
onepad_cipher.py
Copy path
File metadata and controls
30 lines (25 loc) · 849 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import
random
class
Onepad
:
def
encrypt
(
self
,
text
:
str
)
->
([
str
], [
int
]):
"""Function to encrypt text using pseudo-random numbers"""
plain
=
[
ord
(
i
)
for
i
in
text
]
key
=
[]
cipher
=
[]
for
i
in
plain
:
k
=
random
.
randint
(
1
,
300
)
c
=
(
i
+
k
)
*
k
cipher
.
append
(
c
)
key
.
append
(
k
)
return
cipher
,
key
def
decrypt
(
self
,
cipher
: [
str
],
key
: [
int
])
->
str
:
"""Function to decrypt text using pseudo-random numbers."""
plain
=
[]
for
i
in
range
(
len
(
key
)):
p
=
int
((
cipher
[
i
]
-
(
key
[
i
])
**
2
)
/
key
[
i
])
plain
.
append
(
chr
(
p
))
plain
=
""
.
join
([
i
for
i
in
plain
])
return
plain
if
__name__
==
"__main__"
:
c
,
k
=
Onepad
().
encrypt
(
"Hello"
)
print
(
c
,
k
)
print
(
Onepad
().
decrypt
(
c
,
k
))
Back
|
FazBrowse Home
|
New Git URL