Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
tef
May 30, 2004

-> some l-system crap ->
What is IsAllowed defined as?

Adbot
ADBOT LOVES YOU

Fruit Smoothies
Mar 28, 2004

The bat with a ZING

tef posted:

What is IsAllowed defined as?

It returns true if the pair is allowed, and false if the pair is forbidden.

Patashu
Jan 7, 2009
What exactly happens in the computer when a process waits for a certain amount of time? As in, what's done to ensure that the processor continues its execution at the appropriate time? I came up with the idea of an automatically sorted list of (long) system times in milliseconds linked to what process would be woken up, incrementing every millisecond and checking the first value to see if it was time (and the second if that worked and so on in case there are ties) but I'm sure that's not how it's done.

tef
May 30, 2004

-> some l-system crap ->

Fruit Smoothies posted:

It returns true if the pair is allowed, and false if the pair is forbidden.

You really have a knack for answering a question without any substance.


This is I think the third time I've asked for your constraints and either you present a different set to the one you want to implement (primes), or in this case you manage to tell me "isallowed" is whether a pair is allowed.


When someone asks for the definition, the mean the code.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

Patashu posted:

What exactly happens in the computer when a process waits for a certain amount of time? As in, what's done to ensure that the processor continues its execution at the appropriate time? I came up with the idea of an automatically sorted list of (long) system times in milliseconds linked to what process would be woken up, incrementing every millisecond and checking the first value to see if it was time (and the second if that worked and so on in case there are ties) but I'm sure that's not how it's done.

http://en.wikipedia.org/wiki/Scheduling_(computing)

Or if you really want depth, /usr/src/linux/kernel/sched.c

e: on second thought a bsd kernel is probably way more readable, so i guess grab a fbsd image and poke around /usr/src/sys/ for something that looks like a scheduler if you're interested

Blotto Skorzany fucked around with this message at 15:43 on Apr 5, 2009

Fruit Smoothies
Mar 28, 2004

The bat with a ZING

tef posted:

You really have a knack for answering a question without any substance.


This is I think the third time I've asked for your constraints and either you present a different set to the one you want to implement (primes), or in this case you manage to tell me "isallowed" is whether a pair is allowed.


When someone asks for the definition, the mean the code.

The problem I am having, is working out how to loop through the tree. It makes no difference to the problem what the IsAllowed() function does, or how it works. All it does, is confirm whether or not a pair is valid based on a set of constraints.

If you want the code, here it is with some of the constraints not yet added, because it's harder to debug with them all in initially.

code:
function IsAllowed(a, b: Integer): Boolean;
var
da, fi, gr, dr,ps,ro,ic,wa,gra,fir,el,fl: set of 1..255;
begin
//
// Each of these refer to the disallowed types
//
da := [1,2,3,4,5];
fi := [1,2,3,4,5,6,7,11,12];
gr := [1,3,2,4,6,11];
dr := [1,2,3,4,6,7,9,10,11];
ps := [1,2,5,10,11];
ro := [2,3,11,7,4,6];
ic := [7,2,10,11,6,4];
case a of
  1:
      if b in da then
        result := false;
  2:
      if b in fi then
        result := false;
  3:
      if b in gr then
        result := false;
  4:
      if b in dr then
        result := false;
  5:
      if b in ps then
        result := false;
  6:
      if b in ro then
        result := false;
  7:
      if b in ic then
        result := false;
  8: result := true;
  9: result := true;
  10: result := true;
  11: result := true;
  12: result := true;
end;
end;

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Fruit Smoothies posted:

If you want the code, here it is with some of the constraints not yet added, because it's harder to debug with them all in initially.

Now I'm really curious what your problem domain is, because that's a wacky set of constraints.

That said, visual inspection can give us a solution without too much trouble. We reformulate the constraints as allowed pairs rather than unallowed pairs:
pre:
 1:           6 7 8 9 10 11 12
 2:               8 9 10
 3:         5   7 8 9 10    12  
 4:         5     8         12  
 5:     3 4   6 7 8 9       12  
 6: 1       5     8 9 10    12  
 7: 1   3   5     8 9       12  
 8: 1 2 3 4 5 6 7 8 9 10 11 12
 9: 1 2 3 4 5 6 7 8 9 10 11 12
