<?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>Pensador&#039;s Blog</title>
	<atom:link href="http://pensador.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://pensador.org</link>
	<description>Yet another pseudo-intellectual</description>
	<lastBuildDate>Mon, 25 Jan 2010 18:03:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to load a properties file from a servlet</title>
		<link>http://pensador.org/2009/06/28/how-to-load-a-properties-files-from-a-servlet/</link>
		<comments>http://pensador.org/2009/06/28/how-to-load-a-properties-files-from-a-servlet/#comments</comments>
		<pubDate>Sun, 28 Jun 2009 14:48:30 +0000</pubDate>
		<dc:creator>Saulo</dc:creator>
				<category><![CDATA[How-Tos]]></category>

		<guid isPermaLink="false">http://pensador.org/?p=433</guid>
		<description><![CDATA[
I wanted to read a properties file from a servlet without using a hard-coded, absolute path. I tried to search on the web for a portable solution, but I couldn&#8217;t find anything.
Here is the trick: use ServletContext.getRealPath(String). For instance, a file called &#8220;config.properties&#8221; located in &#8220;WEB-INF&#8221;, can be loaded like this:

public void init(ServletConfig config) throws [...]]]></description>
			<content:encoded><![CDATA[<p><img class="aligncenter size-full wp-image-462" title="config.properties" src="http://pensador.org/wp-content/uploads/2009/06/config.properties.png" alt="config.properties" width="366" height="131" /></p>
<p>I wanted to read a properties file from a servlet without using a hard-coded, absolute path. I tried to <a href="http://www.google.ca/search?q=properties+file+j2ee&amp;hl=en">search on the web</a> for a portable solution, but I couldn&#8217;t find anything.</p>
<p>Here is the trick: use <code><a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletContext.html#getRealPath(java.lang.String)">ServletContext.getRealPath(String)</a></code>. For instance, a file called &#8220;config.properties&#8221; located in &#8220;WEB-INF&#8221;, can be loaded like this:</p>
<pre class="brush: java;">
public void init(ServletConfig config) throws ServletException {
	String pathToFile = config.getServletContext().getRealPath(&quot;&quot;)
		+ &quot;/WEB-INF/config.properties&quot;;
	Properties properties = new Properties();
	properties.load(new FileInputStream(pathToPropertiesFile));
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://pensador.org/2009/06/28/how-to-load-a-properties-files-from-a-servlet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Aspect-oriented programming with AspectJ</title>
		<link>http://pensador.org/2009/03/29/aspect-oriented-programming-with-aspectj/</link>
		<comments>http://pensador.org/2009/03/29/aspect-oriented-programming-with-aspectj/#comments</comments>
		<pubDate>Mon, 30 Mar 2009 03:35:47 +0000</pubDate>
		<dc:creator>Saulo</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[aspectj]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://pensador.org/?p=276</guid>
		<description><![CDATA[In one of the courses I took this session I was introduced to aspect-oriented programming. For those who are not familiar with it, an aspect can be used to implement a concern that is crosscutting among different components. (There are a few such concerns that are commonly affected by crosscutting, namely: authentication, persistence, logging and [...]]]></description>
			<content:encoded><![CDATA[<p>In one of the courses I took this session I was introduced to aspect-oriented programming. For those who are not familiar with it, an aspect can be used to implement a concern that is crosscutting among different components. (There are a few such concerns that are commonly affected by crosscutting, namely: authentication, persistence, logging and contract checking.) It is argued that with object-oriented programming, even after proper refactoring, it is not always possible to map a requirement to a single component. When a requirement is implemented by more than one component, scattering occurs. <acronym title="Aspect-oriented programming">AOP</acronym> allows you to localize the scattered requirement into an aspect.</p>
<p>AspectJ is an extension to the Java language that adds support to <acronym title="Aspect-oriented programming">AOP</acronym>. An aspect in AspectJ is composed of pointcuts and advices. A pointcut defines the condition that needs to be met in order for the logic in an advice to be executed. A pointcut could be, for instance, the execution of a method in a particular class.</p>
<h3>How AspectJ can be useful</h3>
<p>Let&#8217;s look at an example. Say we want to log when <a title="A horse drinking water." href="http://www.flickr.com/photos/architekt2/185791912/">horses drink water</a> and when <a title="A cow eating grass." href="http://www.flickr.com/photos/dizzo/2168240431/">cows eat grass</a>. Assume we have a class <code>Logger</code> with a static method <code>log()</code>. Here&#8217;s what the implementation could look like:</p>
<pre class="brush: java;">public class Horse {
	private int consumedWaterInLitres;

	public void drink() {
		consumedWaterInLitres++;
		Logger.log(&quot;A horse is drinking water.&quot;);
	}
}

public class Cow {
	private int consumedGrassInGrams;

	public void eat() {
		consumedGrassInGrams++;
		Logger.log(&quot;A cow is eating grass.&quot;);
	}
}</pre>
<p>The argument is that the concern of logging is now crosscut among the Horse and Cow components. In addition, it can be said that <code>Horse.drink()</code> and <code>Cow.eat()</code> are responsible for more core logic (eating and drinking) than they should have been. Let&#8217;s try to fix this problem with an aspect:</p>
<pre class="brush: java;">public aspect Logging {
	pointcut logHorseDrinking() : call(public void Horse.drink());
	pointcut logCowEating() : call(public void Cow.eat());

	void after() : logHorseDrinking() {
		Logger.log(&quot;A horse is drinking water.&quot;);
	}

	void after() : logCowEating() {
		Logger.log(&quot;A cow is eating grass.&quot;);
	}
}</pre>
<p>Here we defined two pointcuts that capture calls to <code>Horse.drink()</code> and to <code>Cow.eat()</code>. We&#8217;ve attached these pointcuts to two advices that will run after these methods are executed. With the Logging aspect in place, we can now remove all calls to <code>Logger.log()</code> from <code>Horse</code> and <code>Cow</code>. Isn&#8217;t that great?</p>
<h3>How AspectJ can be dangerous</h3>
<div id="attachment_330" class="wp-caption alignright" style="width: 96px"><img class="size-full wp-image-330" title="Dog Class Diagram" src="http://pensador.org/wp-content/uploads/2009/03/dog_class_diagram.png" alt="Dog before DogAspect" width="86" height="46" /><p class="wp-caption-text">Dog before DogAspect</p></div>
<p>Aspects can also add state, behaviour and inheritance to a component. Privileged aspects have access to all features in a system—including private ones. Does that raise a red flag? Let&#8217;s look at the class <code>Dog</code> below.</p>
<pre class="brush: java;">public class Dog {
}</pre>
<p>It has no features—no attributes nor methods—and doesn&#8217;t extend from any class, right? Wrong:</p>
<pre class="brush: java;">public aspect DogAspect {
	declare parents: Dog extends Animal;
	private String Dog.ownersName = &quot;Bobert&quot;;

	public String Dog.getOwnwersName() {
		return ownersName;
	}
}</pre>
<div id="attachment_353" class="wp-caption alignright" style="width: 156px"><img class="size-full wp-image-353" title="Class Dog after DogAspect" src="http://pensador.org/wp-content/uploads/2009/03/dog_after_dogaspect.png" alt="Dog after DogAspect" width="146" height="136" /><p class="wp-caption-text">Dog after DogAspect</p></div>
<p>The aspect above has completely changed the class <code>Dog</code>. It has made it an <code>Animal</code>, it has added an attribute <em>ownersName</em> and a getter for it. The worst part is that <code>Dog</code> is completely oblivious to the aspect—it will never know about it. In fact, unless you as a developer look at all aspects on the system, you will never know about it either.</p>
<p>That is not completely true because some <acronym title="Integrated development environment">IDE</acronym>s will provide a visual clue as to when a class is affected by an aspect. The <a href="http://www.eclipse.org/ajdt/">AspectJ Developement Tools</a> add-on for <a href="http://eclipse.org/">Eclipse</a> (a great <acronym title="Integrated development environment">IDE</acronym> by the way) is supposed to show a marker on the editor margin whenever a component is being advised by an aspect. I have the latest version installed (ADJT 1.6.4) but for some reason the marker is not showing up, unfortunately.</p>
<p>There are also other issues one might encounter when using AspectJ. It is not an easy task to document the impact aspects have on a system—<acronym title="Unified Modeling Language">UML</acronym> has no support for aspects at this moment, and how are you going to show that on a sequence diagram? Also, the debugging and tracing of execution of a class that is being advised by an aspect can get pretty tricky.</p>
<h3>In conclusion</h3>
<p>I believe that the application of <acronym title="Aspect-oriented programming">AOP</acronym> could indeed improve the quality of a system through the localization of crosscutting concerns. However, its Java implementation—AspectJ—provides a level of control that is too risky to be used in industrial medium- to large-scale projects. Its supporting technologies and documenting tools have not yet reached the desired maturity level.</p>
]]></content:encoded>
			<wfw:commentRss>http://pensador.org/2009/03/29/aspect-oriented-programming-with-aspectj/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Should we use foreign-key constraints when persisting Domain Models?</title>
		<link>http://pensador.org/2009/02/28/domain-model-persistence-and-foreign-key-constraints/</link>
		<comments>http://pensador.org/2009/02/28/domain-model-persistence-and-foreign-key-constraints/#comments</comments>
		<pubDate>Sat, 28 Feb 2009 19:53:25 +0000</pubDate>
		<dc:creator>Saulo</dc:creator>
				<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://pensador.org/?p=253</guid>
		<description><![CDATA[
Since last summer I&#8217;ve been working with three other Software Engineering undergraduates on a web enterprise application that will eventually replace a legacy ERP system. We used patterns from Martin Fowler&#8217;s Patterns of Enterprise Application Architecture (a great book, by the way), and the well-known three-layered architecture.
One day we had a discussion related to the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://pensador.org/wp-content/uploads/2009/02/mediawiki-database-schema.png"><img class="size-thumbnail wp-image-264 alignleft" title="The Mediawiki database schema" src="http://pensador.org/wp-content/uploads/2009/02/mediawiki-database-schema-150x150.png" alt="Mediawiki Database Schema" width="150" height="150" /></a></p>
<p>Since last summer I&#8217;ve been working with three other Software Engineering undergraduates on a web enterprise application that will eventually replace a legacy <acronym title="Enterprise Resource Planning">ERP</acronym> system. We used patterns from Martin Fowler&#8217;s <a href="http://martinfowler.com/books.html"><em>Patterns of Enterprise Application Architecture</em></a> (a great book, by the way), and the well-known three-layered architecture.</p>
<p>One day we had a discussion related to the persistence of <a title="The Domain Model software design pattern." href="http://martinfowler.com/eaaCatalog/domainModel.html">Domain Model</a>s and whether we should enforce foreign-key constraints at the database level. My first reaction was that the very use of a relational database implied the enforcement of such constraints, but some of my colleagues argued that the database should be seen as nothing but a persistence mechanism and therefore we should avoid placing any business logic in it. We ended up by not using foreign-key constraints.</p>
<p>Would you have done otherwise? I would like to hear what other software engineers/developers have to say about this.</p>
]]></content:encoded>
			<wfw:commentRss>http://pensador.org/2009/02/28/domain-model-persistence-and-foreign-key-constraints/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Mighty Putty</title>
		<link>http://pensador.org/2009/01/29/mighty-putty/</link>
		<comments>http://pensador.org/2009/01/29/mighty-putty/#comments</comments>
		<pubDate>Thu, 29 Jan 2009 16:29:31 +0000</pubDate>
		<dc:creator>Saulo</dc:creator>
				<category><![CDATA[Humour]]></category>
		<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://pensador.org/?p=234</guid>
		<description><![CDATA[Hey guys, sorry for the lack of updates. My last semester has been a little bit hectic, but in three months I&#8217;ll be a (Junior) Software Engineer! :)
Here&#8217;s a little video I just sumbled upon on reddit. It&#8217;s pure gold.

]]></description>
			<content:encoded><![CDATA[<p>Hey guys, sorry for the lack of updates. My last semester has been a little bit hectic, but in three months I&#8217;ll be a (Junior) Software Engineer! :)</p>
<p>Here&#8217;s a little video I just sumbled upon on reddit. It&#8217;s pure gold.</p>
<p><object width="480" height="385" data="http://www.youtube.com/v/r_4a4O7kXQo&amp;hl=en&amp;fs=1&amp;color1=0x2b405b&amp;color2=0x6b8ab6" type="application/x-shockwave-flash"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/r_4a4O7kXQo&amp;hl=en&amp;fs=1&amp;color1=0x2b405b&amp;color2=0x6b8ab6" /><param name="allowfullscreen" value="true" /></object></p>
]]></content:encoded>
			<wfw:commentRss>http://pensador.org/2009/01/29/mighty-putty/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Obama&#8217;s acceptance speech</title>
		<link>http://pensador.org/2008/11/07/obamas-acceptance-speech/</link>
		<comments>http://pensador.org/2008/11/07/obamas-acceptance-speech/#comments</comments>
		<pubDate>Fri, 07 Nov 2008 19:39:03 +0000</pubDate>
		<dc:creator>Saulo</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[images]]></category>
		<category><![CDATA[politics]]></category>
		<category><![CDATA[United States]]></category>

		<guid isPermaLink="false">http://pensador.org/?p=221</guid>
		<description><![CDATA[Thanks to my friend Gabx for sending me this great artwork by pluckylump from deviantArt.

]]></description>
			<content:encoded><![CDATA[<p>Thanks to my friend <a href="http://gabrielx.com/">Gabx</a> for sending me this great artwork by <a href="http://pluckylump.deviantart.com/">pluckylump</a> from <a href="http://pluckylump.deviantart.com/art/With-Great-Humility-100963792">deviantArt</a>.<br />
<a href="http://pensador.org/wp-content/uploads/2008/11/with_great_humility____by_pluckylump.jpg"><img class="aligncenter size-medium wp-image-222" title="With Great Humility... by *pluckylump" src="http://pensador.org/wp-content/uploads/2008/11/with_great_humility____by_pluckylump-197x300.jpg" alt="" width="197" height="300" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://pensador.org/2008/11/07/obamas-acceptance-speech/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Barack Obama 2008</title>
		<link>http://pensador.org/2008/10/31/i-support-barack-obama/</link>
		<comments>http://pensador.org/2008/10/31/i-support-barack-obama/#comments</comments>
		<pubDate>Fri, 31 Oct 2008 14:52:38 +0000</pubDate>
		<dc:creator>Saulo</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[politics]]></category>
		<category><![CDATA[United States]]></category>

		<guid isPermaLink="false">http://pensador.org/?p=214</guid>
		<description><![CDATA[I support Barack Obama. That is all.
Edit: Obama is the new elect-president! Congratulations!

]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-215" title="Barack Obama 2008" src="http://pensador.org/wp-content/uploads/2008/10/obamafaceicon.jpg" alt="" width="96" height="96" />I support Barack Obama. That is all.<br />
<strong>Edit:</strong> Obama is the new elect-president! Congratulations!<br />
<br clear="all" /></p>
]]></content:encoded>
			<wfw:commentRss>http://pensador.org/2008/10/31/i-support-barack-obama/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Google Chrome, a new web browser</title>
		<link>http://pensador.org/2008/09/01/google-chrome-a-new-web-browser/</link>
		<comments>http://pensador.org/2008/09/01/google-chrome-a-new-web-browser/#comments</comments>
		<pubDate>Mon, 01 Sep 2008 23:11:46 +0000</pubDate>
		<dc:creator>Saulo</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[web browser]]></category>

		<guid isPermaLink="false">http://pensador.org/?p=170</guid>
		<description><![CDATA[Google confirmed tomorrow&#8217;s launch of Google Chrome beta, a new open source web browser that borrows the rendering engine from Apple&#8217;s WebKit and components from Mozilla Firefox.
An important design aspect behind Google Chrome is that each tab will be assigned an entire process instead of a thread within a process. This means that if a [...]]]></description>
			<content:encoded><![CDATA[<p><img class="size-full wp-image-179 alignleft" title="Google Chrome logo" src="http://pensador.org/wp-content/uploads/2008/09/google_chrome_logo.jpg" alt="" width="128" height="147" /><a href="http://googleblog.blogspot.com/2008/09/fresh-take-on-browser.html">Google confirmed</a> tomorrow&#8217;s launch of Google Chrome beta, a new open source web browser that borrows the rendering engine from Apple&#8217;s WebKit and components from Mozilla Firefox.</p>
<p>An important design aspect behind Google Chrome is that each tab will be assigned an entire process instead of a thread within a process. This means that if a particular website causes the page to hang, only its tab will have to be closed. In addition, a task manager will allow the user to see which page, plug-in or web application is consuming system resources, a feature available in all modern <acronym title="Operating System">OS</acronym>s.</p>
<p>Google has published a <a href="http://www.google.com/googlebooks/chrome/">comic</a> that explains in 38 pages their web browser project.</p>
<p>How will this affect the battle for market share between existing web browsers? Will Google Chrome be adopted by Firefox or <acronym title="Internet Explorer">IE</acronym> users?</p>
<p><a href="http://pensador.org/wp-content/uploads/2008/09/google_chrome_comic_page_38.png"><img class="size-thumbnail wp-image-177 alignnone" title="Google Chrome Comic page 38" src="http://pensador.org/wp-content/uploads/2008/09/google_chrome_comic_page_38-150x150.png" alt="Google Chrome Comic page 38" width="150" height="150" /></a> <a href="http://pensador.org/wp-content/uploads/2008/09/google_chrome_screenshot.jpg"><img class="size-thumbnail wp-image-186 alignnone" title="A screenshot of Google Chrome" src="http://pensador.org/wp-content/uploads/2008/09/google_chrome_screenshot-150x150.jpg" alt="A screenshot Google Chrome" width="150" height="150" /></a></p>
<p><strong>Update 1</strong>: added a screenshot (found at <a href="http://www.techcrunch.com/2008/09/01/first-public-screen-captures-of-google-chrome/">TechCrunch</a>).<br />
<strong>Update 2:</strong> <a title="Google Chrome" href="http://www.google.com/chrome/">The Google Chrome webpage is up</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://pensador.org/2008/09/01/google-chrome-a-new-web-browser/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Goodbye PensCMS, hello Wordpress!</title>
		<link>http://pensador.org/2008/08/28/goodbye-penscms-hello-wordpress/</link>
		<comments>http://pensador.org/2008/08/28/goodbye-penscms-hello-wordpress/#comments</comments>
		<pubDate>Thu, 28 Aug 2008 15:54:20 +0000</pubDate>
		<dc:creator>Saulo</dc:creator>
				<category><![CDATA[Site updates]]></category>

		<guid isPermaLink="false">http://pensador.org/?p=119</guid>
		<description><![CDATA[After realizing that I would never match the power of hundreds of developers behind Wordpress&#8217; success, I decided to ditch my own custom, ad hoc content management system. PensCMS had been around for eight years, and I had just successfully solved the spam problem with reCAPTCHA (I know, I should have thought about that before!). [...]]]></description>
			<content:encoded><![CDATA[<p>After realizing that I would never match the power of hundreds of developers behind Wordpress&#8217; success, I decided to ditch my own custom, <em>ad hoc</em> content management system. PensCMS had been around for eight years, and I had just successfully solved the spam problem with <a href="http://recaptcha.net/">reCAPTCHA</a> (I know, I should have thought about that before!). The other thing that really bothered me with my own blogging software is that in order to add images to a post, I had to manually resize, upload via FTP and paste the code for them, which was a painful process to say the least.</p>
<p>I prefer to always include at least an image with my posts, so this was a big issue for me.  As I thought about a solution, I had a sudden spark of humbleness: maybe it&#8217;s OK to use other people&#8217;s work instead of doing it all myself from the ground up.</p>
<div id="attachment_135" class="wp-caption alignleft" style="width: 110px"><img class="size-full wp-image-135" title="Wordpress" src="http://pensador.org/wp-content/uploads/2008/08/wp-20-square-button-trans.gif" alt="Wordpress" width="100" height="100" /><p class="wp-caption-text">Wordpress</p></div>
<p>After some research, I narrowed down to two options: <a href="http://wordpress.org">Wordpress</a> and <a href="http://blogger.com">Blogger</a>. The reason why I chose the former is that I wanted to transfer all my posts and comments from my old blog. The easiest way of doing so (although a bit long and tedious) was to manually add them to the database. The other option was to convert all posts and comments to XML—which I did—but I was unable to import into Blogger. Besides, there is no way of creating the <a href="about">about</a> and <a href="thoughts">thoughts</a> pages on the Google-maintained blogging system.</p>
<p>I spent the whole day yesterday moving posts and comments, customizing the <a href="http://ifelse.co.uk/simpla">Simpla</a> theme and installing plug-ins. I left behind some posts that were either too old or too silly—I did keep the ones that were chronologically interesting such as the post on how <a href="http://pensador.org/2003/10/17/mozilla-firebird-a-great-ie-alternative/">Firebird (now &#8220;Firefox&#8221;) was good alternative to IE</a>.</p>
<p>I am happy with the results and I will try to write more often now that I don&#8217;t have to open Paint.NET and FileZilla in order to post an article!</p>
]]></content:encoded>
			<wfw:commentRss>http://pensador.org/2008/08/28/goodbye-penscms-hello-wordpress/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Applying the Chinese Remainder Theorem</title>
		<link>http://pensador.org/2007/10/02/applying-the-chinese-remainder-theorem/</link>
		<comments>http://pensador.org/2007/10/02/applying-the-chinese-remainder-theorem/#comments</comments>
		<pubDate>Tue, 02 Oct 2007 13:17:59 +0000</pubDate>
		<dc:creator>Saulo</dc:creator>
				<category><![CDATA[How-Tos]]></category>
		<category><![CDATA[computer science]]></category>
		<category><![CDATA[cryptography]]></category>
		<category><![CDATA[mathematics]]></category>

		<guid isPermaLink="false">http://pensador.org/wordpress/?p=1</guid>
		<description><![CDATA[In public-key Cryptography, especially with the RSA algorithm, the Chinese Remainder Theorem is often used. Say you have a system of simultaneous congruences as follows
x  a1 mod m1
x  a3 mod m2

x  ak mod mk ,
where m1, m2, &#8230;, mk are coprime, i.e. gcd(m1, m2, &#8230;, mk) = 1.   How can [...]]]></description>
			<content:encoded><![CDATA[<p>In public-key Cryptography, especially with the <a href="http://en.wikipedia.org/wiki/RSA">RSA algorithm</a>, the Chinese Remainder Theorem is often used. Say you have a system of simultaneous congruences as follows</p>
<p align="center">x <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://pensador.org/wp-content/uploads/2008/08/congruence.png" alt="" width="11" height="13" /> a<sub>1</sub> mod m<sub>1</sub><br />
x <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://pensador.org/wp-content/uploads/2008/08/congruence.png" alt="" width="11" height="13" /> a<sub>3</sub> mod m<sub>2</sub></p>
<p style="text-align: center;"><img class="size-full wp-image-106 noborder alignnone" title="Vertical Ellipsis" src="http://pensador.org/wp-content/uploads/2008/08/vertical_ellipsis.png" alt="" width="5" height="20" /><br />
x <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://pensador.org/wp-content/uploads/2008/08/congruence.png" alt="" width="11" height="13" /> a<sub>k</sub> mod m<sub>k</sub> ,</p>
<p>where m<sub>1</sub>, m<sub>2</sub>, &#8230;, m<sub>k</sub> are coprime, i.e. <acronym title="Greatest common divisor">gcd</acronym>(m<sub>1</sub>, m<sub>2</sub>, &#8230;, m<sub>k</sub>) = 1.   How can we solve for x? The solution is quite straight forward, but could involve a   fair amount of calculations. I find that breaking down the method into smaller steps   makes it easier to find and fix mistakes. By the Chinese   Remainder Theorem, the solution to that system of equations is</p>
<p align="center">x =   (a<sub>1</sub>M<sub>1</sub>y<sub>1</sub> + a<sub>2</sub>M<sub>2</sub>y<sub>2</sub> + &#8230; + a<sub>k</sub>M<sub>k</sub>y<sub>k</sub>) mod M ,</p>
<p>where M<sub>i</sub> is the product of all   m&#8217;s except for m<sub>i</sub></p>
<p style="text-align: center;"><img class="size-full wp-image-107 noborder alignnone" title="How to compute M sub i" src="http://pensador.org/wp-content/uploads/2008/08/mi.png" alt="" width="77" height="54" />,</p>
<p>y<sub>i</sub> is the multiplicative inverse of M<sub>i</sub> modulo m<sub>i</sub></p>
<p align="center">y<sub>i</sub> <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://pensador.org/wp-content/uploads/2008/08/congruence.png" alt="" width="11" height="13" /> M<sub>i</sub><sup>-1</sup> mod m<sub>i</sub> ,</p>
<p>and M = m<sub>1</sub> * m<sub>2</sub> * &#8230; * m<sub>k</sub> .</p>
<p>Let us try a numeric example. Here is a system of simultaneous congruences:</p>
<p align="center">x <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://pensador.org/wp-content/uploads/2008/08/congruence.png" alt="" width="11" height="13" /> 12 mod 25<br />
x <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://pensador.org/wp-content/uploads/2008/08/congruence.png" alt="" width="11" height="13" /> 9 mod 26<br />
x <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://pensador.org/wp-content/uploads/2008/08/congruence.png" alt="" width="11" height="13" /> 23 mod 27</p>
<p>We start by calculating M<sub>1</sub> and y<sub>1</sub>:</p>
<p>M<sub>1</sub> = m<sub>2</sub> * m<sub>3</sub> = 26 * 27 = 702</p>
<p>y<sub>1</sub> = M<sub>1</sub><sup>-1</sup> mod m<sub>1</sub> = 702<sup>-1</sup> mod 25 .</p>
<p>We apply the <a href="http://en.wikipedia.org/wiki/Extended_Euclidean_algorithm">Extended Euclidean Algorithm</a> to find the multiplicative inverse of 702 relative to 25:</p>
<p>702 = 28 * 25 + 2  → 2 = 702 – 28 * 25<br />
25   = 12 * 2 + 1      → 1 = 25 – 12 * <span style="text-decoration: underline;">2</span><br />
= 25 – 12 * (702 – 28 * 25)<br />
= 337 * 25 – 12 * 702</p>
<p>Then y<sub>1</sub> = 702<sup>-1</sup> mod 25 <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://pensador.org/wp-content/uploads/2008/08/congruence.png" alt="" width="11" height="13" /> -12 <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://pensador.org/wp-content/uploads/2008/08/congruence.png" alt="" width="11" height="13" /> 13.</p>
<p>The same calculations can be carried on to find M<sub>2</sub> = 675, y<sub>2</sub> = 25, M<sub>3</sub> = 650 and y<sub>3</sub> = 14. Now it is just a matter of plugging in the values into the equation:</p>
<p>x = (a<sub>1</sub>M<sub>1</sub>y<sub>1</sub> + a<sub>2</sub>M<sub>2</sub>y<sub>2</sub> + a<sub>3</sub>M<sub>3</sub>y<sub>3</sub>) mod  M<br />
= (12*702*13 + 9*675*25 + 23*650*14) mod 17550 <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://pensador.org/wp-content/uploads/2008/08/congruence.png" alt="" width="11" height="13" /> 470687 <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://pensador.org/wp-content/uploads/2008/08/congruence.png" alt="" width="11" height="13" /> 14387</p>
<p>To verify our answer we can plug that number back into the system:</p>
<p>470687 mod 25 <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://pensador.org/wp-content/uploads/2008/08/congruence.png" alt="" width="11" height="13" /> 12<br />
470687 mod 26 <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://pensador.org/wp-content/uploads/2008/08/congruence.png" alt="" width="11" height="13" /> 9<br />
470687 mod 27 <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://pensador.org/wp-content/uploads/2008/08/congruence.png" alt="" width="11" height="13" /> 23</p>
]]></content:encoded>
			<wfw:commentRss>http://pensador.org/2007/10/02/applying-the-chinese-remainder-theorem/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Support peaceful protest by monks in Burma</title>
		<link>http://pensador.org/2007/09/27/support-peaceful-protest-by-monks-in-burma/</link>
		<comments>http://pensador.org/2007/09/27/support-peaceful-protest-by-monks-in-burma/#comments</comments>
		<pubDate>Thu, 27 Sep 2007 13:52:40 +0000</pubDate>
		<dc:creator>Saulo</dc:creator>
				<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://pensador.org/wordpress/?p=6</guid>
		<description><![CDATA[
Related links:

March of the monks
Myanmar troops kill 9 protesters &#8211; Reuters
Nine killed in Burmese crackdown &#8211; BBC
Canadian friends of Burma
US Campaign for Burma
Burma Campaign UK

]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><img class="aligncenter size-full wp-image-99" title="Peaceful protest by monks in Burma" src="http://pensador.org/wp-content/uploads/2008/08/peaceful_protest_by_monks_in_burma.jpg" alt="" width="416" height="300" /></p>
<p>Related links:</p>
<ul>
<li><a href="http://www.thefirstpost.co.uk/index.php?storyID=8823&amp;p=3">March of the monks</a></li>
<li><a href="http://www.reuters.com/article/worldNews/idUSB58859920070927">Myanmar troops kill 9 protesters</a> &#8211; Reuters</li>
<li><a href="http://news.bbc.co.uk/2/hi/asia-pacific/7016608.stm">Nine killed in Burmese crackdown</a> &#8211; BBC</li>
<li><a href="http://www.cfob.org/">Canadian friends of Burma</a></li>
<li><a href="http://www.uscampaignforburma.org/">US Campaign for Burma</a></li>
<li><a href="http://www.burmacampaign.org.uk/">Burma Campaign UK</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://pensador.org/2007/09/27/support-peaceful-protest-by-monks-in-burma/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
