Category Archives: Programming

The Halving Algorithm and the Guessing Game for the TI-83/TI-84

The first task for each student is to write a program where the computer thinks of a number, and the student gets to guess the number (and the program says if the guess is too high, too low, or just right). The program keeps soliciting the user for a guess until the correct answer has been provided. On the TI-83, to have the computer pick a number from 1 to 1000, you use the random number generator under Math->Prb->randInt. The following line of code is how the Ti-83 picks a number from 1 to 1000, and stores it into the variable A:

randInt(1,1000) -> A

I will leave the rest of the program writing to you. You’ll use Lbl, if, Input, math tests (>, <) and Disp.

I originally got the idea for a number guessing program when I was 12. I got it from the book, Basic Computer Games. This book made quite an impression upon me, so it is a pleasure to pass along a snippet (click on the image below to see page 75):

guess

The second task for the student is to think of the best way to guess numbers. For example, consider that I am thinking of a number from 1 to 1000, and I ask you to guess that number (and I will tell you if you are too high or too low). Two bad ways to go about guessing would be to begin at one and count up to 1000 till you got it, or to begin and 1000 and count down. There must be a better way. Find that way. And then come up with a statement that will tell me the most number of guesses it would take for a person to figure out the secret number.

Do the same thing as if the number to be guessed is between 1 and 10.

Then do it again for a number between 1 and 100. Then 1 and 1000. Can you find a general pattern that will tell you the maximum number of guesses it would take to find the hidden number for any range?

Bonus Assignment: This following line of thinking was not covered in our last class. But consider what it would be like to play the game of Guess in reverse… bear with me, and I’ll try to explain. Imagine that instead of randomly picking a number, the computer randomly picks “too high” or “too low” at each guess. That is, the computer itself does not know the secret number, but discovers it with the guesser. Can any number be written as a sequence of “too high” and “too low” statements? Don’t worry if this Bonus Assignment makes no sense. But if you follow the gist, have fun thinking about it. And welcome to the world of open-ended questions.

Encrypting My Thoughts by Encrypting Twitter Messages

Twitter has become a kind of extension to my brain. And now, like a brain, my Twitter messages are only accessible to me. But it didn’t start this way.

In the beginning, what I wrote on Twitter was a simple index into my latest thoughts. To the outside observer (and especially to the unsympathetic reader) the appearance of my thoughts appeared thoughtless. I was accused of thoughtless thinking. But I imagine that thinking, for many of us, would externally appear to be an undirected or thoughtless activity, and maybe my thinking is. Regardless, thinking is a mostly private affair, and when it was opened up to the world around me, it came off as a collection of unrelated and even crass ciphers. As I began to spread my thoughts, the offense spread.

I never thought that my Twitter account was just for me. But I acted like it was, and so my thoughts were escaping my brain and making it into the wild, but I was thinking like they were still in my head.

My rational was simple. I was writing sentences for the benefit of wanting to recall them later — they were for me to remember (and I still want that Twitter-benefit). But now I am using Twitter as my memories according to this new dictum: Not everything I want to remember do I want to share.

Twitter has evolved for me. First it was a noteworthy little place on the web, and I had an account. Then I tied it to my cell phone and I could easily send messages and track ideas. Then I tied it to my Facebook and I could update my Facebook from my cell phone. I had lots of friends and social media was good to me. But then I wrote more things. And then Twitter was not so good. Soon, my social media was antisocial. So I deleted my Facebook, kicked everyone off of my Twitter account, pulled everything back, and made all my ideas hidden and private.

My Twitter-Cards are now held close; every madly-scribbled thought is a note to me, or a memo to myself. These sentences live in my auxiliary storage–Twitter is an extension of my memory. But Twitter is different than normal memories; I can search these auxiliary sentences and go back to my thoughts and deliberately pick up where I left off in my thinking. My Twitter account is not just an index into my latest thoughts, but is a placeholder for a whole history of thoughts.

My previous mistake was that I was thinking too loudly.

Now I am thinking quietly. I am not claiming to be profound (probably I need to encrypt my thoughts just to spare the world). In fact, just as my thoughts are locked up behind my skull, my Twitter-Thoughts now live behind a mathematical barrier I thought up.

That’s the setup for the cryptography code I am about to show you. Now that my Twitter is closed, I thought: What if some of these thoughts escape? I write some pretty intense things that aren’t safe to share. I still want to use up my 140 character space, but I want some encryption.

I can now encrypt my Twitter comments. I wrote a simple encryption, nothing fancy, just enough to block the casual observer (especially if I leave my Twitter account up on a computer).

Here is the code for that (I had to sacrifice one character to pull this off — my encrypted tweets are thus limited to 139 characters, with one character marking the fact that it is encrypted):

/// <summary>
    /// pw is optional.  If not supplied, we just return the plain text passed in.
    /// Encrypt the plain text, then add a "*" to the end of the string (indicating a encrypted string)
    /// </summary>
    /// <param name="plain"></param>
    /// <param name="pw"></param>
    /// <returns></returns>
    public static string enc(string plain, string pw)
    {
        const byte space = 32;
        const int elements = 126 - space;
        string res = plain;
        if (pw != null && pw != string.Empty)
        {
            byte[] key = Encoding.ASCII.GetBytes(pw);
            byte[] data = Encoding.ASCII.GetBytes(plain);

            int k = 0;
            for (int i = 0; i < data.Length; i++)
            {
                int e = data[i] - space;
                e = (e + key[k]) % elements;
                data[i] = Convert.ToByte(e);
                data[i] += space;
                k++;
                if (k >= key.Length)
                    k = 0;
            }

            res = Encoding.ASCII.GetString(data) + "*";
        }
        return res;
    }
    /// <summary>
    /// Any string that ends in '*' is treated as encrypted.
    /// But we only decrypt it if you pass in a password (and, FYI, the '*' is not part of the encryption).
    /// </summary>
    /// <param name="enc"></param>
    /// <param name="pw"></param>
    /// <returns></returns>
    public static string dec(string enc, string pw)
    {
        const byte space = 32;
        const int elements = 126 - space;
        string res = enc;
        if (pw != null && pw != string.Empty)
        {
            if (enc[enc.Length - 1] == '*')
            {
                byte[] key = Encoding.ASCII.GetBytes(pw);
                byte[] data = Encoding.ASCII.GetBytes(enc.Substring(0, enc.Length - 1));
                int k = 0;
                for (int i = 0; i < data.Length; i++)
                {
                    int d = data[i] - space;
                    d = d - key[k];
                    while (d < 0)
                        d += elements;
                    d = d % elements;
                    d += space;
                    data[i] = (byte)d;
                    k++;
                    if (k >= key.Length)
                        k = 0;
                }
                res = Encoding.UTF8.GetString(data);
            }
        }
        return res;
    }