10: 1 2 3 4 5 6 7 8 9 10 11 12
11: 1 2 3 4 5 6 7 8 9 10 11 12
12: 1 2 3 4 5 6 7 8 9 10 11 12
Assign (1,6).
pre:
 2:               8 9 10
 3:         5   7 8 9 10    12  
 4:         5     8         12  
 5:     3 4     7 8 9       12  
 7:     3   5     8 9       12  
 8:   2 3 4 5   7 8 9 10 11 12
 9:   2 3 4 5   7 8 9 10 11 12
10:   2 3 4 5   7 8 9 10 11 12
11:   2 3 4 5   7 8 9 10 11 12
12:   2 3 4 5   7 8 9 10 11 12
Assign (2,8).
pre:
 3:         5   7   9 10    12
 4:         5               12
 5:     3 4     7   9       12
 7:     3   5       9       12
 9:     3 4 5   7   9 10 11 12
10:     3 4 5   7   9 10 11 12
11:     3 4 5   7   9 10 11 12
12:     3 4 5   7   9 10 11 12
Assign (3,5).
pre:
 4:                         12
 7:                 9       12
 9:       4     7   9 10 11 12
10:       4     7   9 10 11 12
11:       4     7   9 10 11 12
12:       4     7   9 10 11 12
Assign (4,12).
pre:
 7:                 9
 9:             7   9 10 11
10:             7   9 10 11
11:             7   9 10 11
Assign (7,9).
pre:
10:                   10 11
11:                   10 11
Assign (10,11), and we're done; no backtracking.

The only pair I'm not sure of is (10,11), because you didn't provide enough constraints.

Edit: [(1,11),(4,8),(6,12),(7,5),(3,9),(2,10)] is a solution that exists entirely within the constraints you specified.

ShoulderDaemon fucked around with this message at 18:18 on Apr 5, 2009

Fruit Smoothies
Mar 28, 2004

The bat with a ZING

ShoulderDaemon posted:

Now I'm really curious what your problem domain is, because that's a wacky set of constraints.

I'm really not going to go into the problem, because it really is complicated. Those are some of the constraints.

My concern is that making all these lists, and lists of lists isn't the best way to implement the backtracking. Also, with the complexity of the full-scale problem, human attempts would be rendered useless, because you'd have to permanently look these things up.

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Fruit Smoothies posted:

I'm really not going to go into the problem, because it really is complicated. Those are some of the constraints.

My concern is that making all these lists, and lists of lists isn't the best way to implement the backtracking.

Yeah, you're doing something crazy in there with parentOf and recursing up the search tree instead of down and I don't really understand what you want that code to do.

