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 }}
LockGit
Py
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
Py
/
rsa.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
49 lines (36 loc) · 1.31 KB
master
Breadcrumbs
Py
/
rsa.py
Copy path
Top
File metadata and controls
Code
Blame
49 lines (36 loc) · 1.31 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
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python
# encoding: utf-8
# author: Lock
# time: 2016/11/8 16:51
# RSA算法中加密方公布的密钥是n和e,解密方使用n和d解密
# p和q必须为素数,在实际运用中通常为很大的数
p = 5
q = 7
n = p * q
z = (p - 1) * (q - 1)
e = 5 # 加密方选择e,e必须和z只有一个公约数
d = 5 # (e * d - 1)必须能够被z整除 , 由于long int无法表示过大的数字,所以d取5
def run():
raw_msg = [12, 15, 22, 5]
en, de = [], []
sec_code, de_msg = [], []
print "下面是一个RSA加解密算法的简单演示:\n"
print "报文\t加密\t 加密后密文\n"
for item in raw_msg:
en_key_item = pow(item, e)
en.append(en_key_item)
sec_code_item = en_key_item % n
sec_code.append(sec_code_item)
print "%d\t%d\t\t%d" % (item, en_key_item, sec_code_item)
print "\n"
print "---------------------------"
print "----------执行解密---------"
print "---------------------------"
print "原始报文\t密文\t加密\t解密报文\n"
for key,item in enumerate(sec_code):
de_key_item = pow(item,d)
de_msg_item = de_key_item % n
de_msg.append(de_msg_item)
print "%d\t\t%d\t%d\t\t%d" % (raw_msg[key], item, de_key_item, de_msg_item)
if __name__ == '__main__':
run()
You can’t perform that action at this time.