forked from Projjol-zz/dormammu.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.xml
More file actions
274 lines (181 loc) · 14.1 KB
/
index.xml
File metadata and controls
274 lines (181 loc) · 14.1 KB
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title> on Macrocosm </title>
<link>http://blog.projjol.me/index.xml</link>
<language>en-us</language>
<author>Alexander Ivanov</author>
<updated>2017-01-11 16:14:32 +0530 IST</updated>
<item>
<title>Getting started in Vim-Land</title>
<link>http://blog.projjol.me/post/getting-started-in-vimland/</link>
<pubDate>Wed, 11 Jan 2017 16:14:32 IST</pubDate>
<author>Alexander Ivanov</author>
<guid>http://blog.projjol.me/post/getting-started-in-vimland/</guid>
<description>
<h2 id="the-very-slow-move-to-vim">The (very) slow move to Vim</h2>
<p style="text-align: center;"><img src="../../img/vim-lotr.jpeg" alt="Vim 101"></p>
<p>Over many years I&rsquo;ve heard of the myth of the genius programmer (MotGP) who commands bits to move at his/her will using only Vim/Emacs(now, now don&rsquo;t start a flame war) as the weapon of their choice. I used vim for the first time in college. I don&rsquo;t remember the details but I was basically in an environment that did not support any graphical text editors. The two options I had were Vim and Nano. I decided to give things a shot with Vim but it went pretty terribly, I had no idea about how to use it and eventually skipped over to Nano, which I was familiar with.</p>
<p>Skip forward two years and the situation is slightly different. I can do meagre editing jobs on the terminal using vi. I&rsquo;m aware of the very least, :i, :q, :wq, :q! and that&rsquo;s when I was re-introduced to the MotGP and I was genuinely interested. This post will serve as a personal cheat-sheet, I&rsquo;ll keep updating it as and when I learn more of vim-foo. The approach I&rsquo;m taking is rather non-radical. I have not given up on Sublime Text, which is my TE of choice. For smaller/non-regular/non-mission-critical tasks such as writing this blog, I&rsquo;m going to do it in Vim. Shortcuts that I&rsquo;m gonna learn/add here will be those that I use regularly while editing text in Sublime.</p>
<h2 id="vim-foo">Vim-foo</h2>
<pre><code>:wq = Write to file and quit Vim
:q = Save file and quit Vim [works only if you haven't edited the file]
:q! = Don't save changes and quit Vim
:help = Find Vim help
i = Insert mode
a = Append text after cursor
A = Append text at the end-of-line [think cmd+right arrow]
$ = Go to end of line [does not bring up insert mode]
gg = Go to beginning of file
G = Go to end of file
b = Go back one word at a time
w = Go forward one word at a time
</code></pre>
<h2 id="vim-rc-so-far">vim.rc [so far]</h2>
<pre><code>set autoindent
set softtabstop=4
set expandtab
set shiftwidth=4
</code></pre>
<p><em>autoindent</em> = copies indent from the previous line</p>
<p><em>softtabstop</em> = amount of space a <TAB> key adds</p>
<p><em>expandtab</em> = Fills space added by a <TAB> key with spaces and not \t</p>
<p><em>shiftwidth</em> = number of spaces for indent, useful when using cindent</p>
</description>
</item>
<item>
<title>Understanding RSA</title>
<link>http://blog.projjol.me/post/understanding-RSA/</link>
<pubDate>Thu, 24 Nov 2016 12:09:47 IST</pubDate>
<author>Alexander Ivanov</author>
<guid>http://blog.projjol.me/post/understanding-RSA/</guid>
<description>
<h1 id="what-is-public-key-cryptography">What is Public Key Cryptography?</h1>
<p>Public Key Cryptography (AKA asymmetric cryptography) is a <a href="https://en.wikipedia.org/wiki/Cryptosystem">cryptosystem</a> which consists of a pair of keys, i.e public and private.
The public key can be widely disseminated whilst the private key should be known to the owner only. Public Key Cryptography(PKC from hereonforth) is also known as asymmetric cryptography because the public and private keys are different from each other and do not match.
With PKC, to send a message to the recipient of the private key, one merely requires the public key. The public key can be used to sign and encrypt a message which can only be decrypted by the owner of the corresponding private key.
The strength of a PKC cryptosystem depends on how hard it is to determine the private key by working backwards from the public key.</p>
<h1 id="what-is-rsa">What is RSA?</h1>
<p>The RSA cryptosystem is named after it&rsquo;s creators <em>Rivest</em>, <em>Shamir</em> &amp; <em>Adleman</em> and is one of the first implementations of a PKC cryptosystem.</p>
<p>It has 4 steps:</p>
<ul>
<li>Key generation</li>
<li>Key distribution</li>
<li>Encryption</li>
<li>Decryption</li>
</ul>
<p>Let&rsquo;s start with <strong>Key Generation</strong></p>
<h1 id="key-generation">Key Generation</h1>
<p>Take two prime numbers (in proper implementations, large prime numbers are chosen, however for the sake of this post we&rsquo;ll choose smaller, easier to follow primes). Let <em>p</em> &amp; q be the prime numbers in question. A third number <em>n</em> is a product of the chosen primes.</p>
<pre><code>n = p*q
</code></pre>
<p><em>n</em> is considered a modulus. Modulo arithmetic is used to calculate the remainder of a division operation. The idea behind using modulo is to find numbers in the same group, i.e</p>
<pre><code>3 mod 7 = 3
10 mod 7 = 3
</code></pre>
<p>This relationship can also be expressed as <code>10 ≡ 3 mod 7</code>, where &lsquo;≡&rsquo; is to represent congruence. In simpler terms, <code>10 ≡ 3 mod 7</code> is a shorter way of expressing <code>10 mod 7 = 3 mod 7</code>
Therefore, 3 and 10 are a part of the group where the remainder is 3. <strong>Why this is important, I&rsquo;ll show later.</strong>
While we&rsquo;re still on key generation it&rsquo;ll be a good idea to check out Euler’s totient formula</p>
<h1 id="euler-s-totient">Euler’s Totient</h1>
<p>Euler’s totient, represented as φ, is a function on a number that returns the number of positive integers upto the number itself that are co-prime to it.</p>
<p>Lolwat. Let&rsquo;s break this down. Firstly, what&rsquo;s co-prime? Any two numbers whose <a href="https://www.khanacademy.org/math/pre-algebra/pre-algebra-factors-multiples/pre-algebra-greatest-common-divisor/v/greatest-common-divisor">GCD</a> is 1 are considered to be co-prime to each other. So φ(n) finds all the numbers from 1 to <em>n</em>-1 that are co-prime to n. An example of this would be:</p>
<pre><code>φ(5) = 1,2,3,4 [here 1,2,3,4 have a GCD of 1 with 5]
φ(6) = 1,5
</code></pre>
<p>Euler’s totient has the property of being commutative i.e :</p>
<pre><code>φ(n) = φ(p)*φ(q)
</code></pre>
<p>This property will be of use once we re-vist the Key Generation process.</p>
<h1 id="key-generation-contd">Key Generation (contd.)</h1>
<p>So, till this point we have calculated <em>n</em>, which is the product of two random prime numbers that we have selected. As mentioned earlier, <em>n</em> is the modulus and is used to determine the length of the the public and private keys. This can be determined from the fact that the length of <em>n</em> in bits is the length of the key itself. So for example someone uses a 1024 bit RSA key, the value of <em>n</em> would be in the range of <em>0-2^1023</em>.
Euler’s totient that we saw in the previous section comes of use now, especially the commutative property:</p>
<pre><code> φ(n) = φ(p)*φ(q) = (p − 1)(q − 1) = n − (p + q − 1)
</code></pre>
<p>For prime numbers φ(n) is 1-(<em>n</em>-1), check φ(5) above.</p>
<p>Considering <em>p</em> &amp; <em>q</em> to be 7 &amp; 13, <em>n</em> = 91</p>
<p>Therefore, φ(<em>n</em>) = 91 - (7 + 13 - 1) = 72</p>
<p>This value calculated for Euler&rsquo;s totient is kept a secret.</p>
<p>Now, an integer <em>e</em> needs to be obtained such that 1 &lt; <em>e</em> &lt; φ(<em>n</em>) and gcd(<em>e</em>, φ(<em>n</em>)) =1, i.e <em>e</em> &amp; φ(<em>n</em>) are coprime.
Let,</p>
<pre><code>e = 11
</code></pre>
<p>Next step is to compute the modular multiplicative inverse of e.</p>
<p>Lolwat?</p>
<h1 id="modular-multiplicative-inverse">Modular Multiplicative Inverse</h1>
<p>Let’s say we have a number <em>n</em>. The multiplicative inverse of <em>n</em> would be <em>n</em>^-1, such that <em>n</em><em><em>n</em>^-1 = 1
In modular mathematics, the modular inverse of <em>n</em>(mod <em>c</em>) is <em>n</em>^-1 for some number <em>c</em>. What we&rsquo;re looking for is a number x such that <em>n</em></em><em>x</em> mod <em>c</em> = 1
Therefore,</p>
<pre><code>n * x(mod c) = 1
</code></pre>
<p>All of this is fine, but how do we calculate how to actually calculate the modular inverse?</p>
<p>Here&rsquo;s the long method:</p>
<ul>
<li>Calculate <em>n</em> * <em>x</em> ( x has values from 0- <em>c</em>-1)</li>
<li>Modular inverse is the value of <em>x</em> where <em>n</em>*<em>x</em> mod <em>c</em> = 1</li>
</ul>
<p>Let n = 4, c = 7,</p>
<p>Values of x = {0,1,2,3,4,5,6}</p>
<ul>
<li>4 * 0 ≡ 0 ≡ 0 (mod 7)</li>
<li>4 * 1 ≡ 4 ≡ 4 (mod 7)</li>
<li>4 * 2 ≡ 8 ≡ 1 (mod 7) —&gt; bingo</li>
</ul>
<p>Let&rsquo;s see it in isolation:</p>
<pre><code>4(n) * 2(x) mod 7( c ) = 1 [This satisfies the condition we were looking for]
</code></pre>
<p>Note that this is a slow method to calculate the modular inverse of a number and using the <a href="https://www.math.utah.edu/~fguevara/ACCESS2013/Euclid.pdf">Extended Euclidean Algorithm</a>, better performance can be achieved.</p>
<h1 id="key-generation-contd-1">Key Generation (contd.)</h1>
<p>Alright, so we have,</p>
<pre><code>e = 11, φ(n) = 72,
</code></pre>
<p>And we need to calculate their modular multiplicative inverse such that:</p>
<pre><code>e*d mod φ(n) = 1 mod φ(n)
</code></pre>
<p>Let’s find the value of d!</p>
<ul>
<li>11 * 0 ≡ 0 ≡ 0 (mod 72)</li>
<li>11 * 1 ≡ 11 ≡ 11 (mod 72)</li>
<li>11 * 2 ≡ 22 ≡ 22 (mod 72)</li>
<li>&hellip;&hellip;..</li>
<li>11 * 59 ≡ 649 ≡ 1 (mod 72) —&gt; gotcha</li>
</ul>
<p>Therefore,</p>
<pre><code>d = 59
</code></pre>
<p>With this computation done, the public key is made with the values in <em>n</em> and <em>e</em> and the private key is made using values in <em>n</em> and <em>d</em>.</p>
<p>One question does arise though, why did we calculate the modular inverse of <em>e</em> ? Consider the following:</p>
<pre><code>E(M) = M^e mod n
C ≡ M^e mod n
D(C) = C^d mod n
C^d ≡ (M^e)^d mod n
C^d ≡ (M^(e*d)) mod n
e*d ≡ 1 mod n
e*d ≡ kϕ(n)+1
=&gt; D(C) = M^(kϕ(n)+1) mod n
=&gt; D(C) = M * (M^ϕ(n))^k
=&gt; D(C) = M * (1 mod n)^k
=&gt; D(C) = M * 1^k
=&gt; D(C) = M [original message]
</code></pre>
<p>By finding the inverse of e, we find the value which when the message is raised to gives back the original message, thereby acheiving a working public-private key cryptosystem.</p>
<h1 id="simple-example">Simple Example</h1>
<pre><code>e = 11
d = 59
n = 91
</code></pre>
<p>Let the message be <em>9</em></p>
<p>Encryption:</p>
<pre><code>E(M) = M^e mod n
=&gt; 9^11 mod 91
=&gt; 81
D(C) = C^d mod n
=&gt; 81^59 mod 91
=&gt; 9 [the original message]
</code></pre>
<h1 id="errata">Errata</h1>
<p>The idea behind the public key is to have a prime number between 3 and φ(n). Normally, values behind public key cryptography involves large numbers (if you remember, the size of the key could be as high as 2^1023 or 2^2023 but we’re mostly pushing it at key lengths above 2024 bits), so popular implementations set it as <a href="http://crypto.stackexchange.com/questions/3110/impacts-of-not-using-rsa-exponent-of-65537">65537</a> as a good tradeoff between sufficiently high and being a decent enough cost to raise a number to.
A good point that might be made is whether or not the fact that everyone knows if 65537 is a public key exponent. This is the public key that is being shared with people anyway and as long as one cannot deduce the private key from it, there should not be a problem.</p>
</description>
</item>
</channel>
</rss>