-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrsa.html
173 lines (165 loc) · 7.15 KB
/
rsa.html
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title></title>
<script src="js/mui.min.js"></script>
<link href="css/mui.min.css" rel="stylesheet" />
<link href="css/wiki.css" rel="stylesheet" />
<script type="text/javascript" charset="UTF-8">
mui.init();
</script>
<style type="text/css">
p{
color: #000000;
margin-left: 10px;
margin-right: 10px;
}
h4{
margin-left: 10px;
}
</style>
</head>
<body>
<header id="header" class="mui-bar mui-bar-nav" style="height:74px;background: rgba(255,255,255,0);box-shadow: 0 0 0px rgba(0, 0, 0, 0);">
<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" style="color: #FFFFFF;margin-top: 30px;"></a>
<h1 id="nav_title" class="mui-title" style="color: #FFFFFF;margin-top: 30px;">RSA</h1>
</header>
<div class="mui-content">
<img id="background" src="img/Symmetric_key_encryption.svg.png" style="width: 100%;margin-top: -13%;"/>
<div class="mui-content">
<h4><br>Example</h4><br>
<p>Here is an example of RSA encryption and decryption. The parameters used here are artificially small, but one can also use OpenSSL to generate and examine a real keypair.</p>
<p>Choose two distinct prime numbers, such as<br>
p =61 and q =53<br>
Compute n = pq giving<br>
n = 61 x 53 = 3233<br>
Compute the totient of the product as φ(n) = (p − 1)(q − 1) giving<br>
φ(n) = (61 − 1)(53 − 1) = 3120<br>
Choose any number 1 < e < 3120 that is coprime to 3120. Choosing a prime number for e leaves us only to check that e is not a divisor of 3120.
<br>Let e = 17 <br>
Compute d, the modular multiplicative inverse of e (mod φ(n)) yielding,<br>
d = 2753<br>
Worked example for the modular multiplicative inverse:<br>
d x e mod φ(n) = 1<br>
2753 x 17 mod 3120 = 1 <br>
The public key is (n = 3233, e = 17). For a padded plaintext message m, the encryption function is<br>
c(m) = m^17 mod 3233<br>
The private key is (d = 2753). For an encrypted ciphertext c, the decryption function is<br>
m(c) = c^2753 mod 3233<br>
For instance, in order to encrypt m = 65, we calculate<br>
c = 65^17 mod 3233 = 2790<br>
To decrypt c = 2790, we calculate<br>
m = 2790^2753 mod 3233 = 65<br>
Both of these calculations can be computed efficiently using the square-and-multiply algorithm for modular exponentiation. In real-life situations the primes selected would be much larger; in our example it would be trivial to factor n, 3233 (obtained from the freely available public key) back to the primes p and q. e, also from the public key, is then inverted to get d, thus acquiring the private key.<br>
</p>
</div>
<div class="mw-highlight mw-content-ltr" dir="ltr">
</div>
</body>
<script type="text/javascript">
var header = document.getElementById('header');
var background = document.getElementById('background');
setInterval(function() {
var t = document.body.scrollTop;
var height = background.offsetHeight - 74;
if(t>=0 && t<height * 0.1){
header.style.background = "rgba(61,171,201,0)";
document.getElementById('nav_title').style.opacity = 0;
}
if(t>=height * 0.1 + 1 && t<height * 0.2){
header.style.background = "rgba(61,171,201,0.1)";
document.getElementById('nav_title').style.opacity = 0;
}
if(t>=height * 0.2 + 1 && t<height * 0.3){
header.style.background = "rgba(61,171,201,0.2)";
document.getElementById('nav_title').style.opacity = 0;
}
if(t>=height * 0.3 + 1 && t<height * 0.4){
header.style.background = "rgba(61,171,201,0.3)";
document.getElementById('nav_title').style.opacity = 0;
}
if(t>=height * 0.4 + 1 && t<height * 0.5){
header.style.background = "rgba(61,171,201,0.4)";
document.getElementById('nav_title').style.opacity = 0;
}
if(t>=height * 0.5 + 1 && t<height * 0.6){
header.style.background = "rgba(61,171,201,0.5)";
document.getElementById('nav_title').style.opacity = 0;
}
if(t>=height * 0.6 + 1 && t<height * 0.7){
header.style.background = "rgba(61,171,201,0.6)";
document.getElementById('nav_title').style.opacity = 0;
}
if(t>=height * 0.7 + 1 && t<height * 0.8){
header.style.background = "rgba(61,171,201,0.7)";
document.getElementById('nav_title').style.opacity = 0;
}
if(t>=height * 0.8 + 1 && t<height * 0.9){
header.style.background = "rgba(61,171,201,0.8)";
document.getElementById('nav_title').style.opacity = 0;
}
if(t>=height * 0.9 + 1 && t<height * 1){
header.style.background = "rgba(61,171,201,0.9)";
document.getElementById('nav_title').style.opacity = 0;
}
if(t>=height){
header.style.background = "rgba(61,171,201,1)";
header.style.boxShadow = "0 0 1px rgba(0, 0, 0, .85);";
document.getElementById('nav_title').style.opacity = 1;
}
}, 10);
window.addEventListener('scroll',function(event){
if(mui.os.android){
var t = document.body.scrollTop;
var height = background.offsetHeight - 74;
if(t>=0 && t<height * 0.1){
header.style.background = "rgba(61,171,201,0)";
document.getElementById('nav_title').style.opacity = 0;
}
if(t>=height * 0.1 + 1 && t<height * 0.2){
header.style.background = "rgba(61,171,201,0.1)";
document.getElementById('nav_title').style.opacity = 0;
}
if(t>=height * 0.2 + 1 && t<height * 0.3){
header.style.background = "rgba(61,171,201,0.2)";
document.getElementById('nav_title').style.opacity = 0;
}
if(t>=height * 0.3 + 1 && t<height * 0.4){
header.style.background = "rgba(61,171,201,0.3)";
document.getElementById('nav_title').style.opacity = 0;
}
if(t>=height * 0.4 + 1 && t<height * 0.5){
header.style.background = "rgba(61,171,201,0.4)";
document.getElementById('nav_title').style.opacity = 0;
}
if(t>=height * 0.5 + 1 && t<height * 0.6){
header.style.background = "rgba(61,171,201,0.5)";
document.getElementById('nav_title').style.opacity = 0;
}
if(t>=height * 0.6 + 1 && t<height * 0.7){
header.style.background = "rgba(61,171,201,0.6)";
document.getElementById('nav_title').style.opacity = 0;
}
if(t>=height * 0.7 + 1 && t<height * 0.8){
header.style.background = "rgba(61,171,201,0.7)";
document.getElementById('nav_title').style.opacity = 0;
}
if(t>=height * 0.8 + 1 && t<height * 0.9){
header.style.background = "rgba(61,171,201,0.8)";
document.getElementById('nav_title').style.opacity = 0;
}
if(t>=height * 0.9 + 1 && t<height * 1){
header.style.background = "rgba(61,171,201,0.9)";
document.getElementById('nav_title').style.opacity = 0;
}
if(t>=height){
header.style.background = "rgba(61,171,201,1)";
header.style.boxShadow = "0 0 1px rgba(0, 0, 0, .85);";
document.getElementById('nav_title').style.opacity = 1;
}
}
},false);
</script>
</html>