Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects, and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Developer articles
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
trizen
sidef-scripts
Repository navigation
Code
Issues
1
(1)
Pull requests
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
sidef-scripts
/
Math
/
rabin_encryption_method.sf
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
36 lines (27 loc) · 1.41 KB
master
Breadcrumbs
sidef-scripts
/
Math
/
rabin_encryption_method.sf
Copy path
Top
File metadata and controls
Code
Blame
36 lines (27 loc) · 1.41 KB
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
31
32
33
34
35
36
#!/usr/bin/ruby
/*
Rabin's protocol is equivalent to factoring: Suppose you have a procedure P
which, given a quadratic residue, gives one of its square roots mod pq. The
four nsquare roots of a quadratic residue y=x^2 mod pq is -x, x, -gamma x,
gamma x, where gamma is the nontrivial square root of unity mod pq.
Aside: you can find gamma if you know p and q by using the Chinese
Remainder Theorem (CRT) and solving the system of equations
x = -1 mod p
x = 1 mod q
[ You can see where the other square roots of unity comes from: they are the
other possible patterns of signs on the 1's in the system of eqns for CRT. ]
Now, given P, you choose a random r between 1 and pq-1 inclusive and compute
y = P(r^2). With 1/2 probability, y = +/- gamma r. Since you knew r, you
can find g = y/r = +/- gamma. Now, since g-1 is either 0 mod q or 0 mod p,
so GCD(g-1,pq) will give you p or q.
[ To find 1/r mod pq, use EGCD: The extended Euclidean algorithm, given
m,n, will find GCD(m,n) as well as the pair a,b such that am+bn=GCD(m,n).
When GCD(m,n)=1, we have a=1/m mod n. ]
Note that this can be simplfied a little, since with very high probability r
does not divide pq: r(g-1) = r(y/r - 1) = y - r, so GCD(y-r,pq) will work
just as well. If r divides pq, you've already (accidentally) factored the
modulus.
*/
# See also:
# https://ratthing.com/files/textfiles.com/programming/CRYPTOGRAPHY/rabin-al.txt
# TODO: implement it
You can’t perform that action at this time.