Backtracking would normally be done sort of like this:
code:
procedure findPairs( items ): // items has type list-of-integer
                              // return type is list-of-list-of-pair-of-integer
  if items is empty then:
    return [[]] // list with one element: an empty list
  else:

    let a = first element in items
    let l = list of elements in items after the first

    let ret = [] // empty list; we are building our return value here

    for each element b in l:

      let l' = list of elements in l, except for b

      if (a, b) is an allowed pair then:
        for each c in findPairs( l' ): // c is a list of pairs
          add (a, b) to c
          add c to ret

     return ret
Note that in a strict language, this procedure is also strict, so you won't get any results until every result is calculated. But that's fine, because this is a really trivial problem that you can fully enumerate in less than a second.

Fruit Smoothies posted:

Also, with the complexity of the full-scale problem, human attempts would be rendered useless, because you'd have to permanently look these things up.

I'm not sure I believe you, because so far everything you've posted has been really trivially easy to solve by hand, and I'm having trouble accepting that it's any easier to express your wacky constraints in code, debug the code, etc.

Fruit Smoothies
Mar 28, 2004

The bat with a ZING

ShoulderDaemon posted:

I'm not sure I believe you, because so far everything you've posted has been really trivially easy to solve by hand, and I'm having trouble accepting that it's any easier to express your wacky constraints in code, debug the code, etc.

I don't know why you'd think I'd lie about this. It's not difficult to do by hand, but it's lengthy. Additionally, the constraints change on a (fairly) regular bases, sometimes resulting in pairs within pairs and all sorts of complications that can be considered (if at all) after the backtracking is sorted.

I know what your code does there, and I have considered doing it myself, but a lot of this is about a learning curve, so I'd like to have a backtracker, rather than a list of permutations.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

ShoulderDaemon posted:

Now I'm really curious what your problem domain is, because that's a wacky set of constraints.

"Homework"

Fruit Smoothies
Mar 28, 2004

The bat with a ZING

Avenging Dentist posted:

"Homework"

I do a chemistry degree. I wish there was something this mentally challenging in there, and not scheme after scheme of organic mechanisms.

Incidentally, if you can write a program that calculates the best way to synthesize a compound from starting materials (or even better, picks starting materials) you will be very rich. That problem also involves tree-structures, and backtracking too.

tef
May 30, 2004

-> some l-system crap ->

Fruit Smoothies posted:

That problem also involves tree-structures, and backtracking too.

For a problem that involves abstract tree structures and backtracking, you really ought to take a closer look at prolog.

(I don't get to say this often, prolog is useless at nearly everything else)

What you're trying to do sounds like an Expert System, and people have been writing them in prolog for years.

Constrained search is what prolog excels at, and what compilers optimize for. There is also a strongly typed variant if you want excellent performance.

If you've done a little programming before, "The Art of Prolog" is an excellent guide to the language.

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Fruit Smoothies posted:

I don't know why you'd think I'd lie about this. It's not difficult to do by hand, but it's lengthy.

With the constraints you've been posting, it's been taking me less than a minute to find solutions each time. There's only twelve elements. Seriously, computers are overkill sometimes, if you can't solve these problems yourself faster than you can write a program, something is very wrong.

Fruit Smoothies posted:

Additionally, the constraints change on a (fairly) regular bases, sometimes resulting in pairs within pairs and all sorts of complications that can be considered (if at all) after the backtracking is sorted.

So, what you're saying is, you'd have to spend even more time writing an even more complicated program, and you'd have to change the program frequently to account for new rules, which may be difficult to express in your algorithm. These do not sound like good reasons for using a program.

Fruit Smoothies posted:

I know what your code does there, and I have considered doing it myself, but a lot of this is about a learning curve, so I'd like to have a backtracker, rather than a list of permutations.

First of all, I didn't do anything involving permutations in that pseudocode.

Secondly, backtracking is, exactly and precisely, the act of building a list of results at one level, then transforming that into a list of results from the next-highest level. To transform "idealized" backtracking code into a single-result form, you simply change the algorithm to only return the first element (if there is one) of the result list, and optimize away any calculations that would thus be redundant. In this case, such a transformation is trivial, because we have the nice property that if the recursive call returns any results, then they are all equally valid - in particular, the first one is valid, so we can eliminate list management altogether.

This trivially changes the pseudocode into the reduced form:
code:
data type MaybeList is one of:
  Failure
  Success list // list has type list-of-pair-of-integer

procedure findPairs( items ): // items has type list-of-integer
                              // return type is MaybeList
  if items is empty then:
    return Success []
  else:

    let a = first element in items
    let l = list of elements in items after the first

    for each element b in l:

      let l' = list of elements in l, except for b

      if (a, b) is an allowed pair then:

        let child = findPairs( l' )

        if child is Success childList then:
          add (a, b) to childList
          return Success childList

     return Failure
The only interesting property of lists that we are obligated to preserve in this case is that they may be empty, representing a failed search, because there is no concept in this problem of some results being "better" than others.

This is, honestly, the kind of problem I'd expect to see in an intro data structures class. It's about 100 lines of C with no need for dynamic allocation, is easy to verify by hand, and is operating on an incredibly tiny problem with questionable utility.

wrok
Mar 24, 2006

by angerbotSD

Fruit Smoothies posted:

I'm really not going to go into the problem, because it really is complicated.

Jesus Christ, give it up already. For serious how much more can you possibly drag this out....

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

ShoulderDaemon posted:

This is, honestly, the kind of problem I'd expect to see in an intro data structures class. It's about 100 lines of C with no need for dynamic allocation, is easy to verify by hand, and is operating on an incredibly tiny problem with questionable utility.

So, I said this, and then I started thinking to myself that I should be prepared to be called-out on a statement like this. My first try was 99 lines, but I like round numbers, so here's a 50 line version:
code:
#include <stdio.h>
#include <string.h>

#define MAX 12
#define BITS 4

static short allowed_bits[MAX] = { 0xfe0, 0x380, 0xbd0, 0x890, 0x9ec, 0xb91, 0x995 };

#define ALLOWED(f,i) (allowed_bits[(-1)[f]-1]&(1<<((i)[f]-1)))
#define PAIR(f,i) (((i)[f]<<BITS)|(-1)[f])

struct maybe_list {
  int elems;
  int pairs[MAX/2];
};

void find_pairs( struct maybe_list *ret, const int *from, int sz ) {

  if (! (sz-- || (*(int *)ret = 0))) return;

  int lprime[sz - 1];
  memcpy( lprime, ++from + 1, sizeof( lprime ) );

  for ( int i = 0; i < sz; lprime[i] = from[i], ++i )
    if ( ALLOWED(from,i) ) {
      int p = PAIR(from,i);

      find_pairs( ret, lprime, sz - 1 );
      if ( ret->elems >= 0 && (ret->pairs[ret->elems++] = p) )
        break;
    };

}

int main( int argc, char *argv[] ) {

  int starting_from[MAX+1];

  for ( int i = -1; i < MAX; ++i )
    starting_from[i + 1] = i + 1;
  --starting_from[0];

  struct maybe_list *result = (void *)&starting_from;

  find_pairs( result, starting_from + 1, MAX );
  while ( result->elems-- > 0 )
    fprintf( stdout, "(%d,%d) ", *result->pairs & ((1<<BITS)-1), *result->pairs >> BITS ), *result->pairs = result->elems[result->pairs];
  fprintf( stdout, "\n" );

}
I was worried about memory use, so it doesn't touch the heap and reuses a few memory locations. And yeah, I realize only 34 lines are code, the vertical space is to make it readable! It compiles without warnings in gcc's c99 mode; I didn't bother to test with anything else.

floWenoL
Oct 23, 2002

ShoulderDaemon posted:

So, I said this, and then I started thinking to myself that I should be prepared to be called-out on a statement like this. My first try was 99 lines, but I like round numbers, so here's a 50 line version:

Man, look at those strict aliasing violations.

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

floWenoL posted:

Man, look at those strict aliasing violations.

I wanted to make it even less defined, but any other changes I was making to it confused gcc enough to make it stop working on my laptop. If you drop the number of elements to 10 from 12, I have a version that works and uses code space to store the result list instead of reusing the initial elements list; I guess I could use an asm call to pad out this one and put that trick back in... actually, now that I think about it, there should be enough room in find_pairs instead of main where I was sticking them, so I could claim it was "broken memoization" or something...

Fruit Smoothies
Mar 28, 2004

The bat with a ZING

ShoulderDaemon posted:

With the constraints you've been posting, it's been taking me less than a minute to find solutions each time. There's only twelve elements. Seriously, computers are overkill sometimes, if you can't solve these problems yourself faster than you can write a program, something is very wrong.

Perhaps I should have said, near the beginning, that I don't have a huge amount of programming experience, especially when it comes down to the nitty-gritty way of algorithms. I can usually work out what's going on, but never the best way of doing it, which is why I posted in this thread.

Truly, and although it sounds like an exaggeration, this problem really can't be tackled manually in the long run. It will get to the stage when there are hundreds of numbers (which refer to categories) that need to be sorted in the most ridiculously lengthy constraints. Besides that, it will no doubt be translated into PHP, and stuck within our management panel.

ShoulderDaemon posted:

So, what you're saying is, you'd have to spend even more time writing an even more complicated program, and you'd have to change the program frequently to account for new rules, which may be difficult to express in your algorithm. These do not sound like good reasons for using a program.

You have said yourself, in your 50 lines of code, that it is not a complicated problem. Changing the IsAllowed() function is easy. At the moment, it involves sets. I have a vague expression parser that will be able to change these without recompiling.
There are no "good reasons to program" per ce. There are programs that help with drug development, and there are programs / websites to show random lolcats.


ShoulderDaemon posted:

First of all, I didn't do anything involving permutations in that pseudocode.

Your initial code considered all possibilities from a starting point.

ShoulderDaemon posted:

Secondly, backtracking is, exactly and precisely, the act of building a list of results at one level, then transforming that into a list of results from the next-highest level.

This is what my (messy and lengthy) code did. It made a list, until it couldn't, and then it went to the parent.

Thanks for the pseudocode, I will have a play with it, and hopefully have more success.

ShoulderDaemon posted:

This is, honestly, the kind of problem I'd expect to see in an intro data structures class. It's about 100 lines of C with no need for dynamic allocation, is easy to verify by hand, and is operating on an incredibly tiny problem with questionable utility.

I haven't done an intro data structure class, but I have watched the university of Berkley's webcast on comp sci. I'm working my way through their java lecture course now.

wrok posted:

Jesus Christ, give it up already. For serious how much more can you possibly drag this out....

I am not dragging it out, I am trying to understand, and get help which is what this thread it about.
The main reason it's turned into a saga, is because most people have been trying to find out WHY i need the code. I desperately don't want to go into this, because I feel I have already littered the thread enough.
If you're saying that I should give up, and stop asking for help because I haven't yet understood it, then you should rethink how you learn things.

hey mom its 420
May 12, 2007

It's just that people usually find it easier to help you with your problems if you present them in a wider context instead of just letting them see them through a small hole by witholding as much information about them as possible.

Fruit Smoothies
Mar 28, 2004

The bat with a ZING

Bonus posted:

It's just that people usually find it easier to help you with your problems if you present them in a wider context instead of just letting them see them through a small hole by witholding as much information about them as possible.

I agree that in order to solve a problem you need to know about it. However, in this case, it would only confuse people if I gave the whole subject matter.

The reason I have neglected to give the details, is because the problem as a whole doesn't look like it can be solved this way. It has to do with correlating. It was a true eureka moment when I realized the patterns could be found by "organising" the data, and not by initially trying to find a formula. Luckily, the organisation results in categories, which can then be filled with more data, in order to help us.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Fruit Smoothies posted:

I agree that in order to solve a problem you need to know about it. However, in this case, it would only confuse people if I gave the whole subject matter.
Did it occur to you that maybe people are simply curious about what the problem domain is? You have a lot of people spending a nontrivial amount of time writing code for you and the least you could do is provide a bit of context for their interest.

In the worst case, people might get a glimpse into an area that they don't know anything about.

Fruit Smoothies
Mar 28, 2004

The bat with a ZING

Dijkstracula posted:

Did it occur to you that maybe people are simply curious about what the problem domain is? You have a lot of people spending a nontrivial amount of time writing code for you and the least you could do is provide a bit of context for their interest.

In the worst case, people might get a glimpse into an area that they don't know anything about.

I know people are curious, and I appreciate the time and effort they're putting in. I might just post this in the "tiny custom app" thread, because I don't want to plague this thread with any more of my ignorance, or anymore of people's Dr. House syndrome, where they're fixated on the wrong part of the puzzle.

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?

Fruit Smoothies posted:

where they're fixated on the wrong part of the puzzle.

How do you know it's the wrong part of the puzzle? Maybe you're looking at the wrong piece and that's what's confusing people. Something to consider, that's all.

It's like asking a silly question like "how can I enable random access on a linked list?"* The premise is awkward and the question can't be taken at face value because the OP is on the road to mistakenville.

* i'm so sorry i couldn't think of a better example

Jam2
Jan 15, 2008

With Energy For Mayhem
Posted as a thread in SH/SC. I figure it can't hurt to ask here as well.

My family is opening a Hotel for Dogs. I have been tasked with implementing a system to manage reservations.

First, We need to collect data about the "guest" (dog) and owner. Guest's call name, weight, breed, owner's name and contact info, special needs, meal plan, exercise plan, preferred feeding schedule, length of stay, suite (standard, double, penthouse).

Next, our caregivers must be able to see a status report for each day... a list of all guests, feeding schedules, exercise schedules, etc.

We need to be able to enter value added services to a guest's package (24/7 webcam access, treats, food, special water).

We also need to be able to update notes on a guests stay each day to update the owners. When the owners return to pick up their dog, they will receive a summary of the stay at the hotel with caregivers' (room service) notes.

Now I don't expect a single piece of software to offer all of this functionality out of the box.

We currently use Quickbooks for accounting. Can QB Premier do this? Is there an extension that adds this type of functionality?

Should I look into custom coding? What would be the cost to do this from scratch?

POKEMAN SAM
Jul 8, 2004

Jam2 posted:

Posted as a thread in SH/SC. I figure it can't hurt to ask here as well.

My family is opening a Hotel for Dogs. I have been tasked with implementing a system to manage reservations.

First, We need to collect data about the "guest" (dog) and owner. Guest's call name, weight, breed, owner's name and contact info, special needs, meal plan, exercise plan, preferred feeding schedule, length of stay, suite (standard, double, penthouse).

Next, our caregivers must be able to see a status report for each day... a list of all guests, feeding schedules, exercise schedules, etc.

We need to be able to enter value added services to a guest's package (24/7 webcam access, treats, food, special water).

We also need to be able to update notes on a guests stay each day to update the owners. When the owners return to pick up their dog, they will receive a summary of the stay at the hotel with caregivers' (room service) notes.

Now I don't expect a single piece of software to offer all of this functionality out of the box.

We currently use Quickbooks for accounting. Can QB Premier do this? Is there an extension that adds this type of functionality?

Should I look into custom coding? What would be the cost to do this from scratch?

It looks like a pretty straightforward Web application, to me. You guys locally have a certain login that lets you add guests, administrate, etc, and your caregivers each have a login they use to mark what they did or whatever, and then you give your guests a login (one login per guest) and turn on special features on their account like webcam access or whatever.

frumpus
Nov 28, 2005

In VBScript, I have a url-encoded string which I have parsed together.

In order to pass it to a 3rd party website I need to create a secure hash using the HMAC-SHA256 algorithm, and a secret code word that they gave me.

I have no idea how to do this and my googling hasn't been very helpful. All I can find are downloads that I don't trust. Surely there is a way to do this with some vbscript code, it sounds like a fairly common task.

Help?

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

frumpus posted:

In VBScript, I have a url-encoded string which I have parsed together.

In order to pass it to a 3rd party website I need to create a secure hash using the HMAC-SHA256 algorithm, and a secret code word that they gave me.

I have no idea how to do this and my googling hasn't been very helpful. All I can find are downloads that I don't trust. Surely there is a way to do this with some vbscript code, it sounds like a fairly common task.

Help?

Please do not implement cryptographic primitives on your own, you will do it wrong. If you find a third-party which you do not trust, post a link in here and I can do some tests on the implementation for you and tell you if it's at least outwardly correct.

frumpus
Nov 28, 2005

ShoulderDaemon posted:

Please do not implement cryptographic primitives on your own, you will do it wrong. If you find a third-party which you do not trust, post a link in here and I can do some tests on the implementation for you and tell you if it's at least outwardly correct.

I was just looking at this. http://www.example-code.com/vbscript/crypt_hash_algorithms.asp

It has no documentation though so I really don't even know what I'm looking at or how to implement it.

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

frumpus posted:

I was just looking at this. http://www.example-code.com/vbscript/crypt_hash_algorithms.asp

It has no documentation though so I really don't even know what I'm looking at or how to implement it.

That page does not demonstrate HMAC. However, it links to http://www.chilkatsoft.com/refdoc/xChilkatCrypt2Ref.html which is a reference to the library in question, which does support HMAC, and appears quite complete. The license for the library seems reasonable enough for commercial software. This evening I can throw together a few tests to make sure the HMAC implementation isn't completely insane, if you want.

frumpus
Nov 28, 2005

ShoulderDaemon posted:

That page does not demonstrate HMAC. However, it links to http://www.chilkatsoft.com/refdoc/xChilkatCrypt2Ref.html which is a reference to the library in question, which does support HMAC, and appears quite complete. The license for the library seems reasonable enough for commercial software. This evening I can throw together a few tests to make sure the HMAC implementation isn't completely insane, if you want.

I would appreciate that greatly. :)

Cizzo
Jul 5, 2007

Haters gonna hate.
Anyone know how to program PIC devices with C?

Reason I ask is because my teacher gave us the option to use C rather than ASM and I want to jump at that since I hate ASM. Do you know of any websites that have some sort of basic guide to it? Such as pin names and such.

To be more specific, it's a PIC16F887.

Thanks

frumpus
Nov 28, 2005

ShoulderDaemon posted:

That page does not demonstrate HMAC. However, it links to http://www.chilkatsoft.com/refdoc/xChilkatCrypt2Ref.html which is a reference to the library in question, which does support HMAC, and appears quite complete. The license for the library seems reasonable enough for commercial software. This evening I can throw together a few tests to make sure the HMAC implementation isn't completely insane, if you want.

Update, I am playing around with it and it seems to function ok. I just have no idea if the hash is right. This is the code I'm using to test it.

code:
sigString = "emailAddr=someuser%40domain.com&firstName=some&lastName=user&time=1239198055"

set crypt = CreateObject("Chilkat.Crypt2")

'  Any string argument automatically begins the 30-day trial.
success = crypt.UnlockComponent("30-day trial")
If (success <> 1) Then
    MsgBox "Crypt component unlock failed"
    WScript.Quit
End If

crypt.HashAlgorithm = "sha256"
crypt.EncodingMode = "hex"
crypt.SetHmacKeyString("secret")

hash = crypt.HmacStringENC(sigString)

msgbox(hash)
Does this look correctly implemented?

frumpus fucked around with this message at 21:03 on Apr 8, 2009

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender
That should be producing the hash 0ec3b4c8fcd83aee68a2df5e5133cce6f3eec86ca3df2c7a9f0a5557e11eae85.

A few more tests for you to run:
sigString="", key="", result=b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad
sigString="foo", key="", result=0c0d98f7e3d9d45e72e8877bc1b104327efb9c07b18f2ffeced76d81307f1fff
sigString="", key="foo", result=683716d9d7f82eed174c6caebe086ee93376c79d7c61dd670ea00f7f8d6eb0a8
sigString="foo", key="foo", result=08ba357e274f528065766c770a639abf6809b39ccfd37c2a3157c7f51954da0a
sigString="1234567890"(repeated 100 times), key="foo", result=162816456de17fa0f2373ac6336589d5ce74365eccd3b670e7154937946fc3ea
sigString="foo", key="1234567890"(repeated 100 times), result=
2952c50875e93839fdda25a08a85429094d870d131775ac41ffe3919e7ddc9c1
sigString="1234567890"(repeated 100 times), key="1234567890"(repeated 100 times), result=5c04621ef25e277d0541e670f5ade49ee6b2d72004857874509edf897021ee2d

You can also examine the standard test vectors in RFC 4231.

frumpus
Nov 28, 2005

ShoulderDaemon posted:

That should be producing the hash 0ec3b4c8fcd83aee68a2df5e5133cce6f3eec86ca3df2c7a9f0a5557e11eae85.

A few more tests for you to run:
sigString="", key="", result=b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad
sigString="foo", key="", result=0c0d98f7e3d9d45e72e8877bc1b104327efb9c07b18f2ffeced76d81307f1fff
sigString="", key="foo", result=683716d9d7f82eed174c6caebe086ee93376c79d7c61dd670ea00f7f8d6eb0a8
sigString="foo", key="foo", result=08ba357e274f528065766c770a639abf6809b39ccfd37c2a3157c7f51954da0a
sigString="1234567890"(repeated 100 times), key="foo", result=162816456de17fa0f2373ac6336589d5ce74365eccd3b670e7154937946fc3ea
sigString="foo", key="1234567890"(repeated 100 times), result=
2952c50875e93839fdda25a08a85429094d870d131775ac41ffe3919e7ddc9c1
sigString="1234567890"(repeated 100 times), key="1234567890"(repeated 100 times), result=5c04621ef25e277d0541e670f5ade49ee6b2d72004857874509edf897021ee2d

You can also examine the standard test vectors in RFC 4231.

So far they look good! Thanks a bunch!

yippee cahier
Mar 28, 2005

Cizzo posted:

Anyone know how to program PIC devices with C?

Reason I ask is because my teacher gave us the option to use C rather than ASM and I want to jump at that since I hate ASM. Do you know of any websites that have some sort of basic guide to it? Such as pin names and such.

To be more specific, it's a PIC16F887.

Thanks

Our class used Hi-Tech C compiler, which has an unoptimized free version: http://www.htsoft.com/downloads/demos.php#freeware

Integrates into MPLAB, which I assume you'd be doing your ASM in anyways. It has it's quirks if you're not used to building software in C. I forget everything about it, but good luck.

No idea about using GNU tools.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
I believe SDCC has rather good support for PIC

Fetko
Oct 21, 2004
OK, I'll try here first.

setup:
I have a WPF form Window1 class that contains a textbox. On Load, this creates a new ServiceHost for my WCF service, adds the endpoint, and opens it.
I have a WCF service class with a couple events triggered by requests from a client.
They currently exist in the same project and same namespace.

How do I update the textbox.text property from the WCF service class? I can't create a static update method in the Window1 class that does a 'textbox.txt = updateString' because of the control. I don't want to create a new instance of the Window1 class in the WCF service method (rules out a public textbox property.) I'm guessing that I can do this with delegates, but I'm not sure how.

Is there any way to just do a Window1.MethodName(updateString); call from my WCF service class to update the textbox property?

Bonus points for a solution that can let me do this when I move the WCF service to a separate project.

Fetko fucked around with this message at 13:09 on Apr 9, 2009

csammis
Aug 26, 2003

Mental Institution
Next time try in the specific megathread first, and the answer is to pass a reference to your Window1 object to the ServiceHost.

code:
void Window1_Load(object sender, RoutedEventArgs e)
{
  MyServiceHost svcHost = new MyServiceHost(this);  // pass the service host a reference
                                                    // to the current window
}

public void UpdateTextbox(string text)
{
  // This gets called from your service host object
  // Dispatch the update so you don't run into crossthreading errors
}
e: When you move the ServiceHost to a new project, add a reference to the project hosting the window and you're done.

Adbot
ADBOT LOVES YOU

ChewyLSB
Jan 13, 2008

Destroy the core
Okay, I don't think the Excel megathread is active anymore, so I'll ask here.

I have a table of values that are grades, so let's say that I have a list of values that are values for quizzes, where the maximum score is 5. Let's say that I wanted to remove the bottom two values from the average, now, for this, I know about the SMALL command. So right now, my average cell in my excel table's formula is:

=((SUM(B7:B32) - SMALL(B7:B32,1) - SMALL(B7:B32,2))/(COUNT(B7:B32)-2)) / B6 * 100

Would it be possible to have the cells be removed based off of another cell? So, let's say that I had another cell that was just labeled "2" and it would chop off the bottom two values.

I would think this would be done in a for loop but I can't seem to find anything about for loop support in Excel.

Also, I wanted to format it so that my bottom two values that were removed were highlighted in red. If I use the bottom 10 conditional formatting it highlights the bottom two values but it also highlights all values that are tied. I tried using the formula conditional formatting but I can't quite seem to get it to work, if I use SMALL(B7:B32,1) it highlights all of the values, I think it's because it's simply looking for the formula to be 'true' and it always is true.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply