Click here to Skip to main content
15,901,035 members
Home / Discussions / C#
   

C#

 
GeneralRe: Question About outlook add-in Pin
Eddy Vluggen2-Mar-11 20:37
professionalEddy Vluggen2-Mar-11 20:37 
QuestionStill trying to find out how to encode and decode a string of decimal digits...Please could anyone assist me? Pin
stephen.darling27-Feb-11 7:27
stephen.darling27-Feb-11 7:27 
AnswerRe: Still trying to find out how to encode and decode a string of decimal digits...Please could anyone assist me? Pin
Dave Kreskowiak27-Feb-11 12:11
mveDave Kreskowiak27-Feb-11 12:11 
AnswerRe: Still trying to find out how to encode and decode a string of decimal digits...Please could anyone assist me? Pin
OriginalGriff28-Feb-11 0:01
mveOriginalGriff28-Feb-11 0:01 
GeneralRe: Still trying to find out how to encode and decode a string of decimal digits...Please could anyone assist me? Pin
stephen.darling28-Feb-11 1:42
stephen.darling28-Feb-11 1:42 
GeneralRe: Still trying to find out how to encode and decode a string of decimal digits...Please could anyone assist me? Pin
Pete O'Hanlon28-Feb-11 2:37
mvePete O'Hanlon28-Feb-11 2:37 
GeneralRe: Still trying to find out how to encode and decode a string of decimal digits...Please could anyone assist me? Pin
stephen.darling28-Feb-11 3:02
stephen.darling28-Feb-11 3:02 
GeneralRe: Still trying to find out how to encode and decode a string of decimal digits...Please could anyone assist me? Pin
OriginalGriff28-Feb-11 2:49
mveOriginalGriff28-Feb-11 2:49 
stephen.darling wrote:
What type of string would this be.


"Anything you like"

There is a description of MD5 here: Wiki[^]
Basically, when you generate a hash, you work out a number based on the content of your input: For example, you could hash a string by adding together all the characters and taking only the last eight bits. If you used this hash algorithm on the same string, your will always get the same hash value. Change a single character in the string, and you will get a different value: It makes it very easy to compare them, and you cannot get back to the string from the hash value: you have discarded information when you took only the last eight bits of the sum.
I'm not suggesting such a simple hash would help you (there are only 256 different values, so it is too easy to find a duplicate), but MD5 always generates a hash value 128 bits (32 hex digits) long. And it is easy to generate:

private void button1_Click(object sender, EventArgs e)
    {
    string s = "Anything you like!\n" +
               "0123456789ABCDEF" +
               GetHDDSerialNumber("C");
    string MD5 = GetMD5(s);
    Console.WriteLine(MD5);
    if (CheckMD5(s, MD5))
        {
        Console.WriteLine("Hash matches: ok");
        }
    else
        {
        Console.WriteLine("Hash failed to match: WTF!");
        }
    string sFail = s + ".";
    string MD2Fail = GetMD5(sFail);
    Console.WriteLine(MD2Fail);
    if (CheckMD5(sFail, MD5))
        {
        Console.WriteLine("Hash matched: WTF!");
        }
    else
        {
        Console.WriteLine("Hash failed to match: ok");
        }
    }
private static string GetMD5(string input)
    {
    MD5CryptoServiceProvider MD5Builder = new MD5CryptoServiceProvider();
    byte[] bytes = System.Text.Encoding.UTF8.GetBytes(input);
    bytes = MD5Builder.ComputeHash(bytes);
    System.Text.StringBuilder sb = new System.Text.StringBuilder(bytes.Length * 2);
    foreach (byte b in bytes)
        {
        sb.Append(b.ToString("X2"));
        }
    return sb.ToString();
    }
private static bool CheckMD5(string input, string MD5)
    {
    return GetMD5(input) == MD5;
    }
private static string GetHDDSerialNumber(string drive)
    {
    ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"" + drive + ":\"");
    disk.Get();
    return disk["VolumeSerialNumber"].ToString();
    }
You will need to add a reference to "System.Management" and
using System.Security.Cryptography;<br />
to compile this.

Generate the output (on my machine - it would be different on yours):
DC7A30D78A5D410E5619E60F5514F85C
Hash matches: ok
D0E113EB00B3ECDCEA6CA7AC39D68440
Hash failed to match: ok

Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."

QuestionReading VBA data in c# Pin
NaturePhoenix27-Feb-11 6:29
NaturePhoenix27-Feb-11 6:29 
AnswerRe: Reading VBA data in c# Pin
Moonskynoli27-Feb-11 14:39
Moonskynoli27-Feb-11 14:39 
Questionhow to implement page layout properties of word in c#.net Pin
MuraleeKrishnan27-Feb-11 6:25
MuraleeKrishnan27-Feb-11 6:25 
AnswerRe: how to implement page layout properties of word in c#.net Pin
OriginalGriff27-Feb-11 21:20
mveOriginalGriff27-Feb-11 21:20 
QuestionCustom SplitContainer Pin
jasonmp27-Feb-11 3:04
jasonmp27-Feb-11 3:04 
Questionclose a window on btn clk [modified] Pin
aeman27-Feb-11 1:34
aeman27-Feb-11 1:34 
AnswerRe: close a window on btn clk Pin
OriginalGriff27-Feb-11 1:49
mveOriginalGriff27-Feb-11 1:49 
AnswerRe: close a window on btn clk Pin
OriginalGriff27-Feb-11 1:50
mveOriginalGriff27-Feb-11 1:50 
GeneralRe: close a window on btn clk Pin
RobCroll27-Feb-11 2:56
RobCroll27-Feb-11 2:56 
GeneralRe: close a window on btn clk Pin
Mycroft Holmes27-Feb-11 3:00
professionalMycroft Holmes27-Feb-11 3:00 
GeneralRe: close a window on btn clk Pin
OriginalGriff27-Feb-11 3:30
mveOriginalGriff27-Feb-11 3:30 
GeneralRe: close a window on btn clk Pin
Richard MacCutchan27-Feb-11 6:21
mveRichard MacCutchan27-Feb-11 6:21 
GeneralRe: close a window on btn clk Pin
Mycroft Holmes27-Feb-11 11:14
professionalMycroft Holmes27-Feb-11 11:14 
AnswerRe: close a window on btn clk Pin
jasonmp27-Feb-11 3:10
jasonmp27-Feb-11 3:10 
AnswerRe: close a window on btn clk Pin
Hum Dum27-Feb-11 23:20
Hum Dum27-Feb-11 23:20 
GeneralRe: close a window on btn clk Pin
aeman28-Feb-11 20:06
aeman28-Feb-11 20:06 
AnswerRe: close a window on btn clk Pin
aeman28-Feb-11 20:03
aeman28-Feb-11 20:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.