mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-03-23 21:32:09 +08:00
Documentation for c26eea874d
This commit is contained in:
@@ -4,7 +4,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.12.0"/>
|
||||
<meta name="generator" content="Doxygen 1.13.2"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
<title>TheAlgorithms/C++: ciphers/xor_cipher.cpp Source File</title>
|
||||
<link rel="icon" href="../../favicon.svg" type="image/x-icon" />
|
||||
@@ -60,7 +60,7 @@ window.MathJax = {
|
||||
</table>
|
||||
</div>
|
||||
<!-- end header part -->
|
||||
<!-- Generated by Doxygen 1.12.0 -->
|
||||
<!-- Generated by Doxygen 1.13.2 -->
|
||||
<script type="text/javascript">
|
||||
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
||||
var searchBox = new SearchBox("searchBox", "../../search/",'.html');
|
||||
@@ -124,15 +124,15 @@ $(function(){initNavTree('d3/d4c/xor__cipher_8cpp_source.html','../../'); initRe
|
||||
<div class="headertitle"><div class="title">xor_cipher.cpp</div></div>
|
||||
</div><!--header-->
|
||||
<div class="contents">
|
||||
<a href="../../d3/d4c/xor__cipher_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a id="l00001" name="l00001"></a><span class="lineno"> 1</span> </div>
|
||||
<a href="../../d3/d4c/xor__cipher_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a id="l00001" name="l00001"></a><span class="lineno"> 1</span></div>
|
||||
<div class="line"><a id="l00029" name="l00029"></a><span class="lineno"> 29</span><span class="preprocessor">#include <iostream></span></div>
|
||||
<div class="line"><a id="l00030" name="l00030"></a><span class="lineno"> 30</span><span class="preprocessor">#include <string></span></div>
|
||||
<div class="line"><a id="l00031" name="l00031"></a><span class="lineno"> 31</span><span class="preprocessor">#include <cassert></span></div>
|
||||
<div class="line"><a id="l00032" name="l00032"></a><span class="lineno"> 32</span> </div>
|
||||
<div class="line"><a id="l00032" name="l00032"></a><span class="lineno"> 32</span></div>
|
||||
<div class="line"><a id="l00036" name="l00036"></a><span class="lineno"> 36</span><span class="keyword">namespace </span><a class="code hl_namespace" href="../../d6/d4e/namespaceciphers.html">ciphers</a> {</div>
|
||||
<div class="line"><a id="l00040" name="l00040"></a><span class="lineno"> 40</span> <span class="keyword">namespace </span><a class="code hl_namespace" href="../../d7/d47/namespace_x_o_r.html">XOR</a> { </div>
|
||||
<div class="foldopen" id="foldopen00047" data-start="{" data-end="}">
|
||||
<div class="line"><a id="l00047" name="l00047"></a><span class="lineno"><a class="line" href="../../d3/d4c/xor__cipher_8cpp.html#aeff72a463ffc580c16cc849cbbdc58ef"> 47</a></span> std::string encrypt (<span class="keyword">const</span> std::string &text, <span class="keyword">const</span> <span class="keywordtype">int</span> &key) {</div>
|
||||
<div class="line"><a id="l00047" name="l00047"></a><span class="lineno"><a class="line" href="../../d3/d4c/xor__cipher_8cpp.html#aeff72a463ffc580c16cc849cbbdc58ef"> 47</a></span> std::string <a class="code hl_function" href="../../d3/d4c/xor__cipher_8cpp.html#aeff72a463ffc580c16cc849cbbdc58ef">encrypt</a> (<span class="keyword">const</span> std::string &text, <span class="keyword">const</span> <span class="keywordtype">int</span> &key) {</div>
|
||||
<div class="line"><a id="l00048" name="l00048"></a><span class="lineno"> 48</span> std::string encrypted_text = <span class="stringliteral">""</span>; <span class="comment">// Empty string to store encrypted text</span></div>
|
||||
<div class="line"><a id="l00049" name="l00049"></a><span class="lineno"> 49</span> <span class="keywordflow">for</span> (<span class="keyword">auto</span> &c: text) { <span class="comment">// Going through each character</span></div>
|
||||
<div class="line"><a id="l00050" name="l00050"></a><span class="lineno"> 50</span> <span class="keywordtype">char</span> encrypted_char = char(c ^ key); <span class="comment">// Applying encyption</span></div>
|
||||
@@ -141,8 +141,9 @@ $(function(){initNavTree('d3/d4c/xor__cipher_8cpp_source.html','../../'); initRe
|
||||
<div class="line"><a id="l00053" name="l00053"></a><span class="lineno"> 53</span> <span class="keywordflow">return</span> encrypted_text; <span class="comment">// Returning encrypted text</span></div>
|
||||
<div class="line"><a id="l00054" name="l00054"></a><span class="lineno"> 54</span> }</div>
|
||||
</div>
|
||||
<div class="line"><a id="l00055" name="l00055"></a><span class="lineno"> 55</span> </div>
|
||||
<div class="foldopen" id="foldopen00061" data-start="{" data-end="}">
|
||||
<div class="line"><a id="l00061" name="l00061"></a><span class="lineno"><a class="line" href="../../d3/d4c/xor__cipher_8cpp.html#a6099b7e0f1793f418d2c1befca8355a4"> 61</a></span> std::string decrypt (<span class="keyword">const</span> std::string &text, <span class="keyword">const</span> <span class="keywordtype">int</span> &key) {</div>
|
||||
<div class="line"><a id="l00061" name="l00061"></a><span class="lineno"><a class="line" href="../../d3/d4c/xor__cipher_8cpp.html#a6099b7e0f1793f418d2c1befca8355a4"> 61</a></span> std::string <a class="code hl_function" href="../../d3/d4c/xor__cipher_8cpp.html#a6099b7e0f1793f418d2c1befca8355a4">decrypt</a> (<span class="keyword">const</span> std::string &text, <span class="keyword">const</span> <span class="keywordtype">int</span> &key) {</div>
|
||||
<div class="line"><a id="l00062" name="l00062"></a><span class="lineno"> 62</span> std::string decrypted_text = <span class="stringliteral">""</span>; <span class="comment">// Empty string to store decrypted text</span></div>
|
||||
<div class="line"><a id="l00063" name="l00063"></a><span class="lineno"> 63</span> <span class="keywordflow">for</span> (<span class="keyword">auto</span> &c : text) { <span class="comment">// Going through each character</span></div>
|
||||
<div class="line"><a id="l00064" name="l00064"></a><span class="lineno"> 64</span> <span class="keywordtype">char</span> decrypted_char = char(c ^ key); <span class="comment">// Applying decryption</span></div>
|
||||
@@ -153,28 +154,28 @@ $(function(){initNavTree('d3/d4c/xor__cipher_8cpp_source.html','../../'); initRe
|
||||
</div>
|
||||
<div class="line"><a id="l00069" name="l00069"></a><span class="lineno"> 69</span> } <span class="comment">// namespace XOR</span></div>
|
||||
<div class="line"><a id="l00070" name="l00070"></a><span class="lineno"> 70</span>} <span class="comment">// namespace ciphers</span></div>
|
||||
<div class="line"><a id="l00071" name="l00071"></a><span class="lineno"> 71</span> </div>
|
||||
<div class="line"><a id="l00071" name="l00071"></a><span class="lineno"> 71</span></div>
|
||||
<div class="foldopen" id="foldopen00075" data-start="{" data-end="}">
|
||||
<div class="line"><a id="l00075" name="l00075"></a><span class="lineno"><a class="line" href="../../d3/d4c/xor__cipher_8cpp.html#ae1a3968e7947464bee7714f6d43b7002"> 75</a></span><span class="keywordtype">void</span> <a class="code hl_function" href="../../d3/d4c/xor__cipher_8cpp.html#ae1a3968e7947464bee7714f6d43b7002">test</a>() {</div>
|
||||
<div class="line"><a id="l00076" name="l00076"></a><span class="lineno"> 76</span> <span class="comment">// Test 1</span></div>
|
||||
<div class="line"><a id="l00077" name="l00077"></a><span class="lineno"> 77</span> std::string text1 = <span class="stringliteral">"Whipalsh! : Do watch this movie..."</span>;</div>
|
||||
<div class="line"><a id="l00078" name="l00078"></a><span class="lineno"> 78</span> std::string encrypted1 = ciphers::XOR::encrypt(text1, 17);</div>
|
||||
<div class="line"><a id="l00079" name="l00079"></a><span class="lineno"> 79</span> std::string decrypted1 = ciphers::XOR::decrypt(encrypted1, 17);</div>
|
||||
<div class="line"><a id="l00078" name="l00078"></a><span class="lineno"> 78</span> std::string encrypted1 = <a class="code hl_function" href="../../d3/d4c/xor__cipher_8cpp.html#aeff72a463ffc580c16cc849cbbdc58ef">ciphers::XOR::encrypt</a>(text1, 17);</div>
|
||||
<div class="line"><a id="l00079" name="l00079"></a><span class="lineno"> 79</span> std::string decrypted1 = <a class="code hl_function" href="../../d3/d4c/xor__cipher_8cpp.html#a6099b7e0f1793f418d2c1befca8355a4">ciphers::XOR::decrypt</a>(encrypted1, 17);</div>
|
||||
<div class="line"><a id="l00080" name="l00080"></a><span class="lineno"> 80</span> assert(text1 == decrypted1);</div>
|
||||
<div class="line"><a id="l00081" name="l00081"></a><span class="lineno"> 81</span> std::cout << <span class="stringliteral">"Original text : "</span> << text1;</div>
|
||||
<div class="line"><a id="l00082" name="l00082"></a><span class="lineno"> 82</span> std::cout << <span class="stringliteral">" , Encrypted text (with key = 17) : "</span> << encrypted1;</div>
|
||||
<div class="line"><a id="l00083" name="l00083"></a><span class="lineno"> 83</span> std::cout << <span class="stringliteral">" , Decrypted text : "</span><< decrypted1 << std::endl;</div>
|
||||
<div class="line"><a id="l00084" name="l00084"></a><span class="lineno"> 84</span> <span class="comment">// Test 2</span></div>
|
||||
<div class="line"><a id="l00085" name="l00085"></a><span class="lineno"> 85</span> std::string text2 = <span class="stringliteral">"->Valar M0rghulis<-"</span>;</div>
|
||||
<div class="line"><a id="l00086" name="l00086"></a><span class="lineno"> 86</span> std::string encrypted2 = ciphers::XOR::encrypt(text2, 29);</div>
|
||||
<div class="line"><a id="l00087" name="l00087"></a><span class="lineno"> 87</span> std::string decrypted2 = ciphers::XOR::decrypt(encrypted2, 29);</div>
|
||||
<div class="line"><a id="l00086" name="l00086"></a><span class="lineno"> 86</span> std::string encrypted2 = <a class="code hl_function" href="../../d3/d4c/xor__cipher_8cpp.html#aeff72a463ffc580c16cc849cbbdc58ef">ciphers::XOR::encrypt</a>(text2, 29);</div>
|
||||
<div class="line"><a id="l00087" name="l00087"></a><span class="lineno"> 87</span> std::string decrypted2 = <a class="code hl_function" href="../../d3/d4c/xor__cipher_8cpp.html#a6099b7e0f1793f418d2c1befca8355a4">ciphers::XOR::decrypt</a>(encrypted2, 29);</div>
|
||||
<div class="line"><a id="l00088" name="l00088"></a><span class="lineno"> 88</span> assert(text2 == decrypted2);</div>
|
||||
<div class="line"><a id="l00089" name="l00089"></a><span class="lineno"> 89</span> std::cout << <span class="stringliteral">"Original text : "</span> << text2;</div>
|
||||
<div class="line"><a id="l00090" name="l00090"></a><span class="lineno"> 90</span> std::cout << <span class="stringliteral">" , Encrypted text (with key = 29) : "</span> << encrypted2;</div>
|
||||
<div class="line"><a id="l00091" name="l00091"></a><span class="lineno"> 91</span> std::cout << <span class="stringliteral">" , Decrypted text : "</span><< decrypted2 << std::endl;</div>
|
||||
<div class="line"><a id="l00092" name="l00092"></a><span class="lineno"> 92</span>}</div>
|
||||
</div>
|
||||
<div class="line"><a id="l00093" name="l00093"></a><span class="lineno"> 93</span> </div>
|
||||
<div class="line"><a id="l00093" name="l00093"></a><span class="lineno"> 93</span></div>
|
||||
<div class="foldopen" id="foldopen00095" data-start="{" data-end="}">
|
||||
<div class="line"><a id="l00095" name="l00095"></a><span class="lineno"><a class="line" href="../../d3/d4c/xor__cipher_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4"> 95</a></span><span class="keywordtype">int</span> <a class="code hl_function" href="../../d3/d4c/xor__cipher_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4">main</a>() {</div>
|
||||
<div class="line"><a id="l00096" name="l00096"></a><span class="lineno"> 96</span> <span class="comment">// Testing</span></div>
|
||||
@@ -184,15 +185,17 @@ $(function(){initNavTree('d3/d4c/xor__cipher_8cpp_source.html','../../'); initRe
|
||||
</div>
|
||||
<div class="ttc" id="anamespace_x_o_r_html"><div class="ttname"><a href="../../d7/d47/namespace_x_o_r.html">XOR</a></div><div class="ttdoc">Functions for XOR cipher algorithm.</div></div>
|
||||
<div class="ttc" id="anamespaceciphers_html"><div class="ttname"><a href="../../d6/d4e/namespaceciphers.html">ciphers</a></div><div class="ttdoc">Algorithms for encryption and decryption.</div></div>
|
||||
<div class="ttc" id="axor__cipher_8cpp_html_a6099b7e0f1793f418d2c1befca8355a4"><div class="ttname"><a href="../../d3/d4c/xor__cipher_8cpp.html#a6099b7e0f1793f418d2c1befca8355a4">ciphers::XOR::decrypt</a></div><div class="ttdeci">std::string decrypt(const std::string &text, const int &key)</div><div class="ttdef"><b>Definition</b> <a href="#l00061">xor_cipher.cpp:61</a></div></div>
|
||||
<div class="ttc" id="axor__cipher_8cpp_html_ae1a3968e7947464bee7714f6d43b7002"><div class="ttname"><a href="../../d3/d4c/xor__cipher_8cpp.html#ae1a3968e7947464bee7714f6d43b7002">test</a></div><div class="ttdeci">void test()</div><div class="ttdef"><b>Definition</b> <a href="#l00075">xor_cipher.cpp:75</a></div></div>
|
||||
<div class="ttc" id="axor__cipher_8cpp_html_ae66f6b31b5ad750f1fe042a706a4e3d4"><div class="ttname"><a href="../../d3/d4c/xor__cipher_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4">main</a></div><div class="ttdeci">int main()</div><div class="ttdef"><b>Definition</b> <a href="#l00095">xor_cipher.cpp:95</a></div></div>
|
||||
<div class="ttc" id="axor__cipher_8cpp_html_aeff72a463ffc580c16cc849cbbdc58ef"><div class="ttname"><a href="../../d3/d4c/xor__cipher_8cpp.html#aeff72a463ffc580c16cc849cbbdc58ef">ciphers::XOR::encrypt</a></div><div class="ttdeci">std::string encrypt(const std::string &text, const int &key)</div><div class="ttdef"><b>Definition</b> <a href="#l00047">xor_cipher.cpp:47</a></div></div>
|
||||
</div><!-- fragment --></div><!-- contents -->
|
||||
</div><!-- doc-content -->
|
||||
<!-- start footer part -->
|
||||
<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="../../d3/d4c/xor__cipher_8cpp.html">xor_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.12.0 </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.13.2 </li>
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user