And here you see how these Twitter messages look when encoded. I map everything to the ASCII printable character set. That’s important to know. I don’t have to worry about hitting those reserved Twitter characters. I also have it so that the encrypted text is as long as the plain text. Except for the one character that I sacrifice in order to notate that a message is encrypted (which I don’t have to do, but I have my reasons), I get to keep using Twitter as normal.

If you got this far, you may want to use this encryption for yourself. In that case, you have some options. The fastest and easiest option is to use my stand-alone crypt program [see my later article for download instructions].

Optionally, I have my own Twitter program I wrote. To use the encryption code I have offered here, you need to use this or some other custom Twitter software. You can write your own (and add the above code to it), or you can use my free MicroSpeak140. Click the following link to read more about MicroSpeak140 (where you can also get all the code).

Now think. And with encrypted Twitter, you can think quietly like you have always done.

About the Method and the Encryption Strength
Someone who is acquainted with cryptographic methods may detect a weakness of what I have implemented. I will address that below, and I will give a fairly substantial defense. Yet, even if my defense is weak and my method is poor, let me set the context: I’m not trying to protect Fort Knox. My brain is not a vault of treasures. I am not trying to encrypt government secrets. I just want a little bit of bone structure to encase some sensitive tissues. My encryption scheme fits the bill.

Mine is a Vigenere Cipher (which, as you will read, is a improvement upon the older Caesar Cipher). The Vigenere method meets my five chief requirements: 1. Most obviously, I want to change the plain text (that is, I want to obscure the original message), 2. I want to use a password scheme so that each use gets different results based on the password, 3. I want to be able to use the same password to recover the plain text, 4. I want to obscure the frequencies of the English letters in the plain text, and finally, 5. As important as items 1 through 4, I want the encrypted text length to be the same or less than the length of the plain text (some encryption schemes yield an encrypted text that is longer than the plain text).

Now, we know that a Viegenre cipher is mathematically breakable if the key length is known and if your attacker is the NSA (or is a sufficiently motivated geek who is extremely patient and determined). That is, someone would have to want your memories to try to crack them, and it would require some good effort on their part (the Twitter equivalent to being captured and interrogated).

Ah, but, you can use a password that is the same length as the message you are encoding! After all, with Twitter, we are talking about messages not more than 140 characters long; we have a reasonable shot at picking memorable sentences as pass-phrases. Furthermore, you can use any number of sentences as pass-phrases. That is, you don’t have to use the same password (or pass-phrase) for every single Tweet. And, at this point, using passwords that run the length of your message (which you could database), you have a nearly unbreakable cipher.

But that means if you forget your passwords, you lose your memories (the Twitter equivalent to Alzheimer’s).

If you still want something stronger, you can try an AES and encrypt a string so that it comes out equal length — for more on this subject, look here. I did not take that route as I wasn’t that interested (nor sufficiently motivated), but with OpenSSL, these sorts of things are not so hard.

How to deploy a new MVC 4 or MVC 5 app to and older IIS 6 server

You can install newer MVC apps on an older Windows 2003 server (it can be done very easily). You must simply configure your Web.Config with a few settings (as shown below) and you may need to go into the Windows file explorer and grant the correct rights to your web user for the path you install to. Ignore the bit about the ASP.NET user (that’s for something unrelated to what I am showing you here):

Notice I added customErrors with the value, mode=”Off” and I added a whole section called system.codedom section.

You will also need to configure your project by right clicking on your project, and selecting “Add Deployable Dependencies…” and then check all the boxes in the dialog that follows.

Then, highlight and select all the references in your new _bin_deployableAssemblies and set the properties for all of the to either “Copy always” or “Copy if newer”

Finally, make sure that Global.asax is added to the list of files you can access. This is done under IIS under the Virtual directory you care about (where you installed your web site) or under the web site itself.

Programming by existence

If something is there, it has existence.

In C# this makes all the difference. I realized this morning that I don’t wire-up relationships, but the C# MVC system works on the basis of mere existence.

If a filename with a certain name exists, it is accessed by a controller. In the Data Entity Model, the existence of a table name is mapped to a class name. By existence. I don’t tell the C# system what to associate with what. I just create the item, and its existence makes it alive.

C# MVC programming is programming by existence.

It is also programming by name. When something exists, it must be named (a file name, a class name, a property name, etc.). If it exists, its name is how it relates to the system.

C# MVC programming is programming by existence with right naming.

This is eloquent.

Write a Windows Console Application in C# that uses Twitter (and do it in 30 minutes or less)

I decided to write a program called “microSpeak140″ that would be a Windows command-line tool to let me post Twitter updates. The reason for such a seemingly useless tool comes from an idea I had about subscription-based communication to unmanned devices, which naturally led to the thought about implementing an Erlange-like language distributed over Twitter. Hence I started down this path. But none of that is terribly relevant to this post, so I’ll skip all the “whys?” and go right to the “how?”

Step 1: Pick a name for your program (I picked “microSpeak140″).

Step 2: Go to Twitter developer’s site and register the name you picked: https://dev.twitter.com/apps/

If you are like me, you may want to skip this step and go right to the TCP/IP interface (thinking, “just tell me what port to connect to and I’ll start talking”). But it’s not like that. Twitter won’t let you near their servers so easily; there is no skipping this really simple step–it only takes a minute and it is free. So go register your program name at https://dev.twitter.com/apps/ and grab the ASCII strings they give you.

Namely, they will give you two string, the “Consumer key” and the “Consumer secret”. These are the two ASCII strings we need to complete the following steps (you will add them to the Speak140 object). You need them for Twitter to let your program talk to their servers, and you will put them into your C# code file (again, in this case, Speak140.cs).

Step 3: Download the .NET library, TweetSharp from TweetSharp (or use NuGet in Visual Studio).

Step 4: Create a new project in Visual Studio, a Visual C# > Windows > Console Application (give it the same name — in my case, again, this is microSpeak140.cs). Note, I also like to rename the default “program.cs” to “microSpeak140.cs”

Step 5: Add a ref to TweetSharp (which you downloaded in Step 3).

Step 6: Create your Main program as follows (inside program.cs or, in my case, microSpeak140.cs):

