Terrorism: It's a Dog's Life! And, It Just Works...
This morning I heard a piece on the K9 Enforcement Detection program. These dogs, many of which come from animal shelters because their feisty behavior (good for this program) was too much for their original owners, have detected over 40,000 concealed HUMANS in cargo, etc - not to mention tons of explosives and drugs.
The dogs are trained that if they smell a human they can't see, they should make an alert to their handler. All the training is basically positive reinforcement and play to the dogs.
This program costs a measly $3.5 million a year, a drop in the bucket compared to the multimillion dollar high-tech equipment we have that's designed to do to same work and may actually be more effective than the machines.
In addition, the dogs are highly portable and can be flown anywhere on a moment's notice.
Support our Troops - Woof!
It Just Works
I had to do another C++ conversion recently on a custom C++ program that takes a file and a password and performs a custom XOR MD5 encryption on the file. The original code supplied by the vendor had a front-end console application that just looked for the file names and password as command line arguments, so I was able to immediately throw that part out.
Previously I had done a number of managed to unmanaged C++ wrappers, but this time I decided to try "IJW". Turns out that it really does "Just Work" - with some provisos - in this case the inputs were of type unsigned char* (equivalent to a byte array).
The managed code signature looks like:
void Encryption.Encrypt (byte* plaintext, byte* cyphertext, sbyte* pwd);
You can see what's required to perform the marshaling of the parameters to the underlying native C++ types below:
// Modifications to the C++ class (Compile with /CLR switch)
#using <mscorlib.dll>
using namespace System;
public __gc class Encryption
{
....
public:
void Encrypt(unsigned char * plainText, unsigned char *cypherText, char *pwd)
{
...
the above gets compiled with the /CLR switch, which tells C++ to generate a managed code assembly
// C# calling class:
string outputString = System.Text.Encoding.UTF8.GetString(cb);
byte[] pbData = new byte[cb.Length];
byte[] cbData = new byte[cb.Length];
byte[] pwdByt=System.Text.Encoding.UTF8.GetBytes(password);
byte[] pwdBytData = new byte[pwdByt.Length];
IntPtr ptrb = Marshal.AllocHGlobal(b.Length);
Marshal.Copy(b,0,ptrb,b.Length);
IntPtr ptrcb = Marshal.AllocHGlobal(cb.Length);
Marshal.Copy(cb,0,ptrcb,cb.Length);
IntPtr ptrPwd = Marshal.AllocHGlobal(pwdByt.Length);
Marshal.Copy(pwdByt,0,ptrPwd,pwdByt.Length);
unsafe
{
enc.Encrypt((byte*)ptrb,(byte*)ptrcb,(sbyte*)ptrPwd);
}
byte[] resByt=new byte[cb.Length];
Marshal.Copy(ptrcb,resByt,0,resByt.Length);
string fileName2=fileName+".enc";
string resultPath = basePath +fileName2;
FileStream fs2 = new FileStream(resultPath,FileMode.Create );
fs2.Write(resByt,0,resByt.Length);
fs2.Close();
try
{
Marshal.FreeHGlobal(ptrb);
Marshal.FreeHGlobal(ptrcb);
Marshal.FreeHGlobal(ptrPwd);
}
catch(Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
Bottom line? I could have spent hours attempting to translate the complicated encryption algorithm to C#. Instead all i had to do was add some cool __gc stuff to the native C++ code, figure out the marshaling of the pointers, and I was good to go.
Buzzwords Department:
Microsoft announced the release of the first beta release of its Windows Vista client operating system, and with it the company also announced official names for the operating system's presentation and communication subsystems, formerly known by the code names "Avalon" and "Indigo," respectively.
According to sources, Microsoft will officially name Avalon the Windows Presentation Foundation (WPF) and Indigo the Windows Communication Foundation (WCF).
Microsoft officials said Windows Vista, formerly known as Longhorn, offers substantial benefits to developers, particularly around WinFX, the managed code programming model that builds on the .Net Framework.
The dogs are trained that if they smell a human they can't see, they should make an alert to their handler. All the training is basically positive reinforcement and play to the dogs.
This program costs a measly $3.5 million a year, a drop in the bucket compared to the multimillion dollar high-tech equipment we have that's designed to do to same work and may actually be more effective than the machines.
In addition, the dogs are highly portable and can be flown anywhere on a moment's notice.
Support our Troops - Woof!
It Just Works
I had to do another C++ conversion recently on a custom C++ program that takes a file and a password and performs a custom XOR MD5 encryption on the file. The original code supplied by the vendor had a front-end console application that just looked for the file names and password as command line arguments, so I was able to immediately throw that part out.
Previously I had done a number of managed to unmanaged C++ wrappers, but this time I decided to try "IJW". Turns out that it really does "Just Work" - with some provisos - in this case the inputs were of type unsigned char* (equivalent to a byte array).
The managed code signature looks like:
void Encryption.Encrypt (byte* plaintext, byte* cyphertext, sbyte* pwd);
You can see what's required to perform the marshaling of the parameters to the underlying native C++ types below:
// Modifications to the C++ class (Compile with /CLR switch)
#using <mscorlib.dll>
using namespace System;
public __gc class Encryption
{
....
public:
void Encrypt(unsigned char * plainText, unsigned char *cypherText, char *pwd)
{
...
the above gets compiled with the /CLR switch, which tells C++ to generate a managed code assembly
// C# calling class:
string outputString = System.Text.Encoding.UTF8.GetString(cb);
byte[] pbData = new byte[cb.Length];
byte[] cbData = new byte[cb.Length];
byte[] pwdByt=System.Text.Encoding.UTF8.GetBytes(password);
byte[] pwdBytData = new byte[pwdByt.Length];
IntPtr ptrb = Marshal.AllocHGlobal(b.Length);
Marshal.Copy(b,0,ptrb,b.Length);
IntPtr ptrcb = Marshal.AllocHGlobal(cb.Length);
Marshal.Copy(cb,0,ptrcb,cb.Length);
IntPtr ptrPwd = Marshal.AllocHGlobal(pwdByt.Length);
Marshal.Copy(pwdByt,0,ptrPwd,pwdByt.Length);
unsafe
{
enc.Encrypt((byte*)ptrb,(byte*)ptrcb,(sbyte*)ptrPwd);
}
byte[] resByt=new byte[cb.Length];
Marshal.Copy(ptrcb,resByt,0,resByt.Length);
string fileName2=fileName+".enc";
string resultPath = basePath +fileName2;
FileStream fs2 = new FileStream(resultPath,FileMode.Create );
fs2.Write(resByt,0,resByt.Length);
fs2.Close();
try
{
Marshal.FreeHGlobal(ptrb);
Marshal.FreeHGlobal(ptrcb);
Marshal.FreeHGlobal(ptrPwd);
}
catch(Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
Bottom line? I could have spent hours attempting to translate the complicated encryption algorithm to C#. Instead all i had to do was add some cool __gc stuff to the native C++ code, figure out the marshaling of the pointers, and I was good to go.
Buzzwords Department:
Microsoft announced the release of the first beta release of its Windows Vista client operating system, and with it the company also announced official names for the operating system's presentation and communication subsystems, formerly known by the code names "Avalon" and "Indigo," respectively.
According to sources, Microsoft will officially name Avalon the Windows Presentation Foundation (WPF) and Indigo the Windows Communication Foundation (WCF).
Microsoft officials said Windows Vista, formerly known as Longhorn, offers substantial benefits to developers, particularly around WinFX, the managed code programming model that builds on the .Net Framework.
Comments
Post a Comment