|
thanks for your suggest
|
|
|
|
|
You're welcome!
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
What have you tried?
Where are you stuck?
What help do you need?
We aren't here to do it all for you - we'll help, but you need to show that you are trying as well, not just trying to get us to do your job for you! And so far, all you done is say what you want as a result...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
no no I'm sorry about that, I don't mean like that. I was try to build application about steganography. It was use AES encryption and LSB technique and I had a problem on the extention of audio. The Cover audio is wav and midi but when I was insert chipertext into audio(midi) there is a problem with the code and so much the noise (the SNR is so weak)
this is my code: AES Encryption steganography cover audio using LSB technique
using System;
using System.Drawing;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace StegAudio
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void buttonnamafile_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
GetFileName(dlg, textBoxHideFile, false);
}
private void buttontempatfile_Click(object sender, EventArgs e)
{
SaveFileDialog dlg = new SaveFileDialog();
GetFileName(dlg, textBoxDestFile, true);
}
private void GetFileName(FileDialog dialog, TextBox control, bool useFilter)
{
if (useFilter) { dialog.Filter = "Wave Audio (*.wav)|*.wav|MIDI (*.mid)|*.mid";}
if (dialog.ShowDialog(this) == DialogResult.OK)
{
control.Text = dialog.FileName;
}
}
private string GetFileExtension(string filename)
{
return filename.Substring(filename.Length - 3, 3);
}
private void buttoncariaudio_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
GetFileName(dlg, textBoxHideAudio, true);
}
private void buttonfileakhir_Click(object sender, EventArgs e)
{
SaveFileDialog dlg = new SaveFileDialog();
GetFileName(dlg, textBoxExtDest, false);
}
private void buttonsembunyi_Click(object sender, EventArgs e)
{
if(textBoxHideAudio.Text.Length == 0)
{
errorProvider1.SetError(textBoxHideAudio, "You forgot to choose a carrier file.");
}
else if(textBoxPWH.Text.Length == 0)
{
errorProvider1.SetError(textBoxPWH, "You forgot to write a key.");
}
else if(textBoxDestFile.Text.Length == 0)
{
errorProvider1.SetError(textBoxDestFile, "The resulting carrier file must be saved somewhere.");
}
else if (textBoxHideFile.Text.Length == 0)
{
errorProvider1.SetError(textBoxHideFile, "What am I supposed to hide?");
}
else
{
//before we hide the message into the wav file, we must encrypt it first
//in this case, we are using Rijndael encryption
MyEncryptor encryptor = new MyEncryptor(textBoxPWH.Text); //we use the key password as a secret phase
String encryptedMessage = encryptor.Encrypt(GetMessageString());
//reset all the stream first
Stream sourceStream = null;
FileStream destinationStream = null;
WaveStream audioStream = null;
Stream messageStream = GetMessageStream(encryptedMessage); //write the encrypted message into the stream
Stream keyStream = GetKeyStream();
string fileExtension; //fileextension indicating the format of audio file as the carrier of the secret message
fileExtension = GetFileExtension(textBoxHideAudio.Text);
if (fileExtension.Equals("wav"))
{
try
{
//how many samples do we need
long countSampleRequired = WaveUtility.CheckKeyForMessage(keyStream, messageStream.Length);
if (countSampleRequired > Int32.MaxValue)
{
throw new Exception("Message too long, or bad key! This message/key combination requires " + countSampleRequired + " samples, only " + Int32.MaxValue + " samples are allowed.");
}
//use wav file as the carrier
sourceStream = new FileStream(textBoxHideAudio.Text, FileMode.Open);
this.Cursor = Cursors.WaitCursor;
//create empty file for the carrier wave
destinationStream = new FileStream(textBoxDestFile.Text, FileMode.Create);
//copy the carrier file's header
audioStream = new WaveStream(sourceStream, destinationStream);
if (audioStream.Length <= 0)
{
throw new Exception("Invalid WAV file");
}
//are there enough samples in the carrier wave?
if (countSampleRequired > audioStream.CountSamples)
{
String errorReport = "The carrier file is too small for this message and key!\r\n"
+ "Samples available: " + audioStream.CountSamples + "\r\n"
+ "Samples needed: " + countSampleRequired;
throw new Exception(errorReport);
}
//hide message
WaveUtility utility = new WaveUtility(audioStream, destinationStream);
utility.Hide(messageStream, keyStream);
}
catch (Exception ex)
{
this.Cursor = Cursors.Default;
MessageBox.Show(ex.Message);
}
finally
{
if (keyStream != null) { keyStream.Close(); }
if (messageStream != null) { messageStream.Close(); }
if (audioStream != null) { audioStream.Close(); }
if (sourceStream != null) { sourceStream.Close(); }
if (destinationStream != null) { destinationStream.Close(); }
this.Cursor = Cursors.Default;
MessageBox.Show("file has success Inserted");
}
}
else if (fileExtension.Equals("mid"))
{
//i'll make it simple, coz the method is slightly different in code than wav. Another reason is that i'm lazy enough not to port the code.
try
{
this.Cursor = Cursors.WaitCursor;
MidiUtility utility = new MidiUtility();
utility.HideMessage(textBoxHideAudio.Text, textBoxDestFile.Text, messageStream, keyStream);
}
catch (Exception ex)
{
this.Cursor = Cursors.Default;
MessageBox.Show(ex.Message);
}
finally
{
if (keyStream != null) { keyStream.Close(); }
if (messageStream != null) { messageStream.Close(); }
if (audioStream != null) { audioStream.Close(); } //actually, these two streams aren't needed in this method
if (sourceStream != null) { sourceStream.Close(); } //but let's write them anyway...
if (destinationStream != null) { destinationStream.Close(); }
}
}
}
}
private Stream GetMessageStream()
{
BinaryWriter messageWriter = new BinaryWriter(new MemoryStream());
//open the file to be hidden
FileStream fs = new FileStream(textBoxHideFile.Text, FileMode.Open);
int filelength = (int)fs.Length;
messageWriter.Write(filelength); //save the length of file into binary stream
byte[] buffer = new byte[fs.Length]; //allocate the buffer as big as the file length
fs.Read(buffer, 0, filelength); //read the file into the buffer
messageWriter.Write(buffer); //save the buffer into binary stream
fs.Close(); //close the file when operation finished
messageWriter.Seek(0, SeekOrigin.Begin);
return messageWriter.BaseStream;
}
private Stream GetMessageStream(string message)
{
BinaryWriter messageWriter = new BinaryWriter(new MemoryStream());
messageWriter.Write(message.Length);
messageWriter.Write(Encoding.ASCII.GetBytes(message));
messageWriter.Seek(0, SeekOrigin.Begin);
return messageWriter.BaseStream;
}
private String GetMessageString()
{
FileStream fs = new FileStream(textBoxHideFile.Text, FileMode.Open);
StreamReader rd = new StreamReader(fs);
return rd.ReadToEnd();
}
private Stream GetKeyStream()
{
BinaryWriter keyWriter = new BinaryWriter(new MemoryStream());
//write the password to the binary stream
keyWriter.Write(Encoding.ASCII.GetBytes(textBoxPWH.Text));
keyWriter.Seek(0, SeekOrigin.Begin);
return keyWriter.BaseStream;
}
private void buttonekstract_Click(object sender, EventArgs e)
{
if (textBoxHideAudio.Text.Length == 0)
{
errorProvider1.SetError(textBoxHideAudio, "You forgot to choose a carrier file.");
}
else if (textBoxPWH.Text.Length == 0)
{
errorProvider1.SetError(textBoxPWH, "You forgot to write a key.");
}
else
{
this.Cursor = Cursors.WaitCursor;
FileStream sourceStream = null;
WaveStream audioStream = null;
//create an empty stream to receive the extracted message
MemoryStream messageStream = new MemoryStream();
Stream keyStream = GetKeyStream();
string fileExtension; //fileextension indicating the format of audio file as the carrier of the secret message
fileExtension = GetFileExtension(textBoxHideAudio.Text);
if (fileExtension.Equals("wav"))
{
try
{
//open the carrier file
sourceStream = new FileStream(textBoxHideAudio.Text, FileMode.Open);
audioStream = new WaveStream(sourceStream);
WaveUtility utility = new WaveUtility(audioStream);
//extract the message from the carrier wave
utility.Extract(messageStream, keyStream);
messageStream.Seek(0, SeekOrigin.Begin);
//save result to a file
FileStream fs = new FileStream(textBoxExtDest.Text, FileMode.Create);
//before the result message is saved in the destination file, decrypt it first
MyEncryptor decryptor = new MyEncryptor(textBoxPWH.Text); //we use the key password as a secret phase
StreamReader rd = new StreamReader(messageStream);
String decryptedMessage = decryptor.Decrypt(rd.ReadToEnd());
StreamWriter wr = new StreamWriter(fs);
wr.Write(decryptedMessage);
wr.Flush();
fs.Close();
}
catch (Exception ex)
{
this.Cursor = Cursors.Default;
MessageBox.Show(ex.Message);
}
finally
{
if (keyStream != null) { keyStream.Close(); }
if (messageStream != null) { messageStream.Close(); }
if (audioStream != null) { audioStream.Close(); }
if (sourceStream != null) { sourceStream.Close(); }
this.Cursor = Cursors.Default;
MessageBox.Show("Ekstraksi Pesan Telah Selesai");
}
}
else if (fileExtension.Equals("mid"))
{
try
{
MidiUtility utility = new MidiUtility();
utility.ExtractMessage(textBoxHideAudio.Text, null, messageStream, keyStream);
messageStream.Seek(0, SeekOrigin.Begin);
//save result to a file
FileStream fs = new FileStream(textBoxExtDest.Text, FileMode.Create);
//before the result message is saved in the destination file, decrypt it first
MyEncryptor decryptor = new MyEncryptor(textBoxPWH.Text); //we use the key password as a secret phase
StreamReader rd = new StreamReader(messageStream);
String decryptedMessage = decryptor.Decrypt(rd.ReadToEnd());
StreamWriter wr = new StreamWriter(fs);
wr.Write(decryptedMessage);
wr.Flush();
fs.Close();
}
catch (Exception ex)
{
this.Cursor = Cursors.Default;
MessageBox.Show(ex.Message);
}
finally
{
if (keyStream != null) { keyStream.Close(); }
if (messageStream != null) { messageStream.Close(); }
if (audioStream != null) { audioStream.Close(); }
if (sourceStream != null) { sourceStream.Close(); }
this.Cursor = Cursors.Default;
MessageBox.Show("Extraction Messages Completed");
}
}
}
}
}
}
|
|
|
|
|
I am splitting this out and returning it as separate rows The delim is \r\n:
{[Report Criteria, Filter Criteria
:.Archived
: :.All
:.Request ID
: :.xxx
:.Group & Sort Criteria
:.Employee Name Ascending
:.Agency Org Ascending
Report Executed on : xxxxxxxxxxxxxxxxxx UTC]}
Here is the code: I am going to replace rx with rx1, but rx1 does not have "rx1.MoveNext" look below
var rx = ((IEnumerable)e.Current).GetEnumerator();
IEnumerable enumerable;
var rx1 = (IEnumerable)rebuildReportCriteria(((IEnumerable)e.Current).GetEnumerator());
for (int j = 0; rx1.MoveNext(); j++)
{
object v = ((KeyValuePair<string, object>)rx.Current).Value;
string s = "", l = "";...................................
private static object rebuildReportCriteria(IEnumerator enumerator)
{
var list = new List<KeyValuePair<string, string>>();
string v = "";
for (int j = 0; enumerator.MoveNext(); j++)
{
v = ((KeyValuePair<string, object>)enumerator.Current).Key;
if (v == "Report Criteria")
{
string[] stringSeparators = new string[] { "\r\n" };
string[] lines = ((KeyValuePair<string, object>)enumerator.Current).Value.ToString().Split(stringSeparators, StringSplitOptions.None);
foreach (string s in lines)
{
list.Add(new KeyValuePair<string, string>(((KeyValuePair<string, object>)enumerator.Current).Key, ((KeyValuePair<string, object>)enumerator.Current).Value.ToString()));
}
}
}
if (v == "Report Criteria")
{
return list.GetEnumerator();
}
else
{
return enumerator;
}
}
modified 10-Mar-16 11:24am.
|
|
|
|
|
|
Hi,
In my application I am in the process of writing I am building a string containing the result of a test and a comma to be saved out as a CSV file however a test can be re-triggered by accident, not an issue. The problem I have is that the re-triggering can lead to a result being added to the string. I have added a Boolean variable to see if its being re-triggered and if it is only add to the string once see below:
lblPumpMotorSpin_.BackColor = Color.Green;
if (ResultsRecordedOncePumpMotor == false)
{
Results += "Pump Motor OK,";
}
ResultsRecordedOncePumpMotor = true;
This then reset to false in the reset routine for the next attempt.
My thinking was this before it entered Reset() which was after the save routing it would be set to true so it would not enter the if(), but it does!
Any thoughts anyone??
Glenn
modified 11-Mar-16 8:22am.
|
|
|
|
|
What are they declared as?
Are Results and ResultsRecordedOncePumpMotor both static, or both class instance? Or a mix of the two?
If the test can be restarted while a test is in progress, then that implies multiple threads, so you probably want to cancel any running test before you start a new one - which would get rid of the need for the bool.
And a couple of style points:
1) You can use "!" instead of "== false"
if (!ResultsRecordedOncePumpMotor)
2) You shouldn't really add to strings, particularly to build large results sets. Since strings are immutable, each time you add two strings, you create a new longer one and copy both over. Use a StringBuilder instead and Append the data - it's a lot more efficient.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Ah Ha! Threads dang it! Thanks for that.
|
|
|
|
|
You're welcome!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Umm Griff, do you know of a good string builder reference as I can create the string save the string like I could with a string, how can I search the string to find the last item added to it and if its the same don't append it?
Further reading has revealed the .Remove method, however I am not sure this would work as you have to know the exact location in the string, however if you placed a test loop after each function that talked to the string something like
int i=0;
foreach(string subString in sbResults(',')
i++
if( i >4)
{
MessageBox.Show("extra!");
sbResults.Remove(i,5);
} if the message was 5 long. Am I on to anything here??
modified 10-Mar-16 11:11am.
|
|
|
|
|
StringBuilders don't have Contains, StartsWith, or EndsWith methods - so basically you can't search one.
What are you actually building up? Is this a single line of CSV data, or a file full, or what?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Sorry looks like you replied as I was updating my earlier response, I cannot type today for some reason. Its a single line of a CSV, some times the data can get duplicated via a switch...
|
|
|
|
|
I'd be tempted to say "sod that" and cheat!
Is the order important?
If not, then create a List<String> of elements to make up your CSV data, and use the Linq Method .Distinct to remove duplicates. Then String.Join to bolt 'em together with commas.
string csv = string.Join("," myList.Distinct());
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
The order is not really important, I am starting the record process from scratch. Thanks I will give it a look.
|
|
|
|
|
If threads are causing your duplicate, you're in even bigger trouble, since you are also accessing a Control property, something only the GUI thread is allowed to do.
IMO your code needs a big overhaul: use a model that holds your data, a view that takes care of the UI, and a separate object (or at least an explicit method) to create the output file(s) you need.
By not mixing it all up you'll avoid both illegal cross-thread Control accesses and the risk of duplicates in your CSV.
|
|
|
|
|
Thanks, I will give a look!
|
|
|
|
|
I would more likely keep a Dictionary or something to hold the items to be written, you can add an item more than once and it'll just overwrite the existing value, then format and write it once everything is ready.
A small class could easily be written to encapsulate Add, Write, Clear functions.
|
|
|
|
|
I'll look into that! Thanks
|
|
|
|
|
Hi.
Lemme try to be clear here.
I've a code, with two files: Form1.cs and Classes.cs
Classes.cs contains all my methods, variables, etc (and the FilesystemWatcher implementation).
Form1.cs (The main form) contains some button calls, and a call to FilesystemWatcher (when the button is pressed).
What i'm trying to accomplish and can't see to figure out is: Show a ProgressBar from this FilesystemWatcher.
Consider the following scenario: I Just clicked a button and FilesystemWatcher has started. It will monitor the folder and do operations over created files. How i'm gonna show the progress for that ?
On my readfiles() method (inside the Classes.cs) i've tought about passing a variable trough parameter that indicates how much of the file has been read - for so i would have to implement FilesystemWatcher in the Form1.cs. But the FilesystemWatcher calls all my methods.
His method on Classes.cs looks like:
SetupFileWatcher()
all other methods to convert files, etc...
Even if i move FilesystemWatcher to Form1 main code, he doesn't return any progress value - he just run methods as soon files are added.
Lemme try to show a piece of code (This happens at Classes.cs)
Implementing filesystem watcher on this method...
protected FileSystemWatcher SetupFileWatcher(string path)
FileSystemWatcher Call
public void ProgramProcessing(string filePath)
{
SetupFileWatcher(SelectedFolder);
InputFolderSelect();
ReadFiles();
FileDefinition();
ColorExtraction();
ColorValueExtraction();
DataGrouping();
NumberProcessing();
ColorPoolManipulation();
WriteInkzoneXML();
WriteColorPoolXML();
}
Now, this happens inside Form1.cs:
private void btnGo_Click_1(object sender, EventArgs e)
prg.ProgramProcessing(textBox1.Text);
How could i possibly achieve that ? Is it possible ? Al i would like is to show the progress for the operation (or at least the methods for reading files and write XML).
Thanks in advance for any help\guidance.
|
|
|
|
|
|
Message Removed
modified 8-Mar-16 4:20am.
|
|
|
|
|
Hi All,
I am trying to write console application using C# which can export IBM DB2 table data from master database and import same to IBM DB2 table in target database , provided both tables are not coming under same DB2 instance.
can someone please provide direction how to achieve this ?
I tried using DB2BulkCopy Class but not succeeded.
pls help
Thanks
|
|
|
|
|
|
Or you can hit it with a hammer - make a connection to DB1, query the data and store it somewhere.
Connect to DB2 and write each record into the target table from the temp store.
Definitely not elegant and may be unworkable with serious volume.
Explore setting up a linked server and creating a stored proc that can do the job without taking the data into your c# client.
There should also be the equivalent of SQL Servers DTS ETL tools!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|