|
Not really, because I don't know the answer. I do know it's not on that page.
Well, I know how to multiply in GF(2k), using shifts and xors, but I'm not so sure about that remainder.
|
|
|
|
|
I don't know the answer either, but given the lack of any useful detail in the question I pointed OP to the C# mathematical operators. If he comes back with something more concrete then I'll try a bit harder.
|
|
|
|
|
Seems pretty clear to me, multiply and take the remainder by the polynomial, all in GF(256). I've found the answer now so I guess I'll post that..
|
|
|
|
|
Adapted from this[^] but not tested: (probably pretty close though)
int gmul(int a, int b) {
int p = 0;
int counter;
int carry;
for (counter = 0; counter < 8; counter++) {
if ((b & 1) != 0)
p ^= a;
carry = a & 0x80;
a <<= 1;
if (carry != 0)
a ^= 0x81;
b >>= 1;
}
return p & 0xFF;
}
|
|
|
|
|
Hi everyone,
I need a function to redact possible SSNs and CCs from a string.
This is for an application that receives messages from customers, which may contain SSNs or CCs. Instead of passing on that message, we want to redact it of the sensitive information.
We do have some SQL functions that do this, but I want to duplicate what they do in C# as we don't want to use Databases.
Have any of you done this sort of thing before?
All the Best to You!
Anne
|
|
|
|
|
This sounds like a good case for RegEx.
What method were you using in SQL?
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
The functions are here:
http://files.engineering.com/getfile.aspx?folder=0cc581bd-5691-4c60-b0b2-c35b2b7f7a10&file=dbo.fnFixCCandSSN-sqlFunction.txt
http://files.engineering.com/getfile.aspx?folder=b19b9e78-975a-4ca2-9fec-aa852367819b&file=dbo.fnIsLuhnValid-sqlFunction.txt
Thank you so very much for your help!!!
Anne
|
|
|
|
|
|
I think I have found my answer:
private static string RedactCC(string stringToRedact)
{
const string pattern = @"(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})";
stringToRedact = Regex.Replace(
stringToRedact,
pattern,
m => "***-**-" + m.Value.Substring(m.Value.Length - 4, 4));
return stringToRedact;
}
private static string RedactSSN(string stringToRedact)
{
const string pattern = @"\d{3}-\d{2}-\d{4}";
stringToRedact = Regex.Replace(
stringToRedact,
pattern,
m => "***-**-" + m.Value.Substring(m.Value.Length - 4, 4));
return stringToRedact;
}
Maybe this post will help someone else in the future.
Anne
|
|
|
|
|
|
Find() will only load the one object. It will not load related objects. Use SingleOrDefault() instead.
If there is no primary key field for a table, EF will not work with it. You MUST define the ID field for the table, otherwise EF has no way of updating that table.
|
|
|
|
|
|
Take a look at ObjectQuery.MergeOption[^]
As I recall from a few years ago, this was related to Entity loading (or not) related objects.
A positive attitude may not solve every problem, but it will annoy enough people to be worth the effort.
|
|
|
|
|
|
Whoops! I forgot to put that in the post.
using (var context = new MyDbContext())
{
var items = context.MyTable.Include(c => c.YourRelatedCollection).Where(...);
}
You don't need a stored procedure to load related enties.
|
|
|
|
|
|
Note: I'm using VS 2015 CTP 6, but I have not seen this issue outside the Application described here using VS 2015. I observe the same behavior if the project is opened in Visual Studio 2013.
My MainForm instantiates a second utility Form, and the 'Owner property of that utility Form instance is set to the instance of the MainForm. There is only one instance of the utility Form created.
The utility Form has its FormClosing Event set so it hides the utility Form, rather than allowing it to be closed (by setting the FromClosingEventArgs.cancel property to 'true).
Here's the MainForm 'Closing EventHandler:
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
if(utilityForm != null) utilityForm .Dispose();
} How could omitting explicitly setting the value of e.Cancel to 'false in the MainForm's code produce this behavior ? Calling utilityForm.Dispose should have no possible impact on the FormClosingEventArgs of the MainForm.
Appreciate any ideas.
thanks, Bill
«To kill an error is as good a service as, and sometimes even better than, the establishing of a new truth or fact» Charles Darwin in "Prospero's Precepts"<</font>
modified 5-Mar-15 9:57am.
|
|
|
|
|
Ooh I think you have a owned form which isn't playing cricket! When the owner begins to close it tries to close the owned form but can't and then the owner's FormClosing event handler is supplied with a precancelled event args.
Rather than dispose of the utility form you should allow the form to close itself. In the example I assume that Hide should only occur when the user attempts to close the form manually.
protected override void OnFormClosing(FormClosingEventArgs e) {
if (e.CloseReason == CloseReason.UserClosing) {
Hide();
e.Cancel = true;
}
base.OnFormClosing(e);
}
Alan.
|
|
|
|
|
Thanks, Alan, that does take care of the problem. I never thought that the 'Owned Form relationship could be a factor !
«To kill an error is as good a service as, and sometimes even better than, the establishing of a new truth or fact» Charles Darwin in "Prospero's Precepts"<</font>
|
|
|
|
|
Hi,
I am using below code to save image to database.
I would like to ask how can I modify to save PDF to the database?
using (var memoryStream = new MemoryStream())
{
pictureDocument.Image.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png);
byte[] employee_document = memoryStream.ToArray();
sql_command.Parameters.AddWithValue("param_document", employee_document).MySqlDbType = MySqlDbType.LongBlob;
}
Thanks,
Jassim
Technology News @ www.JassimRahma.com
|
|
|
|
|
Convert your PDF to a byte stream and save that instead. You can use a file stream to do this.
|
|
|
|
|
Hi all,,
I was reading about sending a mouse motion to for example Notepad..
I tried to implement something to help me send a right click to Notepad so when the event fired it shows that there is a right click fired and the right click menu appears in the notepad..
I wrote this code but I'm not sure it's correct -no error but it doesn't work..
// to send the mouse Message
[DllImport("user32.dll")]
public static extern int SendMessage(int hWnd,uint Msg, int wParam,int lParam);
// mouse input
private const uint WM_RBUTTONDOWN = 0x0204;
private const uint WM_RBUTTONUP = 0x0205;
// event handler
private void button6_Click(object sender, EventArgs e)
{
int window = FindWindow(null, "Notepad");
SendMessage(window, WM_RBUTTONDOWN, 0, 0);
SendMessage(window, WM_RBUTTONUP, 0, 0);
}
it does not work for me,,
Do I need to add extra code or functions for that??
Thanks
|
|
|
|
|
|
fyi: according to the site, the Mouse Simulation facility was never implemented.
«To kill an error is as good a service as, and sometimes even better than, the establishing of a new truth or fact» Charles Darwin in "Prospero's Precepts"<</font>
|
|
|
|
|
Well, I actually bothered to look at the code.
There is an interface (IMouseSimulator) and a class (MouseSimulator) that look suspiciously like they may have to do something with the mouse.
And executing the MouseMoveTo() method actually moved the mouse!
Maybe there is some functionality missing, but it's a pretty good start: including mouse clicks; double-clicks; left / right buttons; etc.
|
|
|
|