<?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>Deadcore</title>
	<atom:link href="http://www.deadcore.co.uk/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.deadcore.co.uk</link>
	<description>It&#039;s all in your head</description>
	<lastBuildDate>Sat, 04 Feb 2012 22:28:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>VB &#8211; Thread Pooling Part II</title>
		<link>http://www.deadcore.co.uk/?p=57&#038;utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=vb-thread-pooling-part-ii</link>
		<comments>http://www.deadcore.co.uk/?p=57#comments</comments>
		<pubDate>Sat, 04 Feb 2012 22:16:14 +0000</pubDate>
		<dc:creator>Jack</dc:creator>
				<category><![CDATA[Programing Tutorials]]></category>
		<category><![CDATA[Visual Basic .Net]]></category>
		<category><![CDATA[basic]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[IP]]></category>
		<category><![CDATA[mod]]></category>
		<category><![CDATA[Network]]></category>
		<category><![CDATA[Pool]]></category>
		<category><![CDATA[Port]]></category>
		<category><![CDATA[Scan]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[Socket]]></category>
		<category><![CDATA[Thread]]></category>
		<category><![CDATA[Threading]]></category>
		<category><![CDATA[vb]]></category>
		<category><![CDATA[visual]]></category>

		<guid isPermaLink="false">http://www.deadcore.co.uk/?p=57</guid>
		<description><![CDATA[So what calls for a part two on this project? The fact we can only have 64 parral threads :/. If you havent already ready my first tutorial go and read it http://www.deadcore.co.uk/?p=21. So how can we make something thread out and have &#8230;<p class="read-more"><a href="http://www.deadcore.co.uk/?p=57">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>So what calls for a part two on this project? The fact we can only have 64 parral threads :/. If you havent already ready my first tutorial go and read it <a href="http://www.deadcore.co.uk/?p=21">http://www.deadcore.co.uk/?p=21</a>. So how can we make something thread out and have more then 64 threads? Well&#8230;<br />
<span id="more-57"></span></p>
<p>Well with some slight modifications to the code we get this:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">&nbsp;
<span style="color: #E56717; font-weight: bold;">Public</span> <span style="color: #E56717; font-weight: bold;">Sub</span> ThreadPoolCallBack(<span style="color: #151B8D; font-weight: bold;">ByVal</span> state <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Object</span>)
<span style="color: #151B8D; font-weight: bold;">Dim</span> threadIndex <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span> = CType(state, <span style="color: #F660AB; font-weight: bold;">Integer</span>)
<span style="color: #151B8D; font-weight: bold;">RaiseEvent</span> ThreadStarted(threadIndex, state)
ScanPort(state)
&nbsp;
<span style="color: #8D38C9; font-weight: bold;">If</span> remainingWorkItems = 0 <span style="color: #8D38C9; font-weight: bold;">Then</span>
ManualResetEvent.<span style="color: #151B8D; font-weight: bold;">Set</span>()
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span>
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Sub</span>
&nbsp;
<span style="color: #E56717; font-weight: bold;">Private</span> <span style="color: #E56717; font-weight: bold;">Sub</span> ScanPort(<span style="color: #151B8D; font-weight: bold;">ByVal</span> state <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Object</span>)
<span style="color: #151B8D; font-weight: bold;">Dim</span> EPhost <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #E56717; font-weight: bold;">New</span> System.Net.IPEndPoint(_HostIP, state)
<span style="color: #151B8D; font-weight: bold;">Dim</span> mySocket <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #E56717; font-weight: bold;">New</span> System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp)
Try
mySocket.Connect(EPhost)
<span style="color: #8D38C9; font-weight: bold;">If</span> mySocket.Connected <span style="color: #8D38C9; font-weight: bold;">Then</span>
<span style="color: #151B8D; font-weight: bold;">RaiseEvent</span> PortFound(state, portState.<span style="color: #151B8D; font-weight: bold;">Open</span>)
mySocket.<span style="color: #8D38C9; font-weight: bold;">Close</span>()
<span style="color: #8D38C9; font-weight: bold;">Else</span>
<span style="color: #151B8D; font-weight: bold;">RaiseEvent</span> PortFound(state, portState.closed)
mySocket.<span style="color: #8D38C9; font-weight: bold;">Close</span>()
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span>
&nbsp;
Catch ex <span style="color: #151B8D; font-weight: bold;">As</span> Exception
<span style="color: #151B8D; font-weight: bold;">RaiseEvent</span> PortFound(state, portState.closed)
mySocket.<span style="color: #8D38C9; font-weight: bold;">Close</span>()
<span style="color: #8D38C9; font-weight: bold;">End</span> Try
&nbsp;
remainingWorkItems -= 1
&nbsp;
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Sub</span>
&nbsp;
<span style="color: #E56717; font-weight: bold;">Public</span> <span style="color: #E56717; font-weight: bold;">Sub</span> Start()
&nbsp;
<span style="color: #151B8D; font-weight: bold;">Dim</span> objLock1 <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Object</span> = <span style="color: #E56717; font-weight: bold;">New</span> <span style="color: #F660AB; font-weight: bold;">Object</span>
<span style="color: #8D38C9; font-weight: bold;">For</span> i = _iStartPort <span style="color: #8D38C9; font-weight: bold;">To</span> _iEndPort
SyncLock objLock1
remainingWorkItems += 1
<span style="color: #8D38C9; font-weight: bold;">End</span> SyncLock
ThreadPool.QueueUserWorkItem(AddressOf ThreadPoolCallBack, i)
<span style="color: #8D38C9; font-weight: bold;">Next</span>
&nbsp;
ManualResetEvent.WaitOne()
&nbsp;
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Sub</span></pre></div></div>

<p>&nbsp;</p>
<p>So whats happening here? We are wrapping the thread in &#8220;ThreadPoolCallBack&#8221; sub routine. And when we are assigning the threads we generate a counter</p>
<p><em><strong>SyncLock objLock1</strong></em><br />
<em><strong>remainingWorkItems += 1</strong></em><br />
<em><strong>End SyncLock</strong></em></p>
<p>After each thread has completed it decreases it by one and when the counter is at 0 the thread which this lands on says &#8220;Hey were done <img src='http://www.deadcore.co.uk/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> &#8221; and the program wraps itself up. Simple really&#8230; Don&#8217;t worry I have uploaded the whole source code soo&#8230; just go copy that if you must ¬_¬</p>
<p>Download link: http://deadcore.co.uk/download/Port%20Scanner%20-%20Thread%20Pooling%20No%20limit.zip</p>
<p>Have a good one</p>
<p>Jack</p>
]]></content:encoded>
			<wfw:commentRss>http://www.deadcore.co.uk/?feed=rss2&#038;p=57</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux &#8211; Back up script</title>
		<link>http://www.deadcore.co.uk/?p=51&#038;utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=linux-back-up-script</link>
		<comments>http://www.deadcore.co.uk/?p=51#comments</comments>
		<pubDate>Sun, 08 Jan 2012 21:43:03 +0000</pubDate>
		<dc:creator>Jack</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Backup]]></category>
		<category><![CDATA[basic]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mod]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[Network]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://www.deadcore.co.uk/?p=51</guid>
		<description><![CDATA[So my website got hacked about 2 years ago and that really put a hole in my motivation to run this website and opened my eyes on the importance of back up. So after leaving my website for 6 months &#8230;<p class="read-more"><a href="http://www.deadcore.co.uk/?p=51">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>So my website got hacked about 2 years ago and that really put a hole in my motivation to run this website and opened my eyes on the importance of back up. So after leaving my website for 6 months I decided to use it for a gaming clan website (www.clan.deadcore.co.uk) but knowing my website has been hacked once I built a small back up script and I thought I would share the code<br />
<span id="more-51"></span><br />
(I have blanked out some spots because its sensitive information):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Deleting old source files...&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">find</span> ~<span style="color: #000000; font-weight: bold;">/</span>Path to Backup File<span style="color: #000000; font-weight: bold;">/*</span> <span style="color: #660033;">-mtime</span> +<span style="color: #000000;">4</span> <span style="color: #660033;">-exec</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Delete old source files DONE&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Back up begining...&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-zcvf</span> ~<span style="color: #000000; font-weight: bold;">/</span>Path to Backup folder<span style="color: #000000; font-weight: bold;">/`</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>Y-<span style="color: #000000; font-weight: bold;">%</span>m-<span style="color: #000000; font-weight: bold;">%</span>d<span style="color: #000000; font-weight: bold;">`</span>.tar.gz ~<span style="color: #000000; font-weight: bold;">/</span>Folder to back up
mysqldump <span style="color: #660033;">-u</span> user_name <span style="color: #660033;">-h</span> localhost password <span style="color: #660033;">--all-databases</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">gzip</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; ~<span style="color: #000000; font-weight: bold;">/</span>Backup<span style="color: #000000; font-weight: bold;">/</span>Database<span style="color: #000000; font-weight: bold;">/</span>db-<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>Y-<span style="color: #000000; font-weight: bold;">%</span>m-<span style="color: #000000; font-weight: bold;">%</span>d<span style="color: #000000; font-weight: bold;">`</span>.sql.gz</pre></div></div>

<p>So how this backup script works is it deletes the oldest back up(5 day cycle). It then takes a folder, time stamps it and chucks it into a backup folder. The mysql dump works by having a user assigned to the database with only view privileges; so any new database made, I stick it with the backup user and it backs up the database. Easy, quick and efficient.</p>
<p>All that wraps up with a cron <em><strong>&#8220;bash ~/Path to file/file name&#8221;</strong></em> this automates the whole processes.</p>
<p>Nothing fancy but it does nicely for me,</p>
<p>Jack</p>
]]></content:encoded>
			<wfw:commentRss>http://www.deadcore.co.uk/?feed=rss2&#038;p=51</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VB &#8211; Thread pooling Part I</title>
		<link>http://www.deadcore.co.uk/?p=21&#038;utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=vb-thread-pooling-part-i</link>
		<comments>http://www.deadcore.co.uk/?p=21#comments</comments>
		<pubDate>Sat, 07 Jan 2012 18:09:15 +0000</pubDate>
		<dc:creator>Jack</dc:creator>
				<category><![CDATA[Programing Tutorials]]></category>
		<category><![CDATA[Visual Basic .Net]]></category>
		<category><![CDATA[IP]]></category>
		<category><![CDATA[Network]]></category>
		<category><![CDATA[Pool]]></category>
		<category><![CDATA[Port]]></category>
		<category><![CDATA[Scan]]></category>
		<category><![CDATA[Socket]]></category>
		<category><![CDATA[Thread]]></category>
		<category><![CDATA[Threading]]></category>

		<guid isPermaLink="false">http://www.deadcore.co.uk/?p=21</guid>
		<description><![CDATA[So with programming I like to look at it with two perspectives; linear and threaded programming. Taking from the word of Adam Smith (And if you don&#8217;t know who he is then look up &#8220;Pin Factory&#8221;) many men doing smaller &#8230;<p class="read-more"><a href="http://www.deadcore.co.uk/?p=21">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>So with programming I like to look at it with two perspectives; linear and threaded programming. Taking from the word of Adam Smith (And if you don&#8217;t know who he is then look up &#8220;Pin Factory&#8221;) many men doing smaller jobs is better then one man doing all the jobs&#8230; Or something like that. This is what Visual Basic thread pooling is much about; taking a repetitive processes and getting many people (or threads) to do many of them at the same time. Take for example a port scanner; we can have linear program that simply does the following:<br />
<span id="more-21"></span></p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">    <span style="color: #E56717; font-weight: bold;">Sub</span> Main()
        <span style="color: #8D38C9; font-weight: bold;">For</span> i = 0 <span style="color: #8D38C9; font-weight: bold;">To</span> 100
            <span style="color: #151B8D; font-weight: bold;">Dim</span> PortHost <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #E56717; font-weight: bold;">New</span> System.Net.IPEndPoint(System.Net.Dns.GetHostEntry(<span style="color: #800000;">&quot;127.0.0.1&quot;</span>).AddressList(0), i) <span style="color: #008000;">'Setting up the IP address and the port
</span>            <span style="color: #151B8D; font-weight: bold;">Dim</span> mySocket <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #E56717; font-weight: bold;">New</span> System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp) <span style="color: #008000;">'Setting up the Socket to call the port from
</span>            Try
                mySocket.Connect(PortHost) <span style="color: #008000;">'Calling the port through the socket
</span>                <span style="color: #008000;">'Handling the call back
</span>                <span style="color: #8D38C9; font-weight: bold;">If</span> mySocket.Connected <span style="color: #8D38C9; font-weight: bold;">Then</span>
                    Console.WriteLine(<span style="color: #800000;">&quot;Port {0} is Open&quot;</span>, i)
                    mySocket.<span style="color: #8D38C9; font-weight: bold;">Close</span>()
                <span style="color: #8D38C9; font-weight: bold;">Else</span>
                    Console.WriteLine(<span style="color: #800000;">&quot;Port {0} is Closed&quot;</span>, i)
                    mySocket.<span style="color: #8D38C9; font-weight: bold;">Close</span>()
                <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span>
            Catch ex <span style="color: #151B8D; font-weight: bold;">As</span> Exception
                Console.WriteLine(<span style="color: #800000;">&quot;Port {0} is Closed&quot;</span>, i)
                mySocket.<span style="color: #8D38C9; font-weight: bold;">Close</span>()
            <span style="color: #8D38C9; font-weight: bold;">End</span> Try
        <span style="color: #8D38C9; font-weight: bold;">Next</span>
    <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Sub</span></pre></div></div>

<p>This way works&#8230; its just not very efficient hence along comes the thread pool. A thread pool is like a bucket where the master thread puts packets of data for slave threads to come along and complete.</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">Imports System.Threading
&nbsp;
Module Module1
&nbsp;
    <span style="color: #008000;">'Require to thread an application
</span>
    <span style="color: #E56717; font-weight: bold;">Sub</span> Main()
&nbsp;
        <span style="color: #151B8D; font-weight: bold;">Dim</span> ThreadingEvents(40) <span style="color: #151B8D; font-weight: bold;">As</span> ManualResetEvent
        <span style="color: #151B8D; font-weight: bold;">Dim</span> iCounter <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span> = 0
        <span style="color: #8D38C9; font-weight: bold;">For</span> i = 50 <span style="color: #8D38C9; font-weight: bold;">To</span> 90
            ThreadingEvents(iCounter) = <span style="color: #E56717; font-weight: bold;">New</span> ManualResetEvent(<span style="color: #00C2FF; font-weight: bold;">False</span>)
            ThreadPool.QueueUserWorkItem(AddressOf Scan, i)
            iCounter += 1
        <span style="color: #8D38C9; font-weight: bold;">Next</span>
&nbsp;
        ManualResetEvent.WaitAll(ThreadingEvents)
        Console.Read()
    <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Sub</span>
&nbsp;
    <span style="color: #E56717; font-weight: bold;">Public</span> <span style="color: #E56717; font-weight: bold;">Sub</span> Scan(<span style="color: #151B8D; font-weight: bold;">ByVal</span> state <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Object</span>)
        <span style="color: #151B8D; font-weight: bold;">Dim</span> port <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span> = state
        <span style="color: #151B8D; font-weight: bold;">Dim</span> PortHost <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #E56717; font-weight: bold;">New</span> System.Net.IPEndPoint(System.Net.Dns.GetHostEntry(<span style="color: #800000;">&quot;127.0.0.1&quot;</span>).AddressList(0), port) <span style="color: #008000;">'Setting up the IP address and the port
</span>        <span style="color: #151B8D; font-weight: bold;">Dim</span> mySocket <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #E56717; font-weight: bold;">New</span> System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp) <span style="color: #008000;">'Setting up the Socket to call the port from
</span>        Try
            mySocket.Connect(PortHost) <span style="color: #008000;">'Calling the port through the socket
</span>            <span style="color: #008000;">'Handling the call back
</span>            <span style="color: #8D38C9; font-weight: bold;">If</span> mySocket.Connected <span style="color: #8D38C9; font-weight: bold;">Then</span>
                Console.WriteLine(<span style="color: #800000;">&quot;Port {0} is Open&quot;</span>, port)
                mySocket.<span style="color: #8D38C9; font-weight: bold;">Close</span>()
            <span style="color: #8D38C9; font-weight: bold;">Else</span>
                Console.WriteLine(<span style="color: #800000;">&quot;Port {0} is Closed&quot;</span>, port)
                mySocket.<span style="color: #8D38C9; font-weight: bold;">Close</span>()
            <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span>
        Catch ex <span style="color: #151B8D; font-weight: bold;">As</span> Exception
            Console.WriteLine(<span style="color: #800000;">&quot;Port {0} is Closed&quot;</span>, port)
            mySocket.<span style="color: #8D38C9; font-weight: bold;">Close</span>()
        <span style="color: #8D38C9; font-weight: bold;">End</span> Try
    <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Sub</span>
&nbsp;
<span style="color: #8D38C9; font-weight: bold;">End</span> Module</pre></div></div>

<div id="attachment_26" class="wp-caption alignnone" style="width: 310px"><a href="http://www.deadcore.co.uk/wp-content/uploads/2012/01/Port.png"><img class="size-medium wp-image-26" title="Port Scan Threaded" src="http://www.deadcore.co.uk/wp-content/uploads/2012/01/Port-300x151.png" alt="Port Scan Threaded" width="300" height="151" /></a><p class="wp-caption-text">A threaded port scan</p></div>
<p>So what&#8217;s going on here? Simply, to que things in the thread pool you need to have an address. In this case we outsource our scan routine to a different Sub and have our main program just loop through adding it to the pool. Some basic stuff has to be implemented like <strong><em>&#8220;Dim ThreadingEvents(40) As ManualResetEvent&#8221;</em></strong> creates an array of thread statues for the <em><strong>&#8220;ManualResetEvent.WaitAll(ThreadingEvents)&#8221;</strong></em> to tell the program when its done. Finally we exploit a feature in the thread pooling where you have to assign an index to the thread <strong><em>&#8220;ThreadPool.QueueUserWorkItem(AddressOf Scan, i)&#8221;. i </em></strong>is the index but we parse it into the Sub Scan <strong><em>&#8220;Public Sub Scan(ByVal state As Object)&#8221;</em></strong> where state is our port&#8230; and that&#8217;s it. A multi threaded application which is a lot faster then your normal application.</p>
<p><span style="text-decoration: underline;"><strong>There is one small problem though. If you increase the maximum scans above 64 iterations (the for loop, loops more then 64 times) the application crashes and I am going to cover that in part 2.</strong></span></p>
<p>Have a good one</p>
<p>Jack</p>
<p>P.S. This application should only be used in controlled environment and I accept <strong>no</strong> liability for misuse of this application. Use at your own risk. I only used this program to demonstrate how threading can be done.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.deadcore.co.uk/?feed=rss2&#038;p=21</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VB &#8211; The Prime Number Generator</title>
		<link>http://www.deadcore.co.uk/?p=5&#038;utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=vb-the-prime-number-generator</link>
		<comments>http://www.deadcore.co.uk/?p=5#comments</comments>
		<pubDate>Wed, 28 Dec 2011 14:30:33 +0000</pubDate>
		<dc:creator>Jack</dc:creator>
				<category><![CDATA[Programing Tutorials]]></category>
		<category><![CDATA[Visual Basic .Net]]></category>
		<category><![CDATA[basic]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[mod]]></category>
		<category><![CDATA[number]]></category>
		<category><![CDATA[prime]]></category>
		<category><![CDATA[vb]]></category>
		<category><![CDATA[visual]]></category>

		<guid isPermaLink="false">http://www.deadcore.co.uk/?p=5</guid>
		<description><![CDATA[So I wonder how hard it is to make a program that just finds prime numbers? Not hard actually, if we set a for loop running that takes a number and runs through all the divisions it could be. We then check if &#8230;<p class="read-more"><a href="http://www.deadcore.co.uk/?p=5">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>So I wonder how hard it is to make a program that just finds prime numbers? Not hard actually, if we set a for loop running that takes a number and runs through all the divisions it could be. We then check if any of those divisions output a remainder and all of them output a remainder, our number is prime.</p>
<p><span id="more-5"></span></p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">Imports System.IO
&nbsp;
Module Module1
&nbsp;
    <span style="color: #E56717; font-weight: bold;">Sub</span> Main()
        <span style="color: #151B8D; font-weight: bold;">Dim</span> iPrimeNumeberLimit <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span> = 0
        Console.Write(<span style="color: #800000;">&quot;What prime number do you wish to go upto: &quot;</span>)
        iPrimeNumeberLimit = Console.ReadLine()
        Using writer <span style="color: #151B8D; font-weight: bold;">As</span> StreamWriter = <span style="color: #E56717; font-weight: bold;">New</span> StreamWriter(<span style="color: #800000;">&quot;C:\Users\Jack\Desktop\PrimeNumbers.txt&quot;</span>)
            <span style="color: #8D38C9; font-weight: bold;">For</span> i <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span> = 2 <span style="color: #8D38C9; font-weight: bold;">To</span> iPrimeNumeberLimit
                <span style="color: #8D38C9; font-weight: bold;">If</span> CheckPrimeNumber(i) = <span style="color: #00C2FF; font-weight: bold;">True</span> <span style="color: #8D38C9; font-weight: bold;">Then</span>
                    writer.WriteLine(iPrimeNom &amp;amp; <span style="color: #800000;">&quot; =&amp;gt; &quot;</span> &amp;amp; i)
                    iPrimeNom += 1
                    Console.WriteLine(i)
                <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span>
            <span style="color: #8D38C9; font-weight: bold;">Next</span>
        <span style="color: #8D38C9; font-weight: bold;">End</span> Using
&nbsp;
        Console.Read()
    <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Sub</span>
&nbsp;
    <span style="color: #E56717; font-weight: bold;">Private</span> <span style="color: #E56717; font-weight: bold;">Function</span> CheckPrimeNumber(<span style="color: #151B8D; font-weight: bold;">ByVal</span> iNumber <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>) <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Boolean</span>
        <span style="color: #151B8D; font-weight: bold;">Dim</span> upper <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span> = iNumber / 2
        <span style="color: #8D38C9; font-weight: bold;">For</span> i <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span> = 2 <span style="color: #8D38C9; font-weight: bold;">To</span> upper
            <span style="color: #8D38C9; font-weight: bold;">If</span> iNumber <span style="color: #151B8D; font-weight: bold;">Mod</span> i = 0 <span style="color: #8D38C9; font-weight: bold;">Then</span>
                Return <span style="color: #00C2FF; font-weight: bold;">False</span>
                <span style="color: #E56717; font-weight: bold;">Exit</span> <span style="color: #E56717; font-weight: bold;">Function</span>
            <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span>
        <span style="color: #8D38C9; font-weight: bold;">Next</span>
        Return <span style="color: #00C2FF; font-weight: bold;">True</span>
    <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span>
&nbsp;
<span style="color: #8D38C9; font-weight: bold;">End</span> Module</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.deadcore.co.uk/?feed=rss2&#038;p=5</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

