Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
mega.py
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
richardARPANET
mega.py
Commits
ebca1d48
Commit
ebca1d48
authored
Mar 09, 2020
by
voussoir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add extended_gcd and modular_inverse functions.
parent
e28bee94
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
0 deletions
+17
-0
src/mega/crypto.py
src/mega/crypto.py
+17
-0
No files found.
src/mega/crypto.py
View file @
ebca1d48
...
...
@@ -106,6 +106,23 @@ def str_to_a32(b):
def
mpi_to_int
(
s
):
return
int
(
binascii
.
hexlify
(
s
[
2
:]),
16
)
def
extended_gcd
(
a
,
b
):
if
a
==
0
:
return
(
b
,
0
,
1
)
else
:
g
,
y
,
x
=
extended_gcd
(
b
%
a
,
a
)
return
(
g
,
x
-
(
b
//
a
)
*
y
,
y
)
def
modular_inverse
(
a
,
m
):
'''
Thank you Mart Bakhoff for this solution.
https://stackoverflow.com/a/9758173
'''
g
,
x
,
y
=
extended_gcd
(
a
,
m
)
if
g
!=
1
:
raise
Exception
(
'modular inverse does not exist'
)
else
:
return
x
%
m
def
base64_url_decode
(
data
):
data
+=
'=='
[(
2
-
len
(
data
)
*
3
)
%
4
:]
...
...
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