using System;
namespace microspeak140
{
    class microSpeak140
    {
        static void Main(string[] args)
        {

            int len = args.Length;
            int start = 0;
            string pw = string.Empty;

            
            if (len > 0 && args[start] == "-P")
            {
                if (args.Length > 1)
                {
                    pw = args[1];
                    start = 2;
                    len -= 2;
                }
            }

            if (len > 0 && len < 3)
            {
                Speak140 t = new Speak140();
                if (len == 2 && args[start] == "-W")
                    t.theirWall(args[start+1], 0, pw);
                else if (len == 1 && args[start] == "-F")
                    t.iFollow();
                else if (len == 1 && args[start] == "-M")
                    t.followMe();
                else if (len == 1 && args[start] == "-W")
                    t.myWall(0, pw);
                else if (len == 1) // they are leaving a comment.
                    t.Say(args[start], true, pw);
            }
            else
            {
                Console.WriteLine("Usage: microSpeak140 [-P password] <-F> | ");
                Console.WriteLine("            <-W [name of someone else]> | ");
                Console.WriteLine("            <\"message to send (max 140 character)\">");
                Console.WriteLine();
                Console.WriteLine("       -P   Pass in -P followed by a password if you want"); 
                Console.WriteLine("            to encrypt or decrypt messages.");
                Console.WriteLine("       -W   Show me what is on my wall, or [someone else]'s wall.");
                Console.WriteLine("       -F   List the people I follow.");
                Console.WriteLine("       -M   List the people that follow me.");
            }
        }
    }
}

Step 9: Include this object I created: Speak140.cs.
Speak140.cs is my own wrapper around the Twitter DLLs. I had a very narrow purpose for my console application, so this object helps me to zero-in on the narrow set of functions I really wanted to leverage, along with helping me with Twitter key management and encryption. I’ll have more to say about encryption below–by which I mean the option to encrypt the messages you post to Twitter.

Step 10: Build your program.
Note: you may need to go to Project->microSpeak140 properties->Application and set the target framework as .NET 3.0 (i.e., not the default 4.0). Then build it. Then switch it back to 4.0 and try again.

Step 11: Drop down to a command window, go to the build directory, and run it:

    microSpeak140  "At coffee house writing Twitter app in 30 minutes or less"

Step 12: Encrypt your comments
You will notice in the program that I provide a command-line option for a password. This allows you to encrypt your comments. But I will save the details about that for another post. [Indeed, read my later article here for a discussion of encrypting and decrypting messages using MicroSpeak140].

Step 13: What Next: Make it your own!
Maybe you will want to add your own reader functions to the Speak140 object. Or, it might be a good idea to add code to use the registry as opposed to files, and thus handle multiple twitter accounts. You have all the code, so enjoy it and make it your own.

Free Sequence Diagram PNG and PDF Generator

I want to share a link quite useful for explaining the sequence of events. In the technology world, there is a thing called a sequence diagram. A sequence diagram is useful for showing messages that pass back and forth between parties (in order, and sequenced).

For example, this little text here shows how I log onto my bank web site securely using SSL and certificates:

Me->www.MyBank.com: Browse to web site
note left of Me: I think I am attaching to my bnak
www.MyBank.com->Me: My bank sends an SSL Certificate
note right of www.MyBank.com: My bank got an SSL certificate file VeriSign or GoDaddy
note left of Me: I decrypting the cert using the Verisign public key.
Me->www.MyBank.com: Now I send my password
www.MyBank.com->Me: Display my bank account

Feeding that text into the FREE web site, http://www.websequencediagrams.com/, I get the following PNG image file showing the flow of messages:

This free web site is a wonderful resource, especially as sequence diagrams are useful for showing the relationships of events, messages and entities.

Customize the front page of a WordPress blog to merely list your articles

In my WordPress 3.x blog, I use the default theme, and now I want the main page to be a list of all my articles — nothing more, and nothing fancy. I don’t want any of the articles to have a preview paragraph, or the author, or the date and time of publication on the main page. None of that. I only want a list of all my articles, ordered by date, with each entry being a link to the entire article.

Here is how to do it:

1. Create a file called loop-index.php; it will get used instead of loop.php
2. Populate that file as per the loop-index.php file below
3. See my WordPress blog at http://www.mrrives.com/Gezer, to see how it looks

<?php
/*   THE LOOP - Rives Simple Version, cf. http://codex.wordpress.org/Function_Reference/get_template_part
     This file is called by index.php, get_template_part( 'loop', 'index' ), which does a PHP require() 
      for the first file that exists among these, in this priority:
        wp-content/themes/twentytenchild/loop-index.php then wp-content/themes/twentytenchild/loop.php
        wp-content/themes/twentyten/loop-index.php      then wp-content/themes/twentyten/loop.php
 */
?>

<h1><i>The Articles</i></h1>
<?php $pcounter = $wp_query->post_count; ?>
<?php $first_time = 1; ?>
<ol>
 <?php while ( have_posts() ) : the_post(); ?>
  <?php if ($first_time == 1): $first_time = 0; ?>
     <i>Ordered by date of publication with the most recent article listed first<br/>
      Date of last publication: <?php echo get_the_date(); ?><br/></i><br/>  
  <?php endif; ?>
  <div>
     <li value="&lt;?php echo $pcounter--; ?>">
     <h5 class="entry-title" style="font-size: 15px; font-weight: normal;">
     <a href="&lt;?php the_permalink(); ?>"
 STYLE="text-decoration: none" 
title="<?php printf( 
esc_attr__( 'Permalink to %s', 'twentyten' ), 
the_title_attribute( 'echo=0' ) ); ?>" 
rel="bookmark"><?php the_title(); ?></a></h5>
     </li>
   </div>

 <?php endwhile; ?>
</ol>

Pipe Stdin to a C# program and filter out data

I need a program that will filter command line input, and strip out CR+LF from any line that has a certain text.

Solution (in C#):

http://www.mrrives.com/Programming/Filter/Filter.cs

And the EXE file:

http://www.mrrives.com/Programming/Filter/Filter.exe

Here is the code (simple):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Filter
{
    class Filter
    {
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("FILTER: Parameter format not correct");
                return;
            }
            if (args[0] == "/?")
            {
                Console.WriteLine("Searches for a text string typed at the prompt or piped from another program");
                Console.WriteLine("");
                Console.WriteLine("FILTER \"string\"");
                Console.WriteLine("");
                Console.WriteLine("if string in a line, line is echoed without a CR+LF, otherwise it is.");
                return;
            }

            string s = string.Empty;
            try
            {
                while (System.Console.In.Peek() != -1)
                {
                    s = System.Console.In.ReadLine();
                    if (s.Contains(args[0]))
                        Console.Write(s);
                    else
                        Console.WriteLine(s);
                }
            }
            catch
            {

            }

        }
    }
}

Note, I was able to use the really nice web site, http://www.manoli.net/csharpformat/format.aspx to format my C# code into HTML

Part 1: Building an ActiveX Control in C# (with CAB file via CabArc)

I will show you how to write MyActiveX.cs, turn it into a DLL, place it on an HTML page and distribute it with a CAB file. But I will start in reverse order.

I will start with the HTML code and the CAB file. If you are going to build an ActiveX control in C#, then you need to be able to send it around (by the way, ActiveX controls only work in IE, not Chrome or Firefox, so you will only send it around to IE browsers).

