-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsecfunc.html
376 lines (366 loc) · 16.8 KB
/
secfunc.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
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Security and Internet Functions — Ring 1.0 documentation</title>
<link rel="stylesheet" href="_static/classic.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '1.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<link rel="top" title="Ring 1.0 documentation" href="index.html" />
<link rel="next" title="Object Oriented Programming (OOP)" href="oop.html" />
<link rel="prev" title="MySQL Functions" href="mysql.html" />
</head>
<body role="document">
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="oop.html" title="Object Oriented Programming (OOP)"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="mysql.html" title="MySQL Functions"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Ring 1.0 documentation</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="security-and-internet-functions">
<h1>Security and Internet Functions<a class="headerlink" href="#security-and-internet-functions" title="Permalink to this headline">¶</a></h1>
<p>This chapter contains the security and internet functions provided by the Ring programming language
for Hashing, Encryption & Decryption.</p>
<ul class="simple">
<li>MD5()</li>
<li>SHA1()</li>
<li>SHA256()</li>
<li>SHA512()</li>
<li>SHA384()</li>
<li>SHA224()</li>
<li>Encrypt()</li>
<li>Decrypt()</li>
<li>Randbytes()</li>
<li>Download()</li>
<li>SendEmail()</li>
</ul>
<div class="section" id="md5-function">
<h2>MD5() Function<a class="headerlink" href="#md5-function" title="Permalink to this headline">¶</a></h2>
<p>We can calculate the MD5 hash using the MD5() Function</p>
<p>Syntax:</p>
<div class="highlight-none"><div class="highlight"><pre>MD5(cString) ---> String contains the MD5 hash of the string cString
</pre></div>
</div>
<p>Example:</p>
<div class="highlight-none"><div class="highlight"><pre>see "md5('happy') = " + md5("happy") + nl +
"md5('Hello') = " + md5("Hello") + nl
</pre></div>
</div>
<p>Output:</p>
<div class="highlight-none"><div class="highlight"><pre>md5('happy') = 56ab24c15b72a457069c5ea42fcfc640
md5('Hello') = 8b1a9953c4611296a827abf8c47804d7
</pre></div>
</div>
</div>
<div class="section" id="sha1-function">
<h2>SHA1() Function<a class="headerlink" href="#sha1-function" title="Permalink to this headline">¶</a></h2>
<p>We can calculate the SHA1 hash using the SHA1() Function</p>
<p>Syntax:</p>
<div class="highlight-none"><div class="highlight"><pre>SHA1(cString) ---> String contains the SHA1 hash of the string cString
</pre></div>
</div>
<p>Example:</p>
<div class="highlight-none"><div class="highlight"><pre>see "sha1('hello') : " + sha1("hello") + nl +
"sha1('apple') : " + sha1("apple") + nl
</pre></div>
</div>
<p>Output:</p>
<div class="highlight-none"><div class="highlight"><pre>sha1('hello') : aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d
sha1('apple') : d0be2dc421be4fcd0172e5afceea3970e2f3d940
</pre></div>
</div>
</div>
<div class="section" id="sha256-function">
<h2>SHA256() Function<a class="headerlink" href="#sha256-function" title="Permalink to this headline">¶</a></h2>
<p>We can calculate the SHA256 hash using the SHA256() Function</p>
<p>Syntax:</p>
<div class="highlight-none"><div class="highlight"><pre>SHA256(cString) ---> String contains the SHA256 hash of the string cString
</pre></div>
</div>
<p>Example:</p>
<div class="highlight-none"><div class="highlight"><pre>see "sha256('hello') : " + sha256("hello") + nl +
"sha256('apple') : " + sha256("apple") + nl
</pre></div>
</div>
<p>Output:</p>
<div class="highlight-none"><div class="highlight"><pre>sha256('hello') : 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
sha256('apple') : 3a7bd3e2360a3d29eea436fcfb7e44c735d117c42d1c1835420b6b9942dd4f1b
</pre></div>
</div>
</div>
<div class="section" id="sha512-function">
<h2>SHA512() Function<a class="headerlink" href="#sha512-function" title="Permalink to this headline">¶</a></h2>
<p>We can calculate the SHA512 hash using the SHA512() Function</p>
<p>Syntax:</p>
<div class="highlight-none"><div class="highlight"><pre>SHA512(cString) ---> String contains the SHA512 hash of the string cString
</pre></div>
</div>
<p>Example:</p>
<div class="highlight-none"><div class="highlight"><pre>see "sha512('hello') : " + sha512("hello") + nl +
"sha512('apple') : " + sha512("apple") + nl +
"sha512('hello world') : " + sha512("hello world") + nl
</pre></div>
</div>
<p>Output:</p>
<div class="highlight-none"><div class="highlight"><pre>sha512('hello') : 9b71d224bd62f3785d96d46ad3ea3d73319bfbc2890caadae2dff72519673c
a72323c3d99ba5c11d7c7acc6e14b8c5da0c4663475c2e5c3adef46f73bcdec043
sha512('apple') : 844d8779103b94c18f4aa4cc0c3b4474058580a991fba85d3ca698a0bc9e52
c5940feb7a65a3a290e17e6b23ee943ecc4f73e7490327245b4fe5d5efb590feb2
sha512('hello world') : 309ecc489c12d6eb4cc40f50c902f2b4d0ed77ee511a7c7a9bcd3ca8
6d4cd86f989dd35bc5ff499670da34255b45b0cfd830e81f605dcf7dc5542e93ae9cd76f
</pre></div>
</div>
</div>
<div class="section" id="sha384-function">
<h2>SHA384() Function<a class="headerlink" href="#sha384-function" title="Permalink to this headline">¶</a></h2>
<p>We can calculate the SHA384 hash using the SHA384() Function</p>
<p>Syntax:</p>
<div class="highlight-none"><div class="highlight"><pre>SHA384(cString) ---> String contains the SHA384 hash of the string cString
</pre></div>
</div>
<p>Example:</p>
<div class="highlight-none"><div class="highlight"><pre>see "sha384('hello') : " + sha384("hello") + nl +
"sha384('apple') : " + sha384("apple") + nl +
"sha384('hello world') : " + sha384("hello world") + nl
</pre></div>
</div>
<p>Output:</p>
<div class="highlight-none"><div class="highlight"><pre>sha384('hello') : 59e1748777448c69de6b800d7a33bbfb9ff1b463e44354c3553bcdb9c666fa
90125a3c79f90397bdf5f6a13de828684f
sha384('apple') : 3d8786fcb588c93348756c6429717dc6c374a14f7029362281a3b21dc10250
ddf0d0578052749822eb08bc0dc1e68b0f
sha384('hello world') : fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcb
b83578b3e417cb71ce646efd0819dd8c088de1bd
</pre></div>
</div>
</div>
<div class="section" id="sha224-function">
<h2>SHA224() Function<a class="headerlink" href="#sha224-function" title="Permalink to this headline">¶</a></h2>
<p>We can calculate the SHA224 hash using the SHA224() Function</p>
<p>Syntax:</p>
<div class="highlight-none"><div class="highlight"><pre>SHA224(cString) ---> String contains the SHA224 hash of the string cString
</pre></div>
</div>
<p>Example:</p>
<div class="highlight-none"><div class="highlight"><pre>see "sha224('hello') : " + sha224("hello") + nl +
"sha224('apple') : " + sha224("apple") + nl +
"sha224('hello world') : " + sha224("hello world") + nl
</pre></div>
</div>
<p>Output:</p>
<div class="highlight-none"><div class="highlight"><pre>sha224('hello') : ea09ae9cc6768c50fcee903ed054556e5bfc8347907f12598aa24193
sha224('apple') : b7bbfdf1a1012999b3c466fdeb906a629caa5e3e022428d1eb702281
sha224('hello world') : 2f05477fc24bb4faefd86517156dafdecec45b8ad3cf2522a563582b
</pre></div>
</div>
</div>
<div class="section" id="encrypt-function">
<h2>Encrypt() Function<a class="headerlink" href="#encrypt-function" title="Permalink to this headline">¶</a></h2>
<p>We can use the Encrypt() function to encrypts the data using the Blowfish algorithm.</p>
<p>Syntax:</p>
<div class="highlight-none"><div class="highlight"><pre>Encrypt(cString, cKey, cIV) ---> Encrypted string
</pre></div>
</div>
</div>
<div class="section" id="decrypt-function">
<h2>Decrypt() Function<a class="headerlink" href="#decrypt-function" title="Permalink to this headline">¶</a></h2>
<p>We can use the Decrypt() function to decrypt the data encrypted using the Encrypt() function.</p>
<p>Syntax:</p>
<div class="highlight-none"><div class="highlight"><pre>Decrypt(cCipher, cKey, cIV) ---> Decrypted string
</pre></div>
</div>
</div>
<div class="section" id="encryption-and-decryption-example">
<h2>Encryption and Decryption Example<a class="headerlink" href="#encryption-and-decryption-example" title="Permalink to this headline">¶</a></h2>
<p>The next example demonstrates how to use the Encrypt() and Decrypt() functions.</p>
<p>These functions use the Blowfish algorithm.</p>
<div class="highlight-none"><div class="highlight"><pre>See "Enter a string : " give cStr
list = 0:15 cKey="" for x in list cKey += char(x) next
list = 1:8 cIV = "" for x in list cIV += char(x) next
cStr = Encrypt(cStr,cKey,cIV)
See "Cipher Text : " + cStr + nl +
"Plain Text : " + Decrypt(cStr,cKey,cIV) + nl
</pre></div>
</div>
</div>
<div class="section" id="file-hash">
<h2>File Hash<a class="headerlink" href="#file-hash" title="Permalink to this headline">¶</a></h2>
<p>The next example demonstrates how to calculate the hash functions for files</p>
<div class="highlight-none"><div class="highlight"><pre>cStr = read("myapp.exe")
see "Size : " + len(cStr) + nl +
"md5 : " + md5(cStr) + nl +
"sha1 : " + sha1(cStr) + nl +
"sha256 : " + sha256(cStr) + nl +
"sha224 : " + sha224(cStr) + nl +
"sha384 : " + sha384(cStr) + nl +
"sha512 : " + sha512(cStr) + nl
</pre></div>
</div>
<p>Output:</p>
<div class="highlight-none"><div class="highlight"><pre>Size : 58079876
md5 : 762eee15d8d2fd73b71ea52538b28667
sha1 : 9212c0c7258bad89a62bd239e1358a9276a9d070
sha256 : 7d6724e69b6c553da749ba31b6185dddc965129b64d9e9bf3de88f67df3b1cdc
sha224 : 5a9c8a7d662bce4f880ba94f90a79362b672528b9efd5abc718c7a3d
sha384 : 18e23f973abedbeb3981c423f12aeadecf96f9c6fb28aeabe3be4c484f8540afcc3861b
b370ce2b59cf3c99c130b856b
sha512 : da3d5e997d06f8b2a7a9964b77f7d82eedb76b245c611082c1639f83f51d83880bcd08f
cd53dcab1167bdca0b82fec5071971ac17c76479d76985ced4ab0d18e
</pre></div>
</div>
</div>
<div class="section" id="randbytes-function">
<h2>Randbytes() Function<a class="headerlink" href="#randbytes-function" title="Permalink to this headline">¶</a></h2>
<p>We can generate a string of pseudo-random bytes using the Randbytes() function.</p>
<p>Syntax:</p>
<div class="highlight-none"><div class="highlight"><pre>Randbytes(nSize) ---> String contains random bytes (bytes count = nSize)
</pre></div>
</div>
<p>Example:</p>
<div class="highlight-none"><div class="highlight"><pre>salt = randbytes(32)
password = "SecretPassWord@$%123"
see salt + nl
see sha256("test" + salt) + nl
</pre></div>
</div>
</div>
<div class="section" id="download-function">
<h2>Download() Function<a class="headerlink" href="#download-function" title="Permalink to this headline">¶</a></h2>
<p>Syntax:</p>
<div class="highlight-none"><div class="highlight"><pre>Download(cURL) ---> String contains the server response
</pre></div>
</div>
<p>Example:</p>
<div class="highlight-none"><div class="highlight"><pre>cStr= download("http://doublesvsoop.sourceforge.net/")
see cStr
write("download.txt",cStr)
</pre></div>
</div>
</div>
<div class="section" id="sendemail-function">
<h2>SendEmail() Function<a class="headerlink" href="#sendemail-function" title="Permalink to this headline">¶</a></h2>
<p>Syntax:</p>
<div class="highlight-none"><div class="highlight"><pre>SendEmail(cSMTPServer,cEmail,cPassword,cSender,cReceiver,cCC,cTitle,cContent)
</pre></div>
</div>
<p>Example:</p>
<div class="highlight-none"><div class="highlight"><pre>See "Send email..." + nl
sendemail("smtp://smtp.gmail.com:587",
"email@gmail.com",
"password",
"email@gmail.com",
"somebody@yahoo.com",
"somebodyelse@yahoo.com",
"Sending email from Ring",
"Hello
How are you?
Are you fine?
Thank you!
Greetings,
Mahmoud")
see "Done.." + nl
</pre></div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Security and Internet Functions</a><ul>
<li><a class="reference internal" href="#md5-function">MD5() Function</a></li>
<li><a class="reference internal" href="#sha1-function">SHA1() Function</a></li>
<li><a class="reference internal" href="#sha256-function">SHA256() Function</a></li>
<li><a class="reference internal" href="#sha512-function">SHA512() Function</a></li>
<li><a class="reference internal" href="#sha384-function">SHA384() Function</a></li>
<li><a class="reference internal" href="#sha224-function">SHA224() Function</a></li>
<li><a class="reference internal" href="#encrypt-function">Encrypt() Function</a></li>
<li><a class="reference internal" href="#decrypt-function">Decrypt() Function</a></li>
<li><a class="reference internal" href="#encryption-and-decryption-example">Encryption and Decryption Example</a></li>
<li><a class="reference internal" href="#file-hash">File Hash</a></li>
<li><a class="reference internal" href="#randbytes-function">Randbytes() Function</a></li>
<li><a class="reference internal" href="#download-function">Download() Function</a></li>
<li><a class="reference internal" href="#sendemail-function">SendEmail() Function</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="mysql.html"
title="previous chapter">MySQL Functions</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="oop.html"
title="next chapter">Object Oriented Programming (OOP)</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/secfunc.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="oop.html" title="Object Oriented Programming (OOP)"
>next</a> |</li>
<li class="right" >
<a href="mysql.html" title="MySQL Functions"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Ring 1.0 documentation</a> »</li>
</ul>
</div>
<div class="footer" role="contentinfo">
© Copyright 2016, Mahmoud Samir Fayed.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.1.
</div>
</body>
</html>