mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-03-25 22:32:24 +08:00
Documentation for 53a6c16730
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
|
||||
<meta name="generator" content="Doxygen 1.9.2"/>
|
||||
<meta name="generator" content="Doxygen 1.9.3"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
<title>Algorithms_in_C++: ciphers/hill_cipher.cpp File Reference</title>
|
||||
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
|
||||
@@ -30,8 +30,8 @@ MathJax.Hub.Config({
|
||||
<div id="titlearea">
|
||||
<table cellspacing="0" cellpadding="0">
|
||||
<tbody>
|
||||
<tr style="height: 56px;">
|
||||
<td id="projectalign" style="padding-left: 0.5em;">
|
||||
<tr id="projectrow">
|
||||
<td id="projectalign">
|
||||
<div id="projectname">Algorithms_in_C++<span id="projectnumber"> 1.0.0</span>
|
||||
</div>
|
||||
<div id="projectbrief">Set of algorithms implemented in C++.</div>
|
||||
@@ -41,7 +41,7 @@ MathJax.Hub.Config({
|
||||
</table>
|
||||
</div>
|
||||
<!-- end header part -->
|
||||
<!-- Generated by Doxygen 1.9.2 -->
|
||||
<!-- Generated by Doxygen 1.9.3 -->
|
||||
<script type="text/javascript">
|
||||
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
||||
var searchBox = new SearchBox("searchBox", "../../search",'Search','.html');
|
||||
@@ -177,18 +177,18 @@ The matrix generation algorithm is very rudimentary and does not guarantee an in
|
||||
</table>
|
||||
</div><div class="memdoc">
|
||||
<p >Main function </p>
|
||||
<div class="fragment"><div class="line"><a id="l00532" name="l00532"></a><span class="lineno"> 532</span> {</div>
|
||||
<div class="line"><a id="l00533" name="l00533"></a><span class="lineno"> 533</span> <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/random/srand.html">std::srand</a>(<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/chrono/c/time.html">std::time</a>(<span class="keyword">nullptr</span>));</div>
|
||||
<div class="line"><a id="l00534" name="l00534"></a><span class="lineno"> 534</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"Key dictionary: ("</span> << <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/byte/strlen.html">std::strlen</a>(<a class="code hl_variable" href="../../d6/d4e/namespaceciphers.html#ab9aec0ccf4b6809f652bb540be87c216">ciphers::STRKEY</a>) << <span class="stringliteral">")\n\t"</span></div>
|
||||
<div class="line"><a id="l00535" name="l00535"></a><span class="lineno"> 535</span> << <a class="code hl_variable" href="../../d6/d4e/namespaceciphers.html#ab9aec0ccf4b6809f652bb540be87c216">ciphers::STRKEY</a> << <span class="stringliteral">"\n"</span>;</div>
|
||||
<div class="line"><a id="l00536" name="l00536"></a><span class="lineno"> 536</span> </div>
|
||||
<div class="line"><a id="l00537" name="l00537"></a><span class="lineno"> 537</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a> text = <span class="stringliteral">"This is a simple text with numb3r5 and exclamat!0n."</span>;</div>
|
||||
<div class="line"><a id="l00538" name="l00538"></a><span class="lineno"> 538</span> </div>
|
||||
<div class="line"><a id="l00539" name="l00539"></a><span class="lineno"> 539</span> <a class="code hl_function" href="../../d7/db9/hill__cipher_8cpp.html#a3147ad576f8a94a2a6b66948672b452b">test1</a>(text);</div>
|
||||
<div class="line"><a id="l00540" name="l00540"></a><span class="lineno"> 540</span> <a class="code hl_function" href="../../d7/db9/hill__cipher_8cpp.html#a04391124480d2a49f2dec900237b0712">test2</a>(text);</div>
|
||||
<div class="line"><a id="l00541" name="l00541"></a><span class="lineno"> 541</span> </div>
|
||||
<div class="line"><a id="l00542" name="l00542"></a><span class="lineno"> 542</span> <span class="keywordflow">return</span> 0;</div>
|
||||
<div class="line"><a id="l00543" name="l00543"></a><span class="lineno"> 543</span>}</div>
|
||||
<div class="fragment"><div class="line"><span class="lineno"> 532</span> {</div>
|
||||
<div class="line"><span class="lineno"> 533</span> <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/random/srand.html">std::srand</a>(<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/chrono/c/time.html">std::time</a>(<span class="keyword">nullptr</span>));</div>
|
||||
<div class="line"><span class="lineno"> 534</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"Key dictionary: ("</span> << <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/byte/strlen.html">std::strlen</a>(<a class="code hl_variable" href="../../d6/d4e/namespaceciphers.html#ab9aec0ccf4b6809f652bb540be87c216">ciphers::STRKEY</a>) << <span class="stringliteral">")\n\t"</span></div>
|
||||
<div class="line"><span class="lineno"> 535</span> << <a class="code hl_variable" href="../../d6/d4e/namespaceciphers.html#ab9aec0ccf4b6809f652bb540be87c216">ciphers::STRKEY</a> << <span class="stringliteral">"\n"</span>;</div>
|
||||
<div class="line"><span class="lineno"> 536</span> </div>
|
||||
<div class="line"><span class="lineno"> 537</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a> text = <span class="stringliteral">"This is a simple text with numb3r5 and exclamat!0n."</span>;</div>
|
||||
<div class="line"><span class="lineno"> 538</span> </div>
|
||||
<div class="line"><span class="lineno"> 539</span> <a class="code hl_function" href="../../d7/db9/hill__cipher_8cpp.html#a3147ad576f8a94a2a6b66948672b452b">test1</a>(text);</div>
|
||||
<div class="line"><span class="lineno"> 540</span> <a class="code hl_function" href="../../d7/db9/hill__cipher_8cpp.html#a04391124480d2a49f2dec900237b0712">test2</a>(text);</div>
|
||||
<div class="line"><span class="lineno"> 541</span> </div>
|
||||
<div class="line"><span class="lineno"> 542</span> <span class="keywordflow">return</span> 0;</div>
|
||||
<div class="line"><span class="lineno"> 543</span>}</div>
|
||||
<div class="ttc" id="abasic_ostream_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a></div></div>
|
||||
<div class="ttc" id="abasic_string_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a></div></div>
|
||||
<div class="ttc" id="ahill__cipher_8cpp_html_a04391124480d2a49f2dec900237b0712"><div class="ttname"><a href="../../d7/db9/hill__cipher_8cpp.html#a04391124480d2a49f2dec900237b0712">test2</a></div><div class="ttdeci">void test2(const std::string &text)</div><div class="ttdoc">Self test 2 - using 8x8 randomly generated key.</div><div class="ttdef"><b>Definition:</b> hill_cipher.cpp:505</div></div>
|
||||
@@ -242,19 +242,19 @@ template<typename T > </div>
|
||||
</table>
|
||||
</div><div class="memdoc">
|
||||
<p >operator to print a matrix </p>
|
||||
<div class="fragment"><div class="line"><a id="l00054" name="l00054"></a><span class="lineno"> 54</span> {</div>
|
||||
<div class="line"><a id="l00055" name="l00055"></a><span class="lineno"> 55</span> <span class="keyword">const</span> <span class="keywordtype">int</span> width = 15;</div>
|
||||
<div class="line"><a id="l00056" name="l00056"></a><span class="lineno"> 56</span> <span class="keyword">const</span> <span class="keywordtype">char</span> separator = <span class="charliteral">' '</span>;</div>
|
||||
<div class="line"><a id="l00057" name="l00057"></a><span class="lineno"> 57</span> </div>
|
||||
<div class="line"><a id="l00058" name="l00058"></a><span class="lineno"> 58</span> <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> row = 0; row < v.<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector/size.html">size</a>(); row++) {</div>
|
||||
<div class="line"><a id="l00059" name="l00059"></a><span class="lineno"> 59</span> <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> col = 0; col < v[row].<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector/size.html">size</a>(); col++)</div>
|
||||
<div class="line"><a id="l00060" name="l00060"></a><span class="lineno"> 60</span> out << <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/left.html">std::left</a> << <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/setw.html">std::setw</a>(width) << <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/setfill.html">std::setfill</a>(separator)</div>
|
||||
<div class="line"><a id="l00061" name="l00061"></a><span class="lineno"> 61</span> << v[row][col];</div>
|
||||
<div class="line"><a id="l00062" name="l00062"></a><span class="lineno"> 62</span> out << <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
|
||||
<div class="line"><a id="l00063" name="l00063"></a><span class="lineno"> 63</span> }</div>
|
||||
<div class="line"><a id="l00064" name="l00064"></a><span class="lineno"> 64</span> </div>
|
||||
<div class="line"><a id="l00065" name="l00065"></a><span class="lineno"> 65</span> <span class="keywordflow">return</span> out;</div>
|
||||
<div class="line"><a id="l00066" name="l00066"></a><span class="lineno"> 66</span>}</div>
|
||||
<div class="fragment"><div class="line"><span class="lineno"> 54</span> {</div>
|
||||
<div class="line"><span class="lineno"> 55</span> <span class="keyword">const</span> <span class="keywordtype">int</span> width = 15;</div>
|
||||
<div class="line"><span class="lineno"> 56</span> <span class="keyword">const</span> <span class="keywordtype">char</span> separator = <span class="charliteral">' '</span>;</div>
|
||||
<div class="line"><span class="lineno"> 57</span> </div>
|
||||
<div class="line"><span class="lineno"> 58</span> <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> row = 0; row < v.<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector/size.html">size</a>(); row++) {</div>
|
||||
<div class="line"><span class="lineno"> 59</span> <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> col = 0; col < v[row].<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector/size.html">size</a>(); col++)</div>
|
||||
<div class="line"><span class="lineno"> 60</span> out << <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/left.html">std::left</a> << <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/setw.html">std::setw</a>(width) << <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/setfill.html">std::setfill</a>(separator)</div>
|
||||
<div class="line"><span class="lineno"> 61</span> << v[row][col];</div>
|
||||
<div class="line"><span class="lineno"> 62</span> out << <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
|
||||
<div class="line"><span class="lineno"> 63</span> }</div>
|
||||
<div class="line"><span class="lineno"> 64</span> </div>
|
||||
<div class="line"><span class="lineno"> 65</span> <span class="keywordflow">return</span> out;</div>
|
||||
<div class="line"><span class="lineno"> 66</span>}</div>
|
||||
<div class="ttc" id="aendl_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a></div><div class="ttdeci">T endl(T... args)</div></div>
|
||||
<div class="ttc" id="aleft_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/io/manip/left.html">std::left</a></div><div class="ttdeci">T left(T... args)</div></div>
|
||||
<div class="ttc" id="asetfill_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/io/manip/setfill.html">std::setfill</a></div><div class="ttdeci">T setfill(T... args)</div></div>
|
||||
@@ -292,35 +292,35 @@ Here is the call graph for this function:</div>
|
||||
</table>
|
||||
</dd>
|
||||
</dl>
|
||||
<div class="fragment"><div class="line"><a id="l00470" name="l00470"></a><span class="lineno"> 470</span> {</div>
|
||||
<div class="line"><a id="l00471" name="l00471"></a><span class="lineno"> 471</span> <span class="comment">// std::string text = "Hello world!";</span></div>
|
||||
<div class="line"><a id="l00472" name="l00472"></a><span class="lineno"> 472</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"======Test 1 (3x3 key) ======\nOriginal text:\n\t"</span> << text</div>
|
||||
<div class="line"><a id="l00473" name="l00473"></a><span class="lineno"> 473</span> << <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
|
||||
<div class="line"><a id="l00474" name="l00474"></a><span class="lineno"> 474</span> </div>
|
||||
<div class="line"><a id="l00475" name="l00475"></a><span class="lineno"> 475</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/utility/pair.html">std::pair<matrix<int></a>, <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">matrix<int></a>> p =</div>
|
||||
<div class="line"><a id="l00476" name="l00476"></a><span class="lineno"> 476</span> <a class="code hl_function" href="../../d6/d26/classciphers_1_1_hill_cipher.html#a405b0a28d66a61239d3565d5256f9cb5">ciphers::HillCipher::generate_keys</a>(3, 0, 100);</div>
|
||||
<div class="line"><a id="l00477" name="l00477"></a><span class="lineno"> 477</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">matrix<int></a> ekey = p.first;</div>
|
||||
<div class="line"><a id="l00478" name="l00478"></a><span class="lineno"> 478</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">matrix<int></a> dkey = p.second;</div>
|
||||
<div class="line"><a id="l00479" name="l00479"></a><span class="lineno"> 479</span> </div>
|
||||
<div class="line"><a id="l00480" name="l00480"></a><span class="lineno"> 480</span> <span class="comment">// matrix<int> ekey = {{22, 28, 25}, {5, 26, 15}, {14, 18, 9}};</span></div>
|
||||
<div class="line"><a id="l00481" name="l00481"></a><span class="lineno"> 481</span> <span class="comment">// std::cout << "Encryption key: \n" << ekey;</span></div>
|
||||
<div class="line"><a id="l00482" name="l00482"></a><span class="lineno"> 482</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a> gibberish = <a class="code hl_function" href="../../d6/d26/classciphers_1_1_hill_cipher.html#aa8bbb6e4a5749f6008b06602d5103917">ciphers::HillCipher::encrypt_text</a>(text, ekey);</div>
|
||||
<div class="line"><a id="l00483" name="l00483"></a><span class="lineno"> 483</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"Encrypted text:\n\t"</span> << gibberish << <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
|
||||
<div class="line"><a id="l00484" name="l00484"></a><span class="lineno"> 484</span> </div>
|
||||
<div class="line"><a id="l00485" name="l00485"></a><span class="lineno"> 485</span> <span class="comment">// matrix<int> dkey = ciphers::HillCipher::generate_decryption_key(ekey);</span></div>
|
||||
<div class="line"><a id="l00486" name="l00486"></a><span class="lineno"> 486</span> <span class="comment">// std::cout << "Decryption key: \n" << dkey;</span></div>
|
||||
<div class="line"><a id="l00487" name="l00487"></a><span class="lineno"> 487</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a> txt_back = <a class="code hl_function" href="../../d6/d26/classciphers_1_1_hill_cipher.html#a427acfac1dbff3f48a2b071d449d965b">ciphers::HillCipher::decrypt_text</a>(gibberish, dkey);</div>
|
||||
<div class="line"><a id="l00488" name="l00488"></a><span class="lineno"> 488</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"Reconstruct text:\n\t"</span> << txt_back << <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
|
||||
<div class="line"><a id="l00489" name="l00489"></a><span class="lineno"> 489</span> </div>
|
||||
<div class="line"><a id="l00490" name="l00490"></a><span class="lineno"> 490</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ofstream.html">std::ofstream</a> out_file(<span class="stringliteral">"hill_cipher_test1.txt"</span>);</div>
|
||||
<div class="line"><a id="l00491" name="l00491"></a><span class="lineno"> 491</span> out_file << <span class="stringliteral">"Block size: "</span> << ekey.<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector/size.html">size</a>() << <span class="stringliteral">"\n"</span>;</div>
|
||||
<div class="line"><a id="l00492" name="l00492"></a><span class="lineno"> 492</span> out_file << <span class="stringliteral">"Encryption Key:\n"</span> << ekey;</div>
|
||||
<div class="line"><a id="l00493" name="l00493"></a><span class="lineno"> 493</span> out_file << <span class="stringliteral">"\nDecryption Key:\n"</span> << dkey;</div>
|
||||
<div class="line"><a id="l00494" name="l00494"></a><span class="lineno"> 494</span> out_file.close();</div>
|
||||
<div class="line"><a id="l00495" name="l00495"></a><span class="lineno"> 495</span> </div>
|
||||
<div class="line"><a id="l00496" name="l00496"></a><span class="lineno"> 496</span> assert(txt_back == text);</div>
|
||||
<div class="line"><a id="l00497" name="l00497"></a><span class="lineno"> 497</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"Passed :)\n"</span>;</div>
|
||||
<div class="line"><a id="l00498" name="l00498"></a><span class="lineno"> 498</span>}</div>
|
||||
<div class="fragment"><div class="line"><span class="lineno"> 470</span> {</div>
|
||||
<div class="line"><span class="lineno"> 471</span> <span class="comment">// std::string text = "Hello world!";</span></div>
|
||||
<div class="line"><span class="lineno"> 472</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"======Test 1 (3x3 key) ======\nOriginal text:\n\t"</span> << text</div>
|
||||
<div class="line"><span class="lineno"> 473</span> << <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
|
||||
<div class="line"><span class="lineno"> 474</span> </div>
|
||||
<div class="line"><span class="lineno"> 475</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/utility/pair.html">std::pair<matrix<int></a>, <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">matrix<int></a>> p =</div>
|
||||
<div class="line"><span class="lineno"> 476</span> <a class="code hl_function" href="../../d6/d26/classciphers_1_1_hill_cipher.html#a405b0a28d66a61239d3565d5256f9cb5">ciphers::HillCipher::generate_keys</a>(3, 0, 100);</div>
|
||||
<div class="line"><span class="lineno"> 477</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">matrix<int></a> ekey = p.first;</div>
|
||||
<div class="line"><span class="lineno"> 478</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">matrix<int></a> dkey = p.second;</div>
|
||||
<div class="line"><span class="lineno"> 479</span> </div>
|
||||
<div class="line"><span class="lineno"> 480</span> <span class="comment">// matrix<int> ekey = {{22, 28, 25}, {5, 26, 15}, {14, 18, 9}};</span></div>
|
||||
<div class="line"><span class="lineno"> 481</span> <span class="comment">// std::cout << "Encryption key: \n" << ekey;</span></div>
|
||||
<div class="line"><span class="lineno"> 482</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a> gibberish = <a class="code hl_function" href="../../d6/d26/classciphers_1_1_hill_cipher.html#aa8bbb6e4a5749f6008b06602d5103917">ciphers::HillCipher::encrypt_text</a>(text, ekey);</div>
|
||||
<div class="line"><span class="lineno"> 483</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"Encrypted text:\n\t"</span> << gibberish << <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
|
||||
<div class="line"><span class="lineno"> 484</span> </div>
|
||||
<div class="line"><span class="lineno"> 485</span> <span class="comment">// matrix<int> dkey = ciphers::HillCipher::generate_decryption_key(ekey);</span></div>
|
||||
<div class="line"><span class="lineno"> 486</span> <span class="comment">// std::cout << "Decryption key: \n" << dkey;</span></div>
|
||||
<div class="line"><span class="lineno"> 487</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a> txt_back = <a class="code hl_function" href="../../d6/d26/classciphers_1_1_hill_cipher.html#a427acfac1dbff3f48a2b071d449d965b">ciphers::HillCipher::decrypt_text</a>(gibberish, dkey);</div>
|
||||
<div class="line"><span class="lineno"> 488</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"Reconstruct text:\n\t"</span> << txt_back << <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
|
||||
<div class="line"><span class="lineno"> 489</span> </div>
|
||||
<div class="line"><span class="lineno"> 490</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ofstream.html">std::ofstream</a> out_file(<span class="stringliteral">"hill_cipher_test1.txt"</span>);</div>
|
||||
<div class="line"><span class="lineno"> 491</span> out_file << <span class="stringliteral">"Block size: "</span> << ekey.<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector/size.html">size</a>() << <span class="stringliteral">"\n"</span>;</div>
|
||||
<div class="line"><span class="lineno"> 492</span> out_file << <span class="stringliteral">"Encryption Key:\n"</span> << ekey;</div>
|
||||
<div class="line"><span class="lineno"> 493</span> out_file << <span class="stringliteral">"\nDecryption Key:\n"</span> << dkey;</div>
|
||||
<div class="line"><span class="lineno"> 494</span> out_file.close();</div>
|
||||
<div class="line"><span class="lineno"> 495</span> </div>
|
||||
<div class="line"><span class="lineno"> 496</span> assert(txt_back == text);</div>
|
||||
<div class="line"><span class="lineno"> 497</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"Passed :)\n"</span>;</div>
|
||||
<div class="line"><span class="lineno"> 498</span>}</div>
|
||||
<div class="ttc" id="abasic_ofstream_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/io/basic_ofstream.html">std::ofstream</a></div></div>
|
||||
<div class="ttc" id="aclassciphers_1_1_hill_cipher_html_a405b0a28d66a61239d3565d5256f9cb5"><div class="ttname"><a href="../../d6/d26/classciphers_1_1_hill_cipher.html#a405b0a28d66a61239d3565d5256f9cb5">ciphers::HillCipher::generate_keys</a></div><div class="ttdeci">static std::pair< matrix< int >, matrix< int > > generate_keys(size_t size, int limit1=0, int limit2=10)</div><div class="ttdoc">Generate encryption and decryption key pair.</div><div class="ttdef"><b>Definition:</b> hill_cipher.cpp:424</div></div>
|
||||
<div class="ttc" id="aclassciphers_1_1_hill_cipher_html_a427acfac1dbff3f48a2b071d449d965b"><div class="ttname"><a href="../../d6/d26/classciphers_1_1_hill_cipher.html#a427acfac1dbff3f48a2b071d449d965b">ciphers::HillCipher::decrypt_text</a></div><div class="ttdeci">static const std::string decrypt_text(const std::string &text, const matrix< int > &decrypt_key)</div><div class="ttdoc">Decrypt a given text using a given key.</div><div class="ttdef"><b>Definition:</b> hill_cipher.cpp:457</div></div>
|
||||
@@ -359,31 +359,31 @@ Here is the call graph for this function:</div>
|
||||
</table>
|
||||
</dd>
|
||||
</dl>
|
||||
<div class="fragment"><div class="line"><a id="l00505" name="l00505"></a><span class="lineno"> 505</span> {</div>
|
||||
<div class="line"><a id="l00506" name="l00506"></a><span class="lineno"> 506</span> <span class="comment">// std::string text = "Hello world!";</span></div>
|
||||
<div class="line"><a id="l00507" name="l00507"></a><span class="lineno"> 507</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"======Test 2 (8x8 key) ======\nOriginal text:\n\t"</span> << text</div>
|
||||
<div class="line"><a id="l00508" name="l00508"></a><span class="lineno"> 508</span> << <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
|
||||
<div class="line"><a id="l00509" name="l00509"></a><span class="lineno"> 509</span> </div>
|
||||
<div class="line"><a id="l00510" name="l00510"></a><span class="lineno"> 510</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/utility/pair.html">std::pair<matrix<int></a>, <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">matrix<int></a>> p =</div>
|
||||
<div class="line"><a id="l00511" name="l00511"></a><span class="lineno"> 511</span> <a class="code hl_function" href="../../d6/d26/classciphers_1_1_hill_cipher.html#a405b0a28d66a61239d3565d5256f9cb5">ciphers::HillCipher::generate_keys</a>(8, 0, 3);</div>
|
||||
<div class="line"><a id="l00512" name="l00512"></a><span class="lineno"> 512</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">matrix<int></a> ekey = p.first;</div>
|
||||
<div class="line"><a id="l00513" name="l00513"></a><span class="lineno"> 513</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">matrix<int></a> dkey = p.second;</div>
|
||||
<div class="line"><a id="l00514" name="l00514"></a><span class="lineno"> 514</span> </div>
|
||||
<div class="line"><a id="l00515" name="l00515"></a><span class="lineno"> 515</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a> gibberish = <a class="code hl_function" href="../../d6/d26/classciphers_1_1_hill_cipher.html#aa8bbb6e4a5749f6008b06602d5103917">ciphers::HillCipher::encrypt_text</a>(text, ekey);</div>
|
||||
<div class="line"><a id="l00516" name="l00516"></a><span class="lineno"> 516</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"Encrypted text:\n\t"</span> << gibberish << <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
|
||||
<div class="line"><a id="l00517" name="l00517"></a><span class="lineno"> 517</span> </div>
|
||||
<div class="line"><a id="l00518" name="l00518"></a><span class="lineno"> 518</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a> txt_back = <a class="code hl_function" href="../../d6/d26/classciphers_1_1_hill_cipher.html#a427acfac1dbff3f48a2b071d449d965b">ciphers::HillCipher::decrypt_text</a>(gibberish, dkey);</div>
|
||||
<div class="line"><a id="l00519" name="l00519"></a><span class="lineno"> 519</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"Reconstruct text:\n\t"</span> << txt_back << <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
|
||||
<div class="line"><a id="l00520" name="l00520"></a><span class="lineno"> 520</span> </div>
|
||||
<div class="line"><a id="l00521" name="l00521"></a><span class="lineno"> 521</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ofstream.html">std::ofstream</a> out_file(<span class="stringliteral">"hill_cipher_test2.txt"</span>);</div>
|
||||
<div class="line"><a id="l00522" name="l00522"></a><span class="lineno"> 522</span> out_file << <span class="stringliteral">"Block size: "</span> << ekey.<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector/size.html">size</a>() << <span class="stringliteral">"\n"</span>;</div>
|
||||
<div class="line"><a id="l00523" name="l00523"></a><span class="lineno"> 523</span> out_file << <span class="stringliteral">"Encryption Key:\n"</span> << ekey;</div>
|
||||
<div class="line"><a id="l00524" name="l00524"></a><span class="lineno"> 524</span> out_file << <span class="stringliteral">"\nDecryption Key:\n"</span> << dkey;</div>
|
||||
<div class="line"><a id="l00525" name="l00525"></a><span class="lineno"> 525</span> out_file.close();</div>
|
||||
<div class="line"><a id="l00526" name="l00526"></a><span class="lineno"> 526</span> </div>
|
||||
<div class="line"><a id="l00527" name="l00527"></a><span class="lineno"> 527</span> assert(txt_back.<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string/compare.html">compare</a>(0, text.<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string/size.html">size</a>(), text) == 0);</div>
|
||||
<div class="line"><a id="l00528" name="l00528"></a><span class="lineno"> 528</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"Passed :)\n"</span>;</div>
|
||||
<div class="line"><a id="l00529" name="l00529"></a><span class="lineno"> 529</span>}</div>
|
||||
<div class="fragment"><div class="line"><span class="lineno"> 505</span> {</div>
|
||||
<div class="line"><span class="lineno"> 506</span> <span class="comment">// std::string text = "Hello world!";</span></div>
|
||||
<div class="line"><span class="lineno"> 507</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"======Test 2 (8x8 key) ======\nOriginal text:\n\t"</span> << text</div>
|
||||
<div class="line"><span class="lineno"> 508</span> << <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
|
||||
<div class="line"><span class="lineno"> 509</span> </div>
|
||||
<div class="line"><span class="lineno"> 510</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/utility/pair.html">std::pair<matrix<int></a>, <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">matrix<int></a>> p =</div>
|
||||
<div class="line"><span class="lineno"> 511</span> <a class="code hl_function" href="../../d6/d26/classciphers_1_1_hill_cipher.html#a405b0a28d66a61239d3565d5256f9cb5">ciphers::HillCipher::generate_keys</a>(8, 0, 3);</div>
|
||||
<div class="line"><span class="lineno"> 512</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">matrix<int></a> ekey = p.first;</div>
|
||||
<div class="line"><span class="lineno"> 513</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">matrix<int></a> dkey = p.second;</div>
|
||||
<div class="line"><span class="lineno"> 514</span> </div>
|
||||
<div class="line"><span class="lineno"> 515</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a> gibberish = <a class="code hl_function" href="../../d6/d26/classciphers_1_1_hill_cipher.html#aa8bbb6e4a5749f6008b06602d5103917">ciphers::HillCipher::encrypt_text</a>(text, ekey);</div>
|
||||
<div class="line"><span class="lineno"> 516</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"Encrypted text:\n\t"</span> << gibberish << <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
|
||||
<div class="line"><span class="lineno"> 517</span> </div>
|
||||
<div class="line"><span class="lineno"> 518</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a> txt_back = <a class="code hl_function" href="../../d6/d26/classciphers_1_1_hill_cipher.html#a427acfac1dbff3f48a2b071d449d965b">ciphers::HillCipher::decrypt_text</a>(gibberish, dkey);</div>
|
||||
<div class="line"><span class="lineno"> 519</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"Reconstruct text:\n\t"</span> << txt_back << <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
|
||||
<div class="line"><span class="lineno"> 520</span> </div>
|
||||
<div class="line"><span class="lineno"> 521</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ofstream.html">std::ofstream</a> out_file(<span class="stringliteral">"hill_cipher_test2.txt"</span>);</div>
|
||||
<div class="line"><span class="lineno"> 522</span> out_file << <span class="stringliteral">"Block size: "</span> << ekey.<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector/size.html">size</a>() << <span class="stringliteral">"\n"</span>;</div>
|
||||
<div class="line"><span class="lineno"> 523</span> out_file << <span class="stringliteral">"Encryption Key:\n"</span> << ekey;</div>
|
||||
<div class="line"><span class="lineno"> 524</span> out_file << <span class="stringliteral">"\nDecryption Key:\n"</span> << dkey;</div>
|
||||
<div class="line"><span class="lineno"> 525</span> out_file.close();</div>
|
||||
<div class="line"><span class="lineno"> 526</span> </div>
|
||||
<div class="line"><span class="lineno"> 527</span> assert(txt_back.<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string/compare.html">compare</a>(0, text.<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string/size.html">size</a>(), text) == 0);</div>
|
||||
<div class="line"><span class="lineno"> 528</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"Passed :)\n"</span>;</div>
|
||||
<div class="line"><span class="lineno"> 529</span>}</div>
|
||||
<div class="ttc" id="acompare_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/string/basic_string/compare.html">std::string::compare</a></div><div class="ttdeci">T compare(T... args)</div></div>
|
||||
</div><!-- fragment --><div class="dynheader">
|
||||
Here is the call graph for this function:</div>
|
||||
@@ -400,7 +400,7 @@ Here is the call graph for this function:</div>
|
||||
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
|
||||
<ul>
|
||||
<li class="navelem"><a class="el" href="../../dir_4d6e05837bf820fb089a8a8cdf2f42b7.html">ciphers</a></li><li class="navelem"><a class="el" href="../../d7/db9/hill__cipher_8cpp.html">hill_cipher.cpp</a></li>
|
||||
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.2 </li>
|
||||
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.3 </li>
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user