When IE tries to access an ActiveX file (and it does not already have it on the hard drive), then the HTML code tells it to download a CAB and install it. For the sake of simplicity, let’s say your index.html file points to your ActiveX control this way:

<OBJECT id="MyActiveX" name="MyActiveX" 
classid="clsid:3026b51e-a3ff-4587-9ed2-36d7d527bbe6" VIEWASTEXT 
codebase="MyActiveX.cab#Version=1,0,2,0">

MyActiveX.cab is in the same folder as index.htm, and if the MyActiveX.dll is missing, then the CAB file is downloaded and installed. But you have to make that CAB file. To build the CAB file (which is like a ZIP file), you need to use the free CABARC program. You will pass it the name of the ActiveX, and a few support tools that will get stuffed in there with it. I will explain all the files in time, but here is the command line to create a CAB:

cabarc -s 6144 n MyActiveX.cab MyActiveX.dll RegNetX.exe setup.cmd MyActiveX.inf

(You can Download Microsoft’s cabarc.exe here).

This creates the CAB file, MyActiveX.cab, and inside it is the other four files. The final file, MyActiveX.inf, tells the CAB file what to do and what is inside it. It tells us that the ActiveX DLL will go to DestDir=11 (which is a secret Microsoft code meaning windows\sytem32). DestDir=11. Write it down. Use it. The -s command means to add on an extra 6144 bytes so that we can sign this CAB file when all is said and done (I will talk about signing CAB files in Part 2 or Part 3 — do not underestimate how important it is to sign your CAB file and ActiveX file if you want clients to be able to install and use your software).

Let’s look first at MyActiveX.inf (which tells the CAB file how to install on the client):


[Setup Hooks]
hook1=hook1

[hook1]
run=%EXTRACT_DIR%\setup.cmd

[version]
signature="$CHICAGO$"
AdvancedINF=2.0

[Add.Code]
MyActiveX.dll=MyActiveX.dll
MyActiveX.inf=MyActiveX.inf
setup.cmd=setup.cmd
RegNetX.exe=RegNetX.exe

[MyActiveX.dll]
file-win32-x86=thiscab
clsid={3026b51e-a3ff-4587-9ed2-36d7d527bbe6}
RegisterServer=no
FileVersion=1,0,2,0
DestDir=11

[MyActiveX.inf]
file=thiscab

[setup.cmd]
file=thiscab

[RegNetX.exe]
file=thiscab

If you inspect this file, you see that the CAB file will run setup.cmd as the install script when it arrives at a target machine. There is a good article on CAB files and hooks on the Microsoft web site, but that article fails to give you the extra steps required to release a .NET based ActiveX control. Still, go read it and get familiar with the subject, or keep moving along here and you’ll get the gist.

The reason you need all this specialty code for a .NET project, is because a CAB file uses RegSvr32 to register an ActiveX, and that won’t work for a .NET DLL. You need to use Microsoft’s RegAsm to register a .NET ActiveX, but CAB files don’t know about RegAsm. The install location of RegAasm is in your .NET directory. So Setup.cmd is called as the install program, and it handles the registration.

That’s the trick! Setup.cmd is the trick. And here is Setup.cmd


@echo off
set MyACTIVEX=%windir%\system32\MyActiveX.dll
copy MyActiveX.dll %MyACTIVEX%
RegNetX

You may be wondering: What is RegNetX?

It is a little install program I wrote. All it does is install my one ActiveX program. I compile the install program from the command line using csc (which comes free with .NET and is in your Framework directory):

csc RegNetX.cs

Here is the code:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;
using System.Diagnostics;

namespace RegNetX
{
    class Program
    {
        static void Main(string[] args)
        {

	    string DLL = Environment.SystemDirectory + "\\MyActiveX.dll";

 	    Console.WriteLine("Usage: RegNetX [-u]");
 	    Console.WriteLine("    Will register " + DLL);
 	    Console.WriteLine("   -u unregisters it");

            // This is the location of the .Net Framework Registry Key
            string framworkRegPath = @"Software\Microsoft\.NetFramework";

            // Get a non-writable key from the registry
            RegistryKey netFramework = Registry.LocalMachine.OpenSubKey(framworkRegPath, false);

            // Retrieve the install root path for the framework
            string installRoot = netFramework.GetValue("InstallRoot").ToString();

            // Retrieve the version of the framework executing this program
            string version = string.Format(@"v{0}.{1}.{2}\",
              Environment.Version.Major,
              Environment.Version.Minor,
              Environment.Version.Build);

            // Return the path of the framework
            string path = System.IO.Path.Combine(installRoot, version);

            if (path == null)
                path = installRoot + version;

            try
            {
                Process regAsm = new Process();
                regAsm.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                regAsm.StartInfo.CreateNoWindow = true;
                regAsm.StartInfo.WorkingDirectory = path;
                regAsm.StartInfo.FileName = "regasm.exe";
                if (args.Length == 0)
                  regAsm.StartInfo.Arguments = "/silent /codebase " + DLL;
                else
                  regAsm.StartInfo.Arguments = "/unregister " + DLL;
 		
		Console.WriteLine(path + "regasm.exe " + regAsm.StartInfo.Arguments );
                regAsm.Start();
                regAsm.WaitForExit(); // based on comboFusion's comment below (in the comment section of this blog)
            }
            catch
            {
                Console.WriteLine("Error running regasm.exe " + args[0]);
            }
        }
    }
}

RegNetX will find the .NET install and call RegAsm. And note well: I hard coded everything to install the ActiveX DLL into the windows\system32 directory. It makes life so much easier if you know that %windir% is a real environment variable that will exist on your target client. When your code is actually installing, it is in a free fall, and your scripts are operating mostly blind, as it were, so you need to try to land in some known fixed location. For that reason, I coded setup.cmd with a fixed install location with an environment variable that will most likely exist. And how nice that DestDir in the INF file is also pointing to %windir%\system32.

After writing this article, I realized that the CAB building tool, cabarc, is old. It is no longer distributed (though it was on my Windows 7 machine). There is another CAB building tool from Microsoft called “MakeCab”. In Part 2 (if I write Part 2), I will go deeper into all this and show the actual ActiveX control. If there is a Part 3, it may be about MakeCab. Given the positive feedback I have received so far, I may just write that second article.

Generate an HTML Data Dictionary for your Microsoft Database

If you want to auto-generate an HTML Data Dictionary for your Microsoft SQL database, here is a free and simple tool to do it. It is a Windows command line script. Just drop down to a command window, and run this command script and pass in the name of your database (the script will give help if you pass in no parameters). Go get a coffee, come back and see the HTML results.

