<?xml version="1.0" encoding="iso-8859-1" ?>
<rss version="2.0">
<channel>
	<title><![CDATA[Moonbat's Lair]]></title>
	<link><![CDATA[http://www.dreamincode.net/forums/index.php?app=blog&module=showblog&blogid=203]]></link>
	<description><![CDATA[Moonbat's Lair Syndication]]></description>
	<pubDate>Sat, 06 Feb 2010 06:30:41 +0000</pubDate>
	<webMaster>admin@dreamincode.net (Dream.In.Code)</webMaster>
	<generator>IP.Blog</generator>
	<ttl>60</ttl>
	<item>
		<title>PHP to C#</title>
		<link><![CDATA[http://www.dreamincode.net/forums/index.php?app=blog&blogid=203&showentry=1018]]></link>
		<category></category>
		<description><![CDATA[I decided to write this little tidbit just in case you are a PHP user going over to C#. I just want to share my experiences of 2 weeks using C# (after about a solid year of nothing but PHP).<br />
<br />
One, C# is what is known as a <em class='bbc'>strongly typed</em> language. Pretty much everything has a type. Unlike PHP, where we just make a variable with $ and then forget about what it holds, C# depends a lot on types. There are basic ones, like 'string' and 'int' but then there are other, less familiar types like 'DateTime'. If you don't have previous experience with a language other than PHP, prepare for a flurry of compiler errors along the lines of <strong class='bbc'>'Cannot implicitly convert type X to type Y'</strong><br />
<br />
C# is also object-oriented. *gasps of awe and amazement*<br />
<br />
If you haven't experimented with object-oriented programming in PHP, you'll feel very awkward moving to C#, so I'd suggest getting some experience using PHP's OOP capabilities.<br />
<br />
That's about it really. So if you are learning C# as a PHP programmer, or are looking for a new language to learn after PHP, consider C#. It's easy to pickup and fun to use <img src='http://http.cdnlayer.com/dreamincode/forums/public/style_emoticons/default/biggrin.gif' class='bbc_emoticon' alt=':D' />]]></description>
		<pubDate>Mon, 03 Nov 2008 16:56:28 +0000</pubDate>
		<guid><![CDATA[http://www.dreamincode.net/forums/index.php?app=blog&blogid=203&showentry=1018]]></guid>
	</item>
	<item>
		<title>RSA Encryption in PHP</title>
		<link><![CDATA[http://www.dreamincode.net/forums/index.php?app=blog&blogid=203&showentry=985]]></link>
		<category></category>
		<description><![CDATA[Good news and bad news, guys.<br />
<br />
I've completed a class in PHP that generates a public and private key using the algorithm for RSA. Read more about RSA at [1].<br />
<br />
The bad news is, this <em class='bbc'>theoretically</em> works. The public key generates fast, but generating the private key takes forever and I have yet to have a successful test run. Well, anyway, here is the code, which includes the class and a test run.<br />
<br />
<pre class='prettyprint php'>&lt;?php
/**************************************************
 * RSA Algorithm Private and Public Key Generator *
 *              Coded by Moonbat                  *
 *              October 22, 2008                  *
 **************************************************/
set_time_limit(0);

class RSA {
	
	var $p; 	  /* Prime number #1 */
	var $q; 	  /* Prime number #2 */
	var $n; 	  /* Modulus to be used */
	var $totient; /* Totient of $n, used to find public key $e */
	var $e; 	  /* The public key */
	var $d; 	  /* The private key */
	
	public function __construct() {
		$this-&gt;p = $this-&gt;GeneratePrime();
		$this-&gt;q = $this-&gt;GeneratePrime();
		$this-&gt;n = $this-&gt;p * $this-&gt;q;
		$this-&gt;totient = ($this-&gt;p - 1) * ($this-&gt;q - 1);
	}

	public function IsPrime($number) {
		if ($number &lt; 2) { /* We don't want zero or one showing up as prime */
			return FALSE;
		}
		for ($i=2; $i&lt;=($number / 2); $i++) {
			if($number % $i == 0) { /* Modulus operator, very useful */
				return FALSE;
			}
		}
		return TRUE;
	}
	
	public function GeneratePrime() {
		$number = 0;
		while (!$this-&gt;IsPrime($number)) { /* Keep going till we get a prime number */
			$number = rand();
		}
		return $number;
	}
	
	/* FindGCF Function - Credit goes to &#91;url="http://us2.php.net/manual/en/function.gmp-gcd.php#69189"&#93;http://us2.php.net/manual/en/function.gmp-gcd.php#69189&#91;/url&#93; */
	public  function FindGCF($z, $totient) {
    	return ($z % $totient) ? $this-&gt;FindGCF($totient, $z % $totient) : $totient;
	}
	
	public function GeneratePublicKey() {
		$this-&gt;e = rand(2, $this-&gt;totient);
		while ($this-&gt;FindGCF($this-&gt;e, $this-&gt;totient) != 1) { // Keep going till $e is coprime with $totient
			$this-&gt;e = rand(2, $this-&gt;totient);
		}
	}
	
	public function GeneratePrivateKey() {
		$this-&gt;d = rand();
		while (($this-&gt;d % $this-&gt;totient) != ($this-&gt;e % $this-&gt;totient)) {
			$this-&gt;d = rand();
		}
	}
		
}

$encrypt = new RSA();
$encrypt-&gt;GeneratePublicKey();
$encrypt-&gt;GeneratePrivateKey();

echo "p = $encrypt-&gt;p &lt;br&gt;";
echo "q = $encrypt-&gt;q &lt;br&gt;";
echo "n = $encrypt-&gt;n &lt;br&gt;";
echo "Totient of n = $encrypt-&gt;totient";
echo "&lt;br&gt;&lt;br&gt;";
echo "The public key is &lt;font color='green'&gt;&lt;b&gt;(n = $encrypt-&gt;n, e = $encrypt-&gt;e)&lt;/b&gt;&lt;/font&gt;&lt;br&gt;";
echo "The private key is &lt;font color='red'&gt;&lt;b&gt;(n = $encrypt-&gt;n, d = $encrypt-&gt;d)&lt;/b&gt;&lt;/font&gt;";

?&gt;</pre><br />
<br />
If you just want the private key, comment out this line:<br />
<br />
<pre class='prettyprint php'>$encrypt-&gt;GeneratePrivateKey();</pre><br />
<br />
I'll be working on a way to fix the huge time requirement. This oughta be fun  <img src='http://http.cdnlayer.com/dreamincode/forums/public/style_emoticons/default/ph34r.gif' class='bbc_emoticon' alt=':ph34r:' /> <br />
<br />
[1] - <a href='http://en.wikipedia.org/wiki/Rsa' class='bbc_url' title='External link' rel='nofollow external'>http://en.wikipedia.org/wiki/Rsa</a>]]></description>
		<pubDate>Wed, 22 Oct 2008 21:47:32 +0000</pubDate>
		<guid><![CDATA[http://www.dreamincode.net/forums/index.php?app=blog&blogid=203&showentry=985]]></guid>
	</item>
	<item>
		<title>A Lesson In Anonimity</title>
		<link><![CDATA[http://www.dreamincode.net/forums/index.php?app=blog&blogid=203&showentry=979]]></link>
		<category></category>
		<description><![CDATA[If you plan on doing anything illegal, don't ever use any web proxies. This is common knowledge, but why am I emphasizing it now? Behold, Exhibit A.<br />
<br />
If you haven't heard about how the United States Republican Vice-Presidential nominee Sarah Palin had her Yahoo! email hacked, read about it at [1]<br />
<br />
Now, according to [2] an Anonymous member with the handle "Rubico" used the proxy at <a href='http://www.ctunnel.com/' class='bbc_url' title='External link' rel='nofollow external'>http://www.ctunnel.com/</a> to mask his activities. But the owner of ctunnel.com, Gabriel Ramuglia, <strong class='bbc'>voluntarily</strong> offered the logs to the FBI containing the IP address of Rubico. <br />
<br />
So, like I said. Don't trust web proxies. They will not cover you, because behind every proxy site is an owner who does not want to get arrested for obstruction of justice. Or even worse, an owner who is willing sacrifice the percieved anonimity of its users just to get one little quote published in an article.<br />
<br />
Oh, if you were wondering, Rubico was discovered. He's a 20-year old named David Kernell in Tennessee. Turns out that when Kernell was posting his hack on the Web, he used the email address that was tied to all of his other less scrupulous activities. So, lesson #2, don't use your true email when doing something illegal.<br />
<br />
Are people this stupid nowadays?<br />
<br />
[1] - <a href='http://www.time.com/time/politics/article/0,8599,1842097,00.html' class='bbc_url' title='External link' rel='nofollow external'>http://www.time.com/time/politics/article/...1842097,00.html</a><br />
[2] - <a href='http://www.tgdaily.com/html_tmp/content-view-39405-108.html' class='bbc_url' title='External link' rel='nofollow external'>http://www.tgdaily.com/html_tmp/content-view-39405-108.html</a>]]></description>
		<pubDate>Wed, 22 Oct 2008 02:31:38 +0000</pubDate>
		<guid><![CDATA[http://www.dreamincode.net/forums/index.php?app=blog&blogid=203&showentry=979]]></guid>
	</item>
	<item>
		<title>PHP-GTK GtkHtml</title>
		<link><![CDATA[http://www.dreamincode.net/forums/index.php?app=blog&blogid=203&showentry=909]]></link>
		<category></category>
		<description><![CDATA[Well, after finding out about PHP-GTK, I decided I wanted to code a browser, fully in PHP.<br />
<br />
After a little playing around with the ways of organizing the GUI (GtkHBox and GtkVBox), I had a simple web browser look. All I needed way a way to show the page.<br />
<br />
I figured I would just use a file_get_contents() to get the HTML of the page, then just put it in a GtkLabel. But sadly, it doesn't parse HTML. Then I looked up GtkHtml, an extension for PHP-GTK that would parse HTML.<br />
<br />
I followed about 5 different tutorials. I switched between versions 2.0.0 and 2.0.1 many times. I edited the php.ini file in my php-gtk2 directory so many times I've memorized it. Yet, I cannot get the GtkHtml extension to work on Windows.  <img src='http://http.cdnlayer.com/dreamincode/forums/public/style_emoticons/default/mad.gif' class='bbc_emoticon' alt=':angry:' /> <br />
<br />
If anyone has any advice to get it to work, I'm all ears. I've done everything to get it to work with no luck.]]></description>
		<pubDate>Thu, 11 Sep 2008 22:14:09 +0000</pubDate>
		<guid><![CDATA[http://www.dreamincode.net/forums/index.php?app=blog&blogid=203&showentry=909]]></guid>
	</item>
	<item>
		<title>MoonBlog is DONE!</title>
		<link><![CDATA[http://www.dreamincode.net/forums/index.php?app=blog&blogid=203&showentry=886]]></link>
		<category></category>
		<description><![CDATA[Well, after a few weeks, I finished MoonBlog 1.0  <img src='http://http.cdnlayer.com/dreamincode/forums/public/style_emoticons/default/biggrin.gif' class='bbc_emoticon' alt=':D' /> <br />
<br />
You can read about it here - <a href='http://www.dreamincode.net/forums/showtopic61625.htm' class='bbc_url' title='External link' rel='nofollow external'>http://www.dreamincode.net/forums/showtopic61625.htm</a><br />
<br />
Coding was easy enough, and besides the installer, everything else was a piece of cake. The hardest part was making it look nice. CSS and HTML are easy enough, but making it come together was difficult. I'm a programmer, not a designer. Heck, the only image I have on the blog is the little logo at the top. But all in all this was a great experience, and I've learned more than I ever would have if I'd just sat around making little 10-20 line scripts.<br />
<br />
I'd suggest anybody wanting to learn advanced PHP start working on a CMS.<br />
<br />
As for updates to MoonBlog, unless there are any security vulnerbilities (which I'm pretty sure there aren't) or I'm really bored, I don't plan on it. Adding more stuff will mean editing the design, which will be a huge pain for me. <img src='http://http.cdnlayer.com/dreamincode/forums/public/style_emoticons/default/tongue.gif' class='bbc_emoticon' alt=':P' /><br />
<br />
EDIT: I guess I kind of made this post in the heat of the moment after finishing my blog. After looking through my code again, it looks like someone took an object-oriented crap in my toilet bowl of procedural code. I am proud of having made my first CMS, but I defintely will not be updating it. For now it will serve the purpose of sitting on my HD to remind me in a few years of what I was like as a programmer. <img src='http://http.cdnlayer.com/dreamincode/forums/public/style_emoticons/default/biggrin.gif' class='bbc_emoticon' alt=':D' />]]></description>
		<pubDate>Mon, 25 Aug 2008 23:06:57 +0000</pubDate>
		<guid><![CDATA[http://www.dreamincode.net/forums/index.php?app=blog&blogid=203&showentry=886]]></guid>
	</item>
	<item>
		<title>Looking Back... (PHP Edition)</title>
		<link><![CDATA[http://www.dreamincode.net/forums/index.php?app=blog&blogid=203&showentry=873]]></link>
		<category></category>
		<description><![CDATA[I've been using PHP for about a year now, so I'd like to say I have a decent grasp of the language. But I've seen some things that make me wonder why the coders did it. Some are legitimate gripes, others are just my own pet peeves Why bother making a forum post, when I can make a blog post? This thing hasn't been used since I created it a while ago anyway.<br />
<br />
<strong class='bbc'>1. Base64 != 1337 3ncryp710n t00L</strong><br />
I've seen this especially with 'web shells' used to exploit remote file inclusion vulnerabilities. Honestly, what is the point of it? To all those people who make web shells and then backdoor them, your Base64 won't hide anything. Sure it'll take a whole two seconds to decode it, but once it's decoded, the DB details from the connection being made by your 5-minute-hackjob of a backdoor are clear as day.<br />
<br />
<br />
<strong class='bbc'>2. // Commenting every line no matter how mundane or obvious</strong><br />
I know that <span style='color: #33CC00'>md5()</span> hashes a string using the MD5 algorithim, thanks.<br />
<br />
<br />
<strong class='bbc'>3. Spaghetti includes</strong><br />
<em class='bbc'>Problem 1 - Create a function similar to foreach() to iterate through an array, but only if the array consists of nothing but integers. Be sure to have it include a file which includes a file that includes another three files that include the first file and also include two other files that include the second file included by the file that is included by the first file, which should also make use of require on four new files that include each other and require at least one other file.</em><br />
<br />
See how hard that is to understand? Now imagine reading through code that uses include() and/or require() in such a manner.<br />
<br />
<br />
<strong class='bbc'>4. ASCII art in code (art courtesy of <a href='http://chris.com/ascii/)' class='bbc_url' title='External link' rel='nofollow external'>http://chris.com/ascii/)</a></strong><br />
<pre class='prettyprint '>					@=====@
				  #=@	   @=#_
				 # &#092;/&#092;/&#092;/&#092;/&#092;/&#092; #&#092;
				 @@|  _   _  |@@&#40;
				 @@|&#092;|_|-|_|/|@@ &#41;
				  @|	/&#092;   |@ &#40;
				   |  &#092;~~~~/ |   &#41;
				   |   ~~~~  |   |
					&#092;_______/	|
			 _________|   |_______&#40;____
			/		 &#092;   /	  &#40;	 &#96;&#092;
		   /  / |  fvk &#092; /	  |-&#092;---,  &#092;
   _______/  /__|_______@_______|__&#41;___&#092;  &#092;________
  |&#092;	  &#092;  &#092;___   ______________#	 |  |__	 &#092;
  |&#092;&#092;	  /&#092; &#092;  ', |&#092; # W W W W @@ &#092;   /ooo  &#96;,	&#092;
  ||&#092;&#092;	'  ooo   &#092;&#092;#&#092; # W W W W @@ &#092; '		&#092;	&#092;
  || &#092;&#092;	&#092;	 &#59; &#092;#&#092;___o_o_o_o____&#092; &#092;	 &#59;	 &#092;
  &#092;|_|&#092;&#092;	&#96;,_____/  &#092;|______________|  &#96;,_____/	  &#092;
	   &#092;&#092;											   &#092;
		&#092;&#092;											   &#092;
		 &#092;&#092;_______________________________________________&#092;
		  &#092;  ___________________________________________  |
		  || |										 || |
		  || |										 || |
		  || |										 || |
		  &#092;|_|										 &#092;|_| </pre><br />
It looks cool, but my personal view is that it has no place in code, especially if it's as big as this one (which I've seen before). I've seen people brag about 1000+ lines of code. Heads up, ASCII art doesn't (well, shouldn't) count. Also, be sure to notice how much longer this post looks due to the ASCII art.<br />
<br />
<br />
<strong class='bbc'>5. $Overuse['Of']['Multidimensional']['Arrays']</strong><br />
I hate it when multidimensional arrays are abused like this. I have seen an array like this being used to hold stuff like pathnames, username and password details, etc. It's confusing and, frankly, why not use something like classes to hold all this stuff?<br />
<br />
Thanks for reading my first post, and I hope you enjoy it.]]></description>
		<pubDate>Mon, 18 Aug 2008 23:48:21 +0000</pubDate>
		<guid><![CDATA[http://www.dreamincode.net/forums/index.php?app=blog&blogid=203&showentry=873]]></guid>
	</item>
</channel>
</rss>