<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tyler Clemons &#187; C/C++</title>
	<atom:link href="http://www.tylerclemons.com/category/programming/cc/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tylerclemons.com</link>
	<description>tylerclemons.com</description>
	<lastBuildDate>Wed, 26 May 2010 18:39:58 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Learning Python , C++ , and Data Structures</title>
		<link>http://www.tylerclemons.com/learning-python-and-c/</link>
		<comments>http://www.tylerclemons.com/learning-python-and-c/#comments</comments>
		<pubDate>Sun, 01 Feb 2009 03:11:17 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[Books]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Data Structures]]></category>

		<guid isPermaLink="false">http://tylershome.nfshost.com/?p=134</guid>
		<description><![CDATA[Back in undergrad, the majority of our classes taught us sound software engineering principles using Python, C++, and sometimes Java.  The first two were used quite extensively.  The resource I used was invaluable to my success in mastering data structures, learning OOP, and granting me proper exposure to Python and C++.  Data Structures and Algorithms [...]]]></description>
			<content:encoded><![CDATA[<p>Back in undergrad, the majority of our classes taught us sound software engineering principles using Python, C++, and sometimes Java.  The first two were used quite extensively.  The resource I used was invaluable to my success in mastering data structures, learning OOP, and granting me proper exposure to Python and C++.  <span style="text-decoration: underline;">Data Structures and Algorithms Using Python and C++</span> is a great resource and I wanted to share it here.  I believe it is great for beginners of both Python and C++ and those entering a data structures course.  Click <a href="http://www.fbeedle.com/2335.html" target="_blank">HERE</a> to order a copy.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tylerclemons.com/learning-python-and-c/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Modular exponentiation and RSA</title>
		<link>http://www.tylerclemons.com/modular-exponentiation-and-rsa/</link>
		<comments>http://www.tylerclemons.com/modular-exponentiation-and-rsa/#comments</comments>
		<pubDate>Thu, 26 Jun 2008 05:34:54 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[RSA]]></category>

		<guid isPermaLink="false">http://tylershome.nfshost.com/?p=30</guid>
		<description><![CDATA[Here is something that is pretty well documented, but I would like to take another look at it because it is so useful.  I ran across a little problem during my RSA project.  Implementing the RSA equation is pretty simple&#8230; except for taking large numbers to a large power.  Sure generating large prime [...]]]></description>
			<content:encoded><![CDATA[<p>Here is something that is pretty well documented, but I would like to take another look at it because it is so useful.  I ran across a little problem during my RSA project.  Implementing the RSA equation is pretty simple&#8230; except for taking large numbers to a large power.  Sure generating large prime values for p&amp;q is somewhat easy, but without some level of care they can slow down any implementation. Thanks to my professors, Dr. Reed and Dr. Mertens, for introducing me to the powermod method, or what is commonly referred to as Modular Exponentiation.</p>
<p><span id="more-11"></span></p>
<p>The RSA decrypting and encrypting equations are pretty simple:</p>
<div id="codebox" style="overflow: auto; ">
<p><em>Encrypting:<br />
c = (m^e) mod n</em></p>
<p><em>Decrypting<br />
m = (c^ d) mod n</em></div>
<p>This can get pretty ugly using large values for &#8220;m&#8221; and &#8220;e&#8221; in the case of encrypting and &#8220;c&#8221; and &#8220;d&#8221; in the case of decrypting.  For programs written in C++, the value may extend the traditional datatype registers and cause those programs to malfunction, but in programs written in Python, it could drag on as Python extends its traditional register size.  The following function written in C++ can be used to solve this problem:</p>
<div id="codebox" style="overflow: hidden;"><em><span style="color: #800000;"><br />
#include &lt;iostream&gt;</span><br />
<span style="color: #ff00ff;">using namespace</span> std;</em></p>
<p><span style="color: #ff00ff;">template</span> &lt;<span style="color: #ff00ff;">class</span> T, <span style="color: #ff00ff;">class</span> U, <span style="color: #ff00ff;">class</span> V&gt;<em></em></p>
<p><em>T powermod(T x, U y, V n){</em></p>
<p style="padding-left: 10px;"><span style="color: #ff0000;"><em><br />
//Computes (x^y) mod n.<br />
</em></span></p>
<p style="padding-left: 10px;"><em>T ans = 1;</em></p>
<p style="padding-left: 10px;"><span style="color: #ff00ff;"><em>while</em></span><em> (y != 0){</em></p>
<p style="padding-left: 40px;"><em> <span style="color: #ff00ff;">if </span>(y%2 != 0){ans = (ans*x) % n;}<br />
</em></p>
<p style="padding-left: 40px;">x=(x*x)%n;</p>
<p style="padding-left: 40px;">y /= 2;</p>
<p style="padding-left: 10px;">}</p>
<p style="padding-left: 10px;"><span style="color: #ff00ff;"><em>return</em></span><em> ans % n;</em></p>
<p><em><br />
}</em></p>
<p><span style="color: #ff00ff;"><em>int</em></span><em> main (<span style="color: #ff00ff;">int </span>argc, <span style="color: #ff00ff;">char </span>* <span style="color: #ff00ff;">const</span> argv[]) {</em></p>
<p style="padding-left: 10px;"><span style="color: #ff00ff;"><em>long long</em></span><em> x = 232;<br />
<span style="color: #ff00ff;">long</span> y = 323467;<br />
<span style="color: #ff00ff;">int </span>n = 27;</em></p>
<p style="padding-left: 10px;"><em>cout&lt;&lt;powermod(x,y,n)&lt;&lt;endl;<br />
//outputs 25</em></p>
<p style="padding-left: 10px;"><span style="color: #ff00ff;">return <span style="color: #000000;">0;</span></span><em></em></p>
<p><em>}</em></div>
<p>I originally received this code from Dr. Reed in Python and applied it to my RSA application and felt like making it in C++.  Templates are useful, overkill for the simple example above and just a sign of boredom from me, and helpful when applied to datatypes designed to hold large interger types that C++ can&#8217;t traditonally hold.  In Python, the size of any large integer is unlimited as long as you have enough memory, but in C++ it may be possible to exceed numbers that are larger than the built in datatypes.  For this method, powermod, to work, the user defined datatypes must overload the %, *, /= operators and create conversion functions.  But any good large integer datatype will have those <img src='http://tylershome.nfshost.com/home/public/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   I wrote this in C++, but this should not be hard to port to other languages such as Python, Ruby, or Java.  Just change some of the syntax and leave the variables the same.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tylerclemons.com/modular-exponentiation-and-rsa/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