This data dictionary script is meant for developers who need to know the kind of data in the database, and the resulting HTML file is editable so that developer notes can be added over time. I wrote it one weekend as I was contemplating how to document a database. Tools exist to do this, of course, but this one is free, and sufficient for my needs.

This works with all versions of Microsoft SQL. If there is something about it that does not work, let me know, and I’ll see how easy it is to fix. Or, better, just edit it and fix it as you need.

Create a .NET 4 MVC 3 Web Site or Migrate MVC 2 to 3

In earlier posts, I explained the move from Silverlight 3 to 4. Now I want to explain the move from MVC 2 to 3. You need to upgrade, as one day we may well be on MVC 13, and you won’t want your site still running on MVC 2. Besides, MVC 3 has the new HTML Razor engine. Yeah!

In Part I, I briefly explain how to make the small jump from MVC 2 to 3.

In Part II, I give steps for creating an MVC 3 /Razor enabled web site from scratch.

Part I — Move from MVC 2 to 3

Step 1: Install MVC 3

To Install MVC 3, download it here: http://www.asp.net/mvc/mvc3

Step 2: Convert your existing project

To do this, use the automatic conversion tool found here:
http://aspnet.codeplex.com/releases/view/59008

This tool successfully converted my Web.config and Views\Web.config files.

That’s it, the conversion is that easy.

Part II — Creating an MVC Site from Scratch

An MVC 3 site which uses the Razor engine (as opposed to WebForms) is quite compelling, and is the engine of choice (as I understand it). To use this technology, you’ll need to spend three or four hours reading and implementing tutorials.

Step 1: Watch the Tutorials

This multiple part tutorial will get you going with a .NET 4 web site, MVC 3 and Razor. You can use the free Visual Studio browser to build your site, but you will need to purchase space on a .NET 4 compatible server (Discount ASP.NET is a good choice).

Part 1 of 9.

Step 2: Prepare your target server to receive your site

So, you have built your web site, and you want to get your public server ready to serve it up to the world. The exact steps you need to take to do this are dependent upon your particular brand of server, but what you will need to do looks something like what you see at Discount ASP.NET.

You will want to read my earlier article on Silverlight to see how to prepare your server for .NET apps.

Step 3: Deploy

MVC 3 is new, so your server may need some help recognizing your project files. Namely, add the following references to your project and for each one, go to the properties and set Copy Local to true (my source of information).

System.Web.Mvc

Microsoft.Web.Infrastructure

System.Web.Razor

System.Web.WebPages

System.Web.WebPages.Razor

System.Web.Helpers

System.Web.WebPages.Deployment

Conclusion

Programming dynamic web sites is getting a lot easier, and the .NET 4 framework with MVC 3 and the Razor engine is proof. These technologies represent hundreds of man-years (thousands maybe), which have been invested to build and perfect a truly reusable platform.

Part 3 of 3: Speed Comparison of C# BigInteger and C++ mpir

Jan, 2012 Update: With properly coded C#, C++ (in certain cases) is only 2.37x faster (for more, see Patrick’s comment below).

In Part 2 we looked at a C# program that does a little bit of large integer math (using BigInteger). The program was built in release mode, and it gave us its answer in about 55 seconds.

Now it is time to run the same program in C++ using the mpir library (discussed in Part 1 of this 3 part series). MPIR is a Windows-port of the GMP (GNU Multiple Precision Arithmetic Library).

