|
Eddy Vluggen wrote: Cute == obfuscated?
You are absolutely right, I'll now spend the next 2 hours trying to work out what JAANs has done.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Eddy Vluggen wrote: One method to divide them, one to combine them again
For some reason that reminded me of this: Ash nazg durbatulûk, ash nazg gimbatul, ash nazg thrakatulûk agh burzum-ishi krimpatul.
|
|
|
|
|
..and somehow, for some obscure reason, that reminded me of marriage
I are Troll
|
|
|
|
|
And, once we take into account your signature, we wind up with the Orc of the Covenant.
|
|
|
|
|
You should have saved that as a Friday Programming Quiz.
This ought to be more efficient than that Linq abomination:
public static string
Repeater
(
string Source
,
char Delimiter1
,
char Delimiter2
)
{
System.Text.StringBuilder result = new System.Text.StringBuilder() ;
int off = 0 ;
while ( ( off = Source.IndexOf ( Delimiter1 , off + 1 ) ) > -1 )
{
for ( int i = 0 ; i <= off ; i++ ) result.Append ( Source [ i ] ) ;
result.Append ( Delimiter2 ) ;
}
return ( result.ToString ( 0 , result.Length - 1 ) ) ;
}
|
|
|
|
|
PIEBALDconsult wrote: Friday Programming Quiz
Not a chance, one of these codz will turn up in my app this morning (with an appropriate link to the author of course).
PIEBALDconsult wrote: return ( result.ToString ( 0 , result.Length - 1 ) )
I didn't realise you could manage the lenght during a tostring() operation.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: I didn't realise you could manage the lenght during a tostring() operation.
Lots of people don't; I think I learned it in the last year.
|
|
|
|
|
Is it possible to read data from controls of already loaded form in winforms?
Suppose I have a simple mdi application. I open Form1 from menu. On form1 I fill textboxes with clientID and productID. I keep Form1 open. Now I open Form2 from menu. Can I read clientID and productID of Form1 in load event of Form2?
|
|
|
|
|
If you had a valid reference to the form and the control values were exposed via a property.
Something like this
public class Form1
{
public string ClientID
{
get{ return ClientID.Text; }
set{ ClientID.Text = value; }
}
}
public class Form2
{
public Form2(Form frm)
{
string id = frm.ClientID;
}
}
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Another way to do it would be to have a constructor in your form2 that took two integers as parameters, which can be used to populate two fields in your form2 like this:
int ClientID;
int ProductID;
public Form2(int clientID, int productID)
{
this.ClientID = clientID;
this.ProductID = productID;
}
private void Form1_Load(object sender, EventArgs e)
{
}
Hope this helps.
|
|
|
|
|
hi i have a one question.
I made outlook's add-ins.
Now I want to Make function which If i clicked some button in outlooks's add-in,
Some Contents was saved to someone's outlook schedule.
I hearded, this is possible.
If you know, please let me know about site.
Have a nice Day.
hi
My english is a little.
anyway, nice to meet you~~
and give me your advice anytime~
|
|
|
|
|
buffering83 wrote: I hearded, this is possible.
Yup.
buffering83 wrote: If you know, please let me know about site.
It's called MSDN[^], and has all the samples you need to get started
I are Troll
|
|
|
|
|
Thank You!
I just make program what i want because MSDN which you linked!
Have a nice Day!
hi
My english is a little.
anyway, nice to meet you~~
and give me your advice anytime~
|
|
|
|
|
Thanks for the nice response
I are Troll
|
|
|
|
|
Dear Coders,
I am still frustrated by my problem, so I am going to ask again and hope someone may be able to help me?
First of all, I do not want to use a big num type of library, and I am not looking for the simple built in converters and formatters as this does not help my situation.
I did find code that performed the required encoding and decoding a while ago, but I just cant seem to find it anyware.
I will now explain my problem in as simple a way as I can, and then I will provide additinal info further down to explain exactly what I am trying to do.
OK, here goes...
I want to be able to input a string of any length, normaly it is going to be arround 50 digits...
string input = ("45873476774384759909120192837428394458475988343485")
After the string is entered into a text box, I want to decode the decimal digits into their hex representation and store them into a byte array.
So, if I had the following decimal digits...
67384567845
And converted them into hex, I would end up with:
FB06EE825
And to encode, I want to be able to build a fixed length byte array, for example containing the above hex, and then build a string containing the decimal representation, which for the above would be
67384567845
So, I am looking for an encode and a decode routines to perform the above. I cant simply use the bult in functions as the int, or decimal string will be around 50 digits and I do not want to use big num librarys.
The code I was given ages ago used some kind of binary routines to loop through and "build" the string.
What am I trying to do?
I want to build a byte array of FIXED length to represent the ID and version of my app, with some other data.
I then want to encrypt it
I then want to represent it as decimal digits of a fixed length, and not hex, base 32 etc etc.
I then want to be able to enter the decimal string of 50 digits into an app I built
I then want to decode the string into its hex byte representation of fixed length
I can then decrypt the byte array, and perform matching checks etc
I hope this is clear enough and I will be so gratefull if anyone can help, as binary math is not my area at the moment.
Thank you so so much for any help.
Kind regards,
Steve
|
|
|
|
|
If you're Googling for this using the keywords "encode" and "decode", that's not what you're doing. You're converting a number from one base to another. Google for "convert base 10 to base 16 c#" and you might find something useful.
|
|
|
|
|
Steve, every time you have asked this question, someone has told you: converting a number from base 10 to vbase 16 is not encryption".
Now that you have described what you want to do, can I suggest an alternative, which is used by a lot more software than what you appear to be trying to do:
1) Assemble the string you want to check in your application. This can be any string, as long as your software can generat it.
2) Take the MD5 or SHA hash of the string.
3) Enter the hash value to your application.
4) Your application then generates it's version of the string.
5) It then generates the MD5 or SHA hash of the string it just generated.
6) It then compares the two hashes. If they are the same, it passes.
This way, there is no need to encrypt anything in a way that can be reverse engineered: MD5 and SHA are non-reversible (Well, MD5 is "broken" because there is a way to generate an enter-able string from the hash, but never mind that for now)
The only way to do exactly what you are actually asking for is to convert the string to an number and then convert back into the new base. How much clearer do we have to be?
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."
|
|
|
|
|
Hi,
Thank you for the new idea, could I ask you to clarify step 1 above.
What type of string would this be.
As long as I can generate a string of digits that are fixed in length, and different everytime I generate a new serial number, then this method would be fine.
Thank you
Kind regards,
Steve
|
|
|
|
|
stephen.darling wrote: As long as I can generate a string of digits that are fixed in length, and different everytime I generate a new serial number, then this method would be fine.
Or, a Guid. Is there any reason that a Guid won't do?
|
|
|
|
|
Hi.
Well in either case, the generated serial would look like the following:
AF54E45D32E... etc
and I want my serial to be formatted like the following:
32443523454234532... etc
But, because my serial would be large, that is why I cant simply use int64 or simular methods.
I have seen code before, and used it years ago that does exactly what I want.
Yes, there are many products that ask for a MD5 style serial, but, if you look at products from ADOBE, AUTODESK etc etc,
they have serial numbers in the following format:
0000-0000-0000-0000-0000
But if I simply created a string and forced it to be numbers, which I have managed to do, when it is encrypted we loose the format and end up with unreadable charicters.
It is easy to find how to then encode these into a readable format, but it is always base32 or base16 and I still want to represent my large serial as digits.
Thank you, I will keep trying to figure this out.
Regards,
Stephen
|
|
|
|
|
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."
|
|
|
|
|
I have a checkBox in my excel workbook,and I would like to know in my c# application is tht VBA Excel control(chechkBox) set to true or false. How?
Any examples anywhere,or something,so basically how to read data from excel vba in c#
|
|
|
|
|
|
i want to implementing page layout properties of word in C#.net. How can i do this
MURALEEKRISHNAN.K
|
|
|
|
|
1) Assemble a large team - several hundred programmers, managers, project managers, testers, technical authors, etc.
2) Give them a copy of Ami Pro, and tell them "copy that, but don't make it obvious". Allegedly.
3) Go away for ten years or so, remembering to pay them, and hire on more staff when they ask.
4) Done - you now have Word page layout in .NET
Of course, Word has probably moved on a little by then...
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."
|
|
|
|
|