|
Hi,
I am having a problem decrypting a des file or well in this test case a des string. I'm not sure if my error is in the Encrypting or the Decrypting so i will post code for both. This is what i am calling.
<br />
string Key = Security.CreateKey();<br />
Console.WriteLine(Encoding.ASCII.GetString(Security.Decrypt(Security.Encrypt(Encoding.ASCII.GetBytes("Test"), Key), Key)));<br />
But giberish is returned rather than "Test"... Obviously encoding and decoding are using the same key so i'm not exactlly sure is going on . Any help anyone could offer would be GREATLY appreciated.
Thanks in advance!
<br />
public string CreateKey()<br />
{<br />
DESCryptoServiceProvider desCrypto = (DESCryptoServiceProvider)DESCryptoServiceProvider.Create();<br />
return ASCIIEncoding.ASCII.GetString(desCrypto.Key);<br />
}<br />
<br />
public byte[] Encrypt (byte[] Data, string Key)<br />
{<br />
MemoryStream MemStream = new MemoryStream();<br />
DESCryptoServiceProvider Des = new DESCryptoServiceProvider();<br />
SetDesKey(Des, Key);<br />
<br />
ICryptoTransform DesEncrypt = Des.CreateEncryptor();<br />
CryptoStream CryptStream = new CryptoStream(MemStream, DesEncrypt, CryptoStreamMode.Write);<br />
CryptStream.Write(Data, 0, Data.Length);<br />
CryptStream.Close();<br />
<br />
return MemStream.ToArray();<br />
}<br />
<br />
public byte[] Decrypt(byte[] Data, string Key)<br />
{<br />
byte[] returnContainer;<br />
MemoryStream MemStream = new MemoryStream(Data);<br />
<br />
DESCryptoServiceProvider Des = new DESCryptoServiceProvider();<br />
SetDesKey(Des, Key);<br />
<br />
ICryptoTransform DesEncrypt = Des.CreateEncryptor();<br />
CryptoStream CryptStream = new CryptoStream(MemStream, DesEncrypt, CryptoStreamMode.Read);<br />
<br />
returnContainer = new byte[MemStream.Length];<br />
CryptStream.Read(returnContainer, 0, returnContainer.Length);<br />
CryptStream.Close();<br />
<br />
return returnContainer;<br />
}<br />
<br />
private void SetDesKey(DESCryptoServiceProvider DESProvider, String password)<br />
{<br />
int i;<br />
Byte[] bytePassword;<br />
bytePassword = (new ASCIIEncoding()).GetBytes(password);<br />
Byte[] passwordHash;<br />
SHA1Managed SHhash = new SHA1Managed();<br />
<br />
passwordHash = SHhash.ComputeHash(bytePassword);<br />
<br />
Byte[] pwh = new Byte[8];<br />
for (i = 0; i < 8; i++)<br />
pwh[i] = passwordHash[i];<br />
<br />
Byte[] pwiv = new Byte[8];<br />
for (int j = 7; i < 16; i++)<br />
pwiv[j] = passwordHash[j + 7];<br />
<br />
DESProvider.Key = pwh;<br />
DESProvider.IV = pwiv;<br />
}<br />
|
|
|
|
|
In the Decrypt function, you need to call CreateDecryptor instead of CreateEncryptor .
|
|
|
|
|
OMG ok... i kinda feel dumb now.. *sigh* i guess it happends...
thank you very much dominik.
|
|
|
|
|
Guffa:
In response to the following response, I need to ask for some further input. I was able to successfully cause a Timer control to trigger when the dragged control was dropped. However, the dragDropTimer_Tick event cannot retrieve any control so that it could modify its location.
Here is what I have so far:
private static void ProvideDragPathReturnToParent(Control ctrl, int intX_end, int intY_end,
int intX_start, int intY_start)
{
Timer dragDropTimer = new Timer();
dragDropTimer.Enabled = true;
dragDropTimer.Interval = 2;
dragDropTimer.Tick +=new EventHandler(dragDropTimer_Tick);
dragDropTimer.Start();
}
private static void dragDropTimer_Tick(object sender, System.EventArgs e)
{
int x = 0, y = 0;
for (int index = 0; index <= 64; index++)
{
x = pt_start.X + (intX_end - pt_start.X) * index / 64;
y = pt_start.Y + (intY_end - pt_start.Y) * index / 64;
}
MessageBox.Show("Hello");
}
The pt_start System.Drawing.Point was moved to become a public variable in the DragDropHandler. The problem is that I cannot access the control itself because the dragDropTimer_tick event handler has a sender object but it is not the same type as the control being dragged or dropped.
How would I access the control itself to implement your suggestion? The timer event handler does actually show MessageBoxes saying the word "Hello" every interval. Please provide additional information.
P.S. Others may respond as well.
*****************Guffa's Message**********
We start with this:
new_phoenix wrote:
and how would a timer be used to get the form to redraw itself?
If you use a timer to trigger the movement of the control, the main message pump would handle messages in between the timer events. If you just change the location of the control, both the control and the previous area of the control will be invalidated. This creates messages that will be handled by the message pump. The message pump will call the Paint event of the control and the form, which will repaint the control and the part of the form that was invalidated.
new_phoenix wrote:
How could it be done in a loop
The x position of a point on the line can be interpolated like this:
x = startX + (endX - startX) * index / 64
where index is the index of the point from 0 to 64.
The y position can be calculated in the same way.
You don't even have to create an array of points, you can just calculate the position directly in the timer event.
---
single minded; short sighted; long gone;
|
|
|
|
|
The sender object in your dragDropTimer_Tick event is going to be the timer, try creating a public variable of type control and setting it to the calling control in your ProvideDragPathReturnToParent event and use that variable in your dragDropTimer_Tick event
Hope that helps
|
|
|
|
|
Please keep the responses in the same thread.
---
single minded; short sighted; long gone;
|
|
|
|
|
How to change the wallpaper on my desktop.
C#
|
|
|
|
|
http://www.codeproject.com/info/search.asp?cats=2&cats=3&cats=4&cats=5&cats=6&cats=8&cats=9&searchkw=wallpaper&Submit1=Search&author=&sd=15+Nov+1999&ed=11+Mar+2007
|
|
|
|
|
I declare "private System.Windows.Forms.Panel mypanel;" in window form to get a panel name my panel.
Can i declare "System.Windows.Forms.Panel [] mypanel;" to get an array of panel because i want to generate couple of mypanel during runtime...
|
|
|
|
|
Yes you can, you just have to remember to new up each panel in the array prior to use...
|
|
|
|
|
Thanks for the useful information
|
|
|
|
|
However, it's not really going to work. To do this, you need when you create each Panel, pass it into the forms Controls collection, and it's often easier just to create Panels and find them from the Controls collection.
foreach(Control c in Controls)
{
if (c is Panel)
{
}
// OR
Panel p = c as Panel;
if (p != null)
{
}
}
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hello,
I want to write a small vocabulary trainer (EN <=> Spanish).
Now I need to know, if two strings are similar. When the trainer ask you, what the meaning of "veinte" is, and the user writes "tewnty" instead of "twenty" the application should only remark that there is a small mistake in the input. When he writes a total different word (e.g. wine) then the trainer should say, that there is a mistake in the input.
Know anyone of you a good class, which compares two strings on similarities? The class should detect if there is a letter missing or a letter too much (or 2 letters are flipped).
Till now I just found classes, which compares complete texts and which say that a line in text A is different to a line in text B.
Bye
|
|
|
|
|
You'd have to write something to do this. A starting point may be to sort both strings alphabetically, and then compare them, to work out if you only have an error of letter order. Then you can walk them character by character, to work out a list of letters that were added, and that were missing, if the wrong letters were also used.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
There are a number of algorithms that have been developed to determine the similarity between strings (either spelling-wise or pronunciation-wise). A quick Google search brought up this[^], which should give you a good starting point.
-Phil
|
|
|
|
|
I want to move Image through a Path on form
I mean from many points in form until reach destianation
from A , B ,c , d
Like a Flash ,
please Help me.
-- modified at 11:39 Saturday 10th March, 2007
|
|
|
|
|
You need to either use a picturebox ( this is for girls ), or draw the image yourself. You need to set a timer, and handle your paint event. Your timer needs to call Invalidate() to force a paint message, and your paint event needs to draw the image in the right location.
Actually, if you use a picturebox, your timer event can set it's location without having to Invalidate(), but that solution doesn't scale well if you have a lot of images.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thank You very much !
Keep in touch
|
|
|
|
|
Hi,
I'm fighting with performance problems in application which displays data from sound card on the fly.
How can I suppress repaintig a form everytime I move other window over the form or scroll it?
Can I control painting the form only programmaticaly, makes the form holds its state when other window covers it and simply ignore such an events?
|
|
|
|
|
-raada- wrote: How can I suppress repaintig a form everytime I move other window over the form or scroll it?
You can't.
-raada- wrote: Can I control painting the form only programmaticaly, makes the form holds its state when other window covers it and simply ignore such an events?
What you are asking is, you want the form to not refresh itself when it is obscured. If the form is covered, it won't paint itself. It will paint itself when it is uncovered again, or it will be blank.
You can set the AllPaintInWMPaint ( something like that ) control flag, and override the Paint event to control exactly what gets painted. You could set flags within the program which cause this event to do nothing, but, of course, your program will then be ugly.
How do you know that the paint event is your performance problem ? What are you painting ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I know it because when the painting module is not attached the problem doesn't exist. (Module works with already preprocessed data and doesn't do much other thing then just paint them.)
Each sample is represented by array of double values which represents intensity of given frequency in that sample - when it's bigger than a threshold I paint a line at proper place (x axis is time y frequency)
When I repaint the whole signal when new sample was processed - it was unbearable.
Painting is executed in separate thread and I couldn't achieved satisfying results by just set time interval for repainting the signal.
So now I paint just individual samples by calling InvalidateRectangle method and whole signal when Paint event is fired not programmaticaly. But still not satisfyed.
I was asking just to be sure if I have to optimalize painting algorythm or I'm missing something else.
|
|
|
|
|
It does sound like your actual painting code needs optimising. Not drawing parts of it, is not optimisation.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi,
how much data is there to paint ? More samples than pixels in a row ?? If so, reduce the paint work
by either skipping or taking an average value.
It might help to show some code (and some typical values).
|
|
|
|
|
Hi Luc,
well ... I supppose that the most used setting will lead to 160 or 80 Hz frequency when 256 long array of transformed double values has to be processed by painting algorythm.
here is sample code
private void DrawDFTSample(double[] sample, Graphics g)
{
Range yRange = description.YRange;
double colorIndex = 0;
double colorIndexStep = description.Colors.Length / sample.Length;
double fi;
int yGraphBeginning = Height;
double yDisplay;
int xDisplay = currentRectangle.X + currentRectangle.Width / 2;
Pen p = new Pen(Color.Red);
p.Width = (currentRectangle.Width > 1) ? currentRectangle.Width - 1 : 1;
double threshold = 0;
yDisplay = yGraphBeginning;
for(int i=0; i<sample.Length; i++)
{
fi = sample[i];
if(fi >= threshold)
{
p.Color = description.Colors[(int)colorIndex];
yDisplay -= yPixStep;
g.DrawLine(p, xDisplay-1, (int)yDisplay, xDisplay+1, (int)yDisplay);
}
colorIndex += colorIndexStep;
}
counter++;
currentRectangle.X = (int)((double)counter * xPixStep);
}
Now I will try to optimize it by storing already computed values into array of points so I will be able to just draw them without reprocessing signal values when need to repaint whole signal occur.
Hope it will help me
|
|
|
|
|
Hi,
at first glance your code is OK except maybe for p.Color=...
I am not sure but this seems potentially the most expensive line in the for loop.
May I suggest you first retry with only one pen that does not change at all;
if perfo then is all right (or at least much better), make an array of pens
corresponding to description.Colors[] unless that array is really big.
Furthermore I am confused by the line
colorIndexStep = description.Colors.Length / sample.Length;
since it suggests there are more colors than samples (and with 256 samples, that would
be a lot of colors...)
And what is the "160 or 80 Hz frequency" you mentioned ?
is this the rate at which you hope to get the display updated ?? I dont think
Windows can do this at all (see my timers article !).
Best regards.
|
|
|
|