Here is the code (converted from C# to C++):


#include < math.h>
#include < stdio.h>
#include < stdlib.h>
#include < gmpxx.h>
#include < iostream>
#include < time.h>

using namespace std;

void main(int argc, char *argv[])
{
   clock_t start = clock();

   long b, a = 0;
   double guess, root = sqrt(61.0);  

   mpz_class bi_a;
   mpz_class bi_b;
            
   while (a >= 0)  // when a wraps around negateve, bail
   {
        a++;
        guess = a * root; 
        b = (long)floor(guess);
        bi_a = 61 * a * a + 1;
        for (long j = 0; j < 1; j++) // change j < 1 to j < 2 if no answer found...
        {
            b += j;
            bi_b = b * b;
            if (bi_a == bi_b)
            {
                cout << "61 * " << a << "^2 + 1 = " << b << "^2\n";
                cout << "\n\nFinished in Seconds: " << (double)(clock() - start) / CLOCKS_PER_SEC << "\n";
                return;
            }
        }
   }
}

The output of the program is this:

61 * 226153980^2 + 1 = 1766319049^2

Finished in Seconds: 11.5

The C++ code is nearly 5x faster.

C++ wins.

Part 2 of 3: Speed Comparison of C# BigInteger and C++ mpir

In Part 1 I discussed how to use Visual Studio C++ with MPIR and how to use BigInteger and BigRational in C#. Now I want to compare the speed between the two number packages.

We may instinctively suspect that C++ release code is faster than C# — especially optimized large integer packages. So, I will put it to the test. In this part of the series, I write a C# program, and in Part 3 I write the same thing in C++; it is a program to solve a relatively simple Pell’s equation (a famous one too, from Amusements in Mathematics by Henry Dudeney):

129.—THE BATTLE OF HASTINGS.

All historians know that there is a great deal of mystery and uncertainty concerning the details of the ever-memorable battle on that fatal day, October 14, 1066. My puzzle deals with a curious passage in an ancient monkish chronicle that may never receive the attention that it deserves, and if I am unable to vouch for the authenticity of the document it will none the less serve to furnish us with a problem that can hardly fail to interest those of my readers who have arithmetical predilections. Here is the passage in question.

“The men of Harold stood well together, as their wont was, and formed sixty and one squares, with a like number of men in every square thereof, and woe to the hardy Norman who ventured to enter their redoubts; for a single blow of a Saxon war-hatchet would break his lance and cut through his coat of mail…. When Harold threw himself into the fray the Saxons were one mighty square of men, shouting the battle-cries, ‘Ut!’ ‘Olicrosse!’ ‘Godemitè!’”

Now, I find that all the contemporary authorities agree that the Saxons did actually fight in this solid order. For example, in the “Carmen de Bello Hastingensi,” a poem attributed to Guy, Bishop of Amiens, living at the time of the battle, we are told that “the Saxons stood fixed in a dense mass,” and Henry of Huntingdon records that “they were like unto a castle, impenetrable to the Normans;” while Robert Wace, a century after, tells us the same thing. So in this respect my newly-discovered chronicle may not be greatly in error. But I have reason to believe that there is something wrong with the actual figures. Let the reader see what he can make of them.

The number of men would be sixty-one times a square number; but when Harold himself joined in the fray they were then able to form one large square. What is the smallest possible number of men there could have been?

In order to make clear to the reader the simplicity of the question, I will give the lowest solutions in the case of 60 and 62, the numbers immediately preceding and following 61. They are 60 × 42 + 1 = 312, and 62 × 82 + 1 = 632. That is, 60 squares of 16 men each would be 960 men, and when Harold joined them they would be 961 in number, and so form a square with 31 men on every side. Similarly in the case of the figures I have given for 62. Now, find the lowest answer for 61.

Essentially, solve this equation:

61a2 + 1 = b2

Here is the C# code (basically, it counts through values of a, checking b with the assumption that b is essentially a * sqrt(61):


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
using System.Diagnostics;

namespace Euler61
{
    class Program
    {
        static Stopwatch sw;

        static void Start()
        {
            sw = new Stopwatch();
            sw.Start();
        }
        static void Stop()
        {
            sw.Stop();
            TimeSpan ts = sw.Elapsed;
            string elapsedTime = String.Format("Hours: {0:00} Minutes: {1:00} Seconds: {2:00}.{3:00}",
                ts.Hours, ts.Minutes, ts.Seconds,
                ts.Milliseconds / 10);
            Console.WriteLine(elapsedTime, "RunTime");
        }

        // Brute force find a number, 61*x^2 + 1 = y^2
        //   Practically speaking, y = 8x
        //   Well, more like, y = sqrt(61)*x
        static void Main(string[] args)
        {
            Start();

            long b, a = 0;
            double guess, root = Math.Sqrt(61);  
            
            BigInteger bi_a;
            BigInteger bi_b;

            while (a >= 0)  // when a wraps around negateve, bail
            {
                a++;
                guess = a * root; 
                b = (long)Math.Floor((decimal)guess);
                bi_a = 61 * a * a + 1;
                for (long j = 0; j < 1; j++) // change j < 1 to j < 2 if no answer found...
                {
                    b += j;
                    bi_b = b * b;
                    if (bi_a == bi_b)
                    {
                        Console.WriteLine("61 * " + a.ToString() + "^2 + 1 = " + b.ToString() + "\n" );
                        Stop();
                        return;
                    }
                }
            }
        }
    }
}


Time to run and find the solution (on my system): 55.37 seconds.

Program output:

61 * 226153980^2 + 1 = 1766319049

Hours: 00 Minutes: 00 Seconds: 55.37

In the next installment we see about C++ and the mpir package. In the meantime, here are comments from Dudeney about the problem and solution in general (i.e., no brute force!):

129.—THE BATTLE OF HASTINGS.—solution

Any number (not itself a square number) may be multiplied by a square that will give a product 1 less than another square. The given number must not itself be a square, because a square multiplied by a square produces a square, and no square plus 1 can be a square. My remarks throughout must be understood to apply to whole numbers, because fractional soldiers are not of much use in war.

Now, of all the numbers from 2 to 99 inclusive, 61 happens to be the most awkward one to work, and the lowest possible answer to our puzzle is that Harold's army consisted of 3,119,882,982,860,264,400 men. That is, there would be 51,145,622,669,840,400 men (the square of 226,153,980) in each of the sixty-one squares. Add one man (Harold), and they could then form one large square with 1,766,319,049 men on every side. The general problem, of which this is a particular case, is known as the "Pellian Equation"—apparently because Pell neither first propounded the question nor first solved it! It was issued as a challenge by Fermat to the English mathematicians of his day. It is readily solved by the use of continued fractions.

Next to 61, the most difficult number under 100 is 97, where 97 × 6,377,3522 + 1 = a square.

The reason why I assumed that there must be something wrong with the figures in the chronicle is that we can confidently say that Harold's army did not contain over three trillion men! If this army (not to mention the Normans) had had the whole surface of the earth (sea included) on which to encamp, each man would have had slightly more than a quarter of a square inch of space in which to move about! Put another way: Allowing one square foot of standing-room per man, each small square would have required all the space allowed by a globe three times the diameter of the earth.

Part 1 of 3: Doing Large Integer Math with Visual Studio 2010 in C# or C++

If you want to work on Number Theory problems, or Diophatine Equations, you need a math package that allows you to use large integers (MATLAB, e.g.). Optionally, you need to encode your ideas as programs and test your theories the old-fashioned way, with Fortran or some other language. I prefer C++ (it’s the language I have been using for 20 years now). To that end, I want to show you how to use Visual Studio 2010 to build a C++ program to work on large integers. As a bit of a bonus, I’ll also show how to do the same thing in C#.

For fun, we’ll write a small program to verify an old Pell’s equation (which is a kind of Diophantine Equation) where the answer has been given by by Brahmagupta and then Euler. The equation is:

61x2 + 1 = y2

Our goal is not to study the math of Pell’s equations, but to plug a large integer package into your Visual Studio. So I will show you all the steps you need to follow to get this done in a Windows environment using C++ (Section I) and C# (Section II), and then we’ll see about Euler’s answer (3,119,882,982,860,264,401).


Section I — C++

Step 1: Download the large integer math package. We will go to Brian Gladmann’s site, and read about the packages, then go to the Multiple Precision Integers and Rationals page and download the latest source tarball (which happens to be version 2.2.1 at the time of this writing). The version won’t change the code, you’ll be able to use the same C++ code no matter which version you get. At the risk of adding confusion: MPIR is a Windows-port of the GMP (GNU Multiple Precision Arithmetic Library).

Step 2: Decompress the package (I use WinRAR for tarball files, but find something on the internet — something free! — and install it on your machine).

Decompress the file to some location on your computer, let’s say c:\projects\ (for the sake of of discussion).

Step 3: Launch Visual Studio 2010, and load the build file you just decompressed. In our sample case, the 2010 build file would be:

c:\projects\mpir-2.2.1\build.vc10\mpir.sln

Step 4: Build the dll_mpir_gc project.

Screen shot of visual studio

The results (in the sample case of c:\projects\) are in this directory:

c:\projects\mpir-2.2.1\build.vc10\dll\Win32\Release

All the .h files you need, the libs, and the DLL are there.

Step 5: Now we get to use the results! So, create a new blank console application project and name it something related to the problem we are going to solve. We are going to use the results of the above steps which means you’ll place c:\projects\mpir-2.2.1\build.vc10\dll\Win32\Release in your include directory and in your library linking path. Next, you’ll link in the library mpir.lib. The header file you will include is gmpxx.h. For more about this file and the C++ objects in it, go to the gmp site.

Step 6: Create a C++ file in your project with the following code,



#include < stdio.h>
#include < stdlib.h>
#include < gmpxx.h>
#include < iostream>

using namespace std;

void main(int argc, char *argv[])
{
     	
   mpz_class answer_a = 226153980;
   mpz_class answer_b = 1766319049;
   if ((61*answer_a*answer_a + 1) == (answer_b * answer_b))
	cout << "Euler was right!\n";
   else
	cout << "Oooops.  My math package has failed me.\n";

}

Notice that instead of using int or long, we now use mpz_class. Everything else is as expected.

Other large integer tools exist (OpenSSL comes with a BigNum package that is quite nice -- you'll have to build it with the help of some tools I provide in an early article). Of course, the list of tools is impressive, my goal here was to show you a free C++ method that fits within your life easily (if you are a Visual Studio users).


Part II -- C#

Using Big Numbers in C# (.NET 4) is as easy as adding a reference to System.Numerics and then using BigNumber.

But there is also a BigRational which you can use by hooking C# into F#. To use BigRational, follow these steps:

Step 1: Install the F# PowerPack tool which has the big number class we'll be using. Get PowerPack here:

http://fsharppowerpack.codeplex.com/

Download this package and install it on your system,

You need to install F# PowerPack

To be fair, this will make my comments here "dated", for I predict that Microsoft will move the F# code we care about out of PowerPack and put it somewhere else (probably in the F# core). Anyway, for now it is in PowerPack.

Step 2: Add a reference to the PowerPack into your C# project.

Right click on "References", and browse to the PowerPack (in your Program Files\FSharpPowerPack directory:

Drill down into the bin directory, and select FSharp.PowerPack.dll

Step 3: Use FSharp.Math in your program. Now that you have added a reference to the PowerPack, you can use Microsoft.FSharp.Math via the "using" clause in your C# program as follows:

Writing a C# program to use BigRational or BigInteger:

Having followed the above steps, our C# program looks like this:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.FSharp.Math;      // gets us BigRational
using System.Numerics;            // gets us BigInteger
namespace ConsoleApplication1
{
	class Program
	{
		static void Main(string[] args)
		{
			BigInteger bi_a = 226153980;
			BigInteger bi_b = 1766319049;         // one way to do it...
			bi_b = BigInteger.Parse("1766319049"); // or do it this way
			BigInteger sq   = bi_b * bi_b;
			if ((61 * bi_a * bi_a  + 1) == (bi_b * bi_b))
			{
				Console.WriteLine("Euler was right!");
				Console.WriteLine(sq.ToString());
			}

			BigRational br_a = BigRational.FromInt(226153980);
			BigRational br_b = BigRational.FromInt(1766319049);

			BigRational br_answer_a = BigRational.FromInt(61) * br_a * br_a + BigRational.FromInt(1);
			BigRational br_answer_b = br_b * br_b;

			if (br_answer_a.Equals(br_answer_b))
			{
				Console.WriteLine("\nEuler was right again!");
				Console.WriteLine(br_answer_b.ToString());
			}
		}
	}
}

You should see the output that Euler was right. If you don't something went wrong in the code or in one of the steps.

In Part 2 and Part 3 I compare C++ to C# in terms of speed. I also explore more about the historical background behind our sample problem (61x2 + 1 = y2).

Create XML from Excel

When working with MS-SketchFlow, you may want to use their Sketch Datagrid. And with version 4 of Expression Blend, you can associate that grid with an XML source. If your data is in a table format, put it in Excel, save it to XML, then load that XML into SketchFlow. This is the best video (i.e. shortest video) I found on getting XML out of Excel — it works for Excel 2010 as well as it does for the Excel 2003:

Note: In Excel 2010, you need to turn on the display of the main Developer tab so that you can see the XML options. To turn on the Developer tab in the ribbon bar, go to File, Options, Customize Ribbon, “Choose Commands From:” Popular Commands, then in the left column, click [x] Developer.

Build a dynamic newspaper site, quickly and free

A local paper needed a web site. After two calls to set up a face-to-face meeting (and we met today for just one hour), I got all the business requirements. The same day they had their site. Here is the story.

Business Requirements:
They needed a server, a user management system (able to add admin, editors, authors, subscribers and readers), a content management system — a newspaper is content based! — with the ability to create dynamic articles, posts, pages, images, menus and all the rest, and a way for ads to be sold (papers generally make their core income from ads). So there was the challenge, but with two important constraints:

Constraint 1. Cost:
Small-town papers are business with budgets. How much would such a thing cost? The newspaper owner had shopped around, contacted some developers, got bids, and the prices were unreasonablly high.

Constraint 2. Speed:
The site needs to be up pretty quickly. The sooner it goes up, the sooner ad space can be sold.

Solution:
Wordpress. I know this sounds like an add, but I was so pleased with the results, it seemed right to share with others the steps on how to do this.

1. Get space on GoDaddy (this is not free, so there is a little cost to this venture)
2. Use GoDaddy to get email address and a MySQL database (need that database to store the content)
3. Install WordPress as the root of the site
Note: I use Firefox’s FirtFTP to get the files up to the GoDaddy site
4. Get a Newspaper theme (installing WordPress themes is an enjoyable process, so do some shopping).

Done.

It was that easy. We then created some basic newspaper categories (WordPress runs off of Categories), and now the system is up and ready for the staff to add content, and they don’t need me–they can manage it on their own. So a bonus in all of this is that they are not tied to a development staff or a developer.

Axis and Allies Ti-83 Program

I bought the Axis and Allies starter kit (the exact one shown here).

I wanted to play with my younger kids, but I found that the dice rolling was too time consuming and cumbersome. So I wrote a Ti-83 / Ti-84 program to manage all the vehicles and soldiers and their damage, dice and speed. That is, I took everything about each tank and soldier (as defined on their corresponding cards) and I put them into the calculator. I then put all the attack / casualty and defensive fire rules into little programs that use the data. In this way, you can play the starter game with your youngest kids. They only need to think about the objective of the game, movement and what they want to fire upon during each phase.
Continue reading

Ti-84 Risk Game

I have some friends who play RISK regularly enough that they decided to write a C# program that speeds up the game for dice rolling. Just enter the number attacking and the number defending, and the laptop tells you who won. Great idea! So, I thought it would be great to write the same kind of app for a TI-84. That way, the calculator can be passed around to each player, and they can manage the dice.

I wrote this on the TI-84 Plus Silver edition, but it should work on the TI 83. I copied the code over to my computer through the USB link. I spent a few hours writing it, and I didn’t want my son to delete it as he is programming the same device — so I backed it up to my computer and I thought that other people may derive some pleasure from it. So here is the binary version. And following is the text version:

Continue reading

SQL Express Server 2008 and the Upgrade to Silverlight 4 RIA

In the past two articles, I explained deployment of a 2010 RIA application and my upgrade from Silverlight 3, VS 2008 to Silverlight 4 on VS 2010. Here is a gotcha: When you upgrade to VS 2010, you also get the latest free (Express) SQL Server 2008 — which will replace your earlier SQL Express Server 2005. In this case (in the case you had an earlier 2005 edition), you need to go back and uninstall SQL Express Server 2005 and download and reinstall SQL Express Server 2008 (that is, if you want to run the SQL Server Management Studio / Management Console — used to view your databases).

Now this all sounds very easy… but there are two steps you need to take:

1) Install Windows Power Shell (the Express SQL Server 2008 installation program requires it).

2. Manually do extra steps to uninstall SQL Express Server 2005. There is a trick you need to know about to fully uninstall the Express SQL Server 2005. And that is why I am writing. Namely, you need to remove the registry key at: HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\90

Hope this helps!

Convert Silverlight 3 (VS 2008) to Silverlight 4 (VS 2010) – RIA

This is my conversion experience. I hope it is of some assistance to you — and, I must say, the link to the DOCx file is essential for your efforts.

Scenario:
I have a Silverlight 3 RIA application built with VS 2008. A few weeks ago (I think it was April 14, 2010) Microsoft released the next official version of Visual Studio (2010) and with it, .NET 4 and Silverlight 4.
Continue reading

Siliverlight 4 .NET 4 RIA Deploy

Install Visual Studio 2010 and the Silverlight 4 Tool RC2. Create a new project (Silverlight Business Application). Build the application.

Buy space on an ASP.NET 4 enabled IIS7 server (I used two providers, and it was only through Discount ASP.NET that I had success getting my new Silverlight app installed and running).

So far so good. Right?

Well, not exactly. You will get an error complaining about LocalSqlServer (this is where Fiddler — see below — helped me the most, but more on that later). I won’t explain the error, I want to explore the solution.

Using everything out of the box (as I have described here) is not sufficient. And there are two reasons: 1) Software Problem: The Web.Config file you have (which was added to your project for you) won’t work; and, 2) Server Problem: Your IIS7 server is not properly configured.

Continue reading

DOS Batch Program to Parse Strings

A friend asked me to write a script that will tell how much space is used in a directory. Using the Microsoft CMD script (the batch program) the answer follows. This cmd script demonstrates three important ideas:

1) Recursive function calls in a MS-Windows OS batch file
Namely, we use the “for /D” command to walk the directory structure. A function is called with the “call” command, and it exits with “goto:eof”

2) The use of the “for” command to parse the output of a program
Namely, near the bottom of the file there is a :DIRECTORY function. DOS bat / cmd files don’t have access to GREP, but they can use FIND. We pipe the output of the dir command to the find command and then token-ize the output and store it in variables.

3) We use the SET /A command to do basic math.
As we determine the used space of each directory, we add it up.

Continue reading

Connections between Thought Realms

Computers can be programed to sift unstructured texts in order to find connections.  If you want to connect two realms of thought, you need data from both realms. You should also have a theory on how to connect the realms. With a fast computer, and the right software, there is a chance to find discoveries between realms of thought. I worked in the stock market trying to find relationships between one stock going up, and another following (tracking stocks). If I could show that Harley Davidson stock prices went up and then Wal Mart stocks followed, I could help investors make money.

Using similar techniques, I seek to find connections in literature, history, culture,… you name it, a link is valuable. With all the data available on the internet (electronic books especially), we are going to see a new era of data mining and connectionism. The book to the left is an invaluable introduction to the topic. I found it while doing research at Reuters on how to connect News Stories to stock movements.

I have been especially interested in applying these ideas to the ancient texts of Egypt, Israel, Assyria, Rome, etc. For example, in the Egyptian Amarna letters, unique phrases appear that also appear in Malachi and Isaiah. There is a connection (at least linguistically) between documents across languages. Finding such connections, and then pointing them out to a researcher, is the work of software.

That is the software I am proposing. The requirements are these: 1) large quantities of ancient texts that may relate at some abstract level; 2) fast computers and 3) advanced algorithms that find connections. The first two are easy to get and the third one is the trick. I will elaborate on all three and suggest a way forward:

1) Large quantities of ancient books stored electronically are readily available from Logos

I have been using Logos for years, and my collection of ancient texts has been growing (I have to purchase each book I unlock). In addition to the Logos collection, I have 1400 Ugaritic tablets along with software that I wrote to display and use them.

2) Fast computer chips and memory are ubiquitous
With the advent of personal computers, and now cloud computing, the ability to process large amounts of data is as close as the least expensive laptop. Computing power is at a point where this kind of project is feasible for the hobbyist. A modern laptop rivals the computing power of earlier super computers and older mainframes.

3) Logos has provided a programming interface to access their LARGE collection of books.
As a software programmer, I need an interface that allows me to access the above mentioned books. They are in a proprietary data format — one not easily accessible. The good news which prompts the writing of this article is this: The folks who provide the important e-books also wrote an interface for programmers. Their interface is freely available and documented on their web site. This means Windows software can be written to sieve, process, connect and collate realms of thought.

This post is the first installment of a series where I will chronicle the use of Logos’s programmer’s interface. I am talking about the start of an ambitious software project — software that gets into Logos’ massive collection of books. As with all of my software experiments, look for scaffolding-like tools to start appearing on my web site. I have written extensively on this subject of connectionism in the past. Specification documents have already been generated along with basic design.

The steps before me are these:

1) Learn the application interface for the Logos system. This will mean sample software; help exists.

2) Implement connectionism algorithms as per the above mentioned book.  Some of this has been written. Earlier excursions have yielded wildly different applications. One software tool connects the Hebrew Old Testament to the Greek Old Testament and finally to the Greek New Testament while another operates on the periodic table of elements.

Limitation: Time. I don’t have any free time to dedicate to this project. It will be slow going. Other software projects take priority (even as they are related).

Steve Rives
Kansas

A Free OpenSSL Visual C++ Object: Part 2

This is Part 2 in a series about integrating OpenSSL into an existing C++ project.  In Part 1 I presented a scenario that would necessitate such integration and I outlined the contours of the problem.  

In essence, the goal of adding OpenSSL to a project is to add the “S” to your C++ based HTTP server — thus getting you an HTTPS server.  I wanted to use this second post to give source code, but before that I need to step you through the install and build process of OpenSSL.  In a future installment, I will present the C++ object which will be downloadable.  

This seris is made possible because of the graciousness of Power Admin; the final project will be available on their web site.  Included in that release are the scripts for Certificate use and generation via a Certificate Authority.  

Continue reading

Adding OpenSSL to an existing Visual C++ Socket Program in C++

Your boss comes into your office and says she wants to support encrypted communications over your HTTP server. She wants your company web site to use HTTPS instead of HTTP. Among other things, they need to handle credit card transactions and the encrypted transmission of user information across the internet. And she wants it written in-house and integrated into the current C++ code base.

If you have been assigned such a task, I am writing for you.

In the next series of articles, I am going to show you how I started with scant knowledge of OpenSSL and wrote a C++ object that allows one to slap SSL (a Secure Sockets Layer) on top of any existing Visual C++ socket code. By the end of this series, I am going to give you the source code.

Continue reading