« first day (598 days earlier)      last day (4351 days later) » 

7:06 AM
@DeadMG what is the 'wrong' output for the empty 'string' - just checking my gcc outputs the same?
gist: gcc version testbed, 2012-06-05 07:05:32Z
#include <algorithm>
#include <stdexcept>
#include <array>
#include <vector>
#include <iostream>

#define _byteswap_uint64 __builtin_bswap64
#define _rotr(x,k) (((x)>>(k)) | ((x)<<(32-(k))))

template<typename T> struct Output {
    std::array<T, 8> h;
};
template<typename T> struct Input {
    std::array<T, 16> c;
};
template<typename T> Output<T> sha2(Input<T> in) {
    T w[64];
    for(int i = 0; i < 16; i++)
        w[i] = in.c[i];

    for(int i = 16; i < 64; i++) {
        auto s0 = _rotr(w[i - 15], 7) ^ _rotr(w[i - 15], 18) ^ (w[i - 15] >> 3);

        auto s1 = _rotr(w[i - 2], 17) ^ _rotr(w[i - 2], 19) ^ (w[i - 2] >> 10);
        w[i] = w[i - 16] + s0 + w[i - 7] + s1;        
    }

    static const T k[] = {    
        0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 
        0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
        0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 
        0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
        0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 
        0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
        0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 
        0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
        0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 
        0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
        0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 
        0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
        0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 
        0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
        0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 
        0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
    };

    static const T h[] = {
        0x6a09e667,
        0xbb67ae85,
        0x3c6ef372,
        0xa54ff53a,
        0x510e527f,
        0x9b05688c,
        0x1f83d9ab,
        0x5be0cd19
    };

    T loopvars[8];
    for(int i = 0; i < 8; i++)
        loopvars[i] = h[i];

    for(int i = 0; i < 64; i++) {
        auto&& la = loopvars[0];
        auto&& lb = loopvars[1];
        auto&& lc = loopvars[2];
        auto&& ld = loopvars[3];
        auto&& le = loopvars[4];
        auto&& lf = loopvars[5];
        auto&& lg = loopvars[6];
        auto&& lh = loopvars[7];

        auto s0 = _rotr(la, 2) ^ _rotr(la, 13) ^ _rotr(la, 22);
        auto maj = (la & lb) ^ (la & lc) ^ (lb & lc);
        auto t2 = s0 + maj;

        auto s1 = _rotr(le, 6) ^ _rotr(le, 11) ^ _rotr(le, 25);
        auto ch = (le & lf) ^ ((~le) & lg);
        auto t1 = lh + s1 + ch + k[i] + w[i];

        lh = lg;
        lg = lf;
        lf = le;
        le = ld + t1;
        ld = lc;
        lc = lb;
        lb = la;
        la = t1 + t2;
    }
    Output<T> output;
    for(int i = 0; i < 8; i++) {
        output.h[i] = h[i] + loopvars[i];
    }
    return output;
}
Output<unsigned int> SHA2(std::vector<char> bytes) {
    auto bitlen = bytes.size() * 8;
    auto big_endian_bitlen = ::_byteswap_uint64(bitlen);
    if (bitlen > 440)
        throw std::runtime_error("Epic fail!");
    Input<unsigned int> in;
    for(int i = 0; i < 16; i++) {
        in.c[i] = 0;
    }
    for(int i = 0; i < bitlen; i++) {
        in.c[i / 32] |= ((bytes[i / 8] >> (i % 8))) << (i % 32);
    }
    in.c[bitlen / 32] |= (1 << (bitlen % 32));
    // all zero by default, so no need to append the extra bits
    in.c[14] = (big_endian_bitlen >> 32);
    in.c[15] = big_endian_bitlen;
    return sha2(in);
}

int main(int argc, const char *argv[])
{
    std::vector<char> bytes;
    for(auto o : SHA2(bytes).h)
        std::cout << std::hex << o << ' ';
    std::cout << '\n';
}
@DeadMG ^ gcc testbed, feel free to refer to it from your question
 
de5c4195
c21e7e70
e6a365c2
77f6bc03
f651e23a
6fb9b88a
1decb688
d6fddf1f
are the 8 outputs for the empty string in hex
 
So, the output is the same:
sehe@mint12:/tmp/2873224$ make && ./test
g++ -std=c++0x -g -O3 -march=native test_sha2_gcc.cpp -o test
de5c4195 c21e7e70 e6a365c2 77f6bc03 f651e23a 6fb9b88a 1decb688 d6fddf1f
 
yep
 
Yay. I got the ror right :)
 
Wikipedia gives the real hash value
 
7:10 AM
echo -n ''|openssl sha -sha256 or sha256sum </dev/null work plenty here (e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855)
 
or that
 
Well - haven't got time to look at it further, but you might use the above link for a test bed to make the barrier to entrance easier for prospectice SO answerers :)
You know, the ones that miss the SSCCE
 
I think there are more people who can use MSVC directly and would have equal issue with your range-based for
damnit
I was hoping that the constants would be wrong, as Wiki says they are big-endian, but swapping them didn't solve
 
Stupid horizontal scrollbars.
 
@DeadMG Oh well
@DeadMG Nope I verified that as well
@RadekdaknokSlupik Stupid huge onebox
 
7:23 AM
The onebox' text wraps.
It's the SHA sum.
 
@RadekdaknokSlupik I noticed, as I coded it ^^
 
@DeadMG That would be nice stuff for a poll. I'd personally guess that the majority of people on SO will actually have access to /a/ gcc.
 
I need this to give the correct output so I can run a differential solve
 
7:39 AM
All this SHA squizzle-gizzle makes me hungry. Time to get up and find some bacon.
 
I was just thinking it makes me sleepy
although I did wake up at 5pm yesterday...
 
Hello
 
@DeadMG you're already awake for 28 hours?
Oh PM. Never mind.
So, @ManofOneWay.
Do one-way functions really exist?
 
bang.
template <typename T> std::nullptr_t bang(T&&) { return {}; }
 
That's not a one-way function.
 
7:52 AM
Why not?
 
A one-way function is easy to compute for any input, but hard to invert.
 
Good luck getting an inverse of that.
And you can't get any easier than that.
 
easy and hard as in complexity theory, doh.
The existence of such functions would imply that N != NP, so if bang would be a one-way function, you'd win a million dollars right now.
</Wikipedia-reader-mode>
 
@CICADA
 
It is impossible to invert a function that discards (part of) its input, since you lose data.
@JAFFA
 
8:03 AM
@jaffa Dafuq?
 
I'm good boy
 
Lack of attention?
 
no longer
 
yellow all
 
8:08 AM
Thought I'd share something with you all.
Had I had milk near any orfice of my body when I watched it the first time, it would have shot out of my nose at lightning speed.
Maybe it's because I have a weird sense of humor
 
red
 
Roses come in many different colors, violets come in many different colors.
 
roses are red, sky is blue, i wanna fuck you :P
pun intended
 
I hope that it was a pun.
 
@jaffa What pun?
 
8:14 AM
I meant, I didn't mean to offend any1
 
Oh god
This exam was so shitty
Also hi
 
I woke up and weren't late for the exam woo.
 
o/
 
It had a RSA question.
A database exam.
 
Link with databases?
 
8:18 AM
Had an RSA question.
 
I read this exam was so slutty.
 
That's how shitty my exam was.
 
which exam?
 
Mine was shittier.
 
Did you have to encode a text with RSA manually?
 
8:19 AM
I don't remember that. However I had to write a SQL plan engine.
 
R u undergraduates?
 
Obviously
And probably always will be
 
@Cicada What, did you have your exam yet?
 
Yes
Just finished
"Finished"
Next one is this afternoon
 
Sounds fun.
 
8:21 AM
Computer architecture (they should name it electronics, to be fair)
 
I have spoken English.
Stupid time wasters.
I want to go to sleep properly.
 
Sleeping is a waste of time, even when done properly.
 
No.
 
Are you productive during sleep? No? It's a waste of time.
 
Not sleeping is a waste of time.
 
8:24 AM
Unfortunately, even when I replace with memcpy, the problem is still true. Notably, I tried the empty string as input because it's all zeroes except for a single 1, which quite limits the places where things can be going wrong. — DeadMG 1 hour ago
 
I'd rather sleep my entire life than stay awake
 
^ a bit is still a bit, even when it's zero?
 
RL is boring
 
I stay as far as I can from iStuff
 
8:26 AM
> It has reached the point where the Canberra Times reported this week that some academics are concerned that the iPad 3 is so vivid that children are finding the real world dull by comparison
@Cicada No second hand mac store nearby?
 
Woo, badger.
Who'd want an overpriced used useless toy?
 
^ this
 
iCar, because you only need one wheel.
 
hello
how are you guys
 
8:28 AM
We are awesome. Except for the Cat, who is crappy and tired.
 
@Cicada I was just asking whether you actually physically stay as far as you can from iStuff. That could be quite hard in a modern city. Just saying :)
 
Crappy. Tired.
 
@sehe Yeah it's nearly impossible actually
MacFags everywhere
 
Listen!
 
8:29 AM
@sehe What does that have to do with Mercurial?
 
@CatPlusPlus "400px-Wayne-Badger-1951-Mercury-2.jpg"
 
A planet would be more related.
So tired.
 
Apr 16 at 12:35, by Cat Plus Plus
Ooh, got a badger for ASCII diagram.
Apr 16 at 12:36, by sehe
           _,-='=- =-  -`"--.__,,.._
        ,-;// /  - -       -   -= - "=.
      ,'///    -     -   -   =  - ==-=\`.
     |/// /  =    `. - =   == - =.=_,,._ `=/|
    ///    -   -    \  - - = ,ndDMHHMM/\b  \\
  ,' - / /        / /\ =  - /MM(,,._`YQMML  `|
 <_,=^Kkm / / / / ///H|wnWWdMKKK#""-;. `"0\  |
        `""QkmmmmmnWMMM\""WHMKKMM\   `--. \> \
 hjm          `""'  `->>>    ``WHMb,.    `-_<@)
                                `"QMM`.
                                   `>>>
 
That looks really fucked up with word wrapping.
 
8:31 AM
@CatPlusPlus Well the thing with planets is, there little relation with badgers... Just keeping up the good tradition
@RadekdaknokSlupik Get yourself useful hardware
 
What, word wrapping. What resolution are you using, 320x240?
 
It wouldn't wrap even on 80x25 terminal.
Congratulations on having a crappy monitor that's crappier than 80x25 terminal.
 
lol it's mah iPod
 
Also what the hell is that resolution.
 
8:32 AM
iPod
 
It's WEIRD.
It's bad. And you should feel bad.
My brain doesn't work.
 
It's like 320x480 only four times as big.
 
How am I going to pass this damn English exam.
Waah.
 
In English.
Exams are for people who have exams.
 
You have to describe pictures or graphs or shit. And roleplay.
Utter nonsense.
 
8:35 AM
Sounds fun.
 
No, it's not. It's an exam.
 
This is a red car that looks like a fucking piece of dogshit.
 
@RadekdaknokSlupik Actually, it's like plain old CGA but 6-10 times as small :)
(did you ever see CGA?)
 
:L
 
8:39 AM
Only VGA and full HD.
 
Full HD is marketing term.
 
Meh
 
The windmill one
 
LINK Y U NO LISTEN
 
8:43 AM
probably
 
Saria's song
 
OOT is the best video game ever.
 
OOT is overrated
lol at that flag with the dog
 
I'm hungry…
 
8:44 AM
zoopedorape
 
@ScottW what, I didn't know I had one
 
TV Tropes is boring.
2
 
@RadekdaknokSlupik No it's not. It's a website. It's only boring if you go there. In which case, there is really nothing we can't do
Scott, that's not an ocarina
 
@sehe if it's boring when you go there, it's boring.
 
8:50 AM
I take offense with this:
SERVER #1 Name	Channel
TheJAVAMaster	Root
@RadekdaknokSlupik Nope potentially boring doesn't have to actually get boring (it certainly won't without your active cooperation)
 
Ell
Mornin all
 
Mourning
 
Ell
Ooh Zelda! I still have it for my n64 :3
 
ROFL
I bet is already has been
 
8:55 AM
She's a french nazi-like politician
 
Not yet, apt.-ly there's your ticket to fame :)
 
Ell
Is it the hand gesture you're interested in?
 
@Ell Ow man... No. The facial :)
 
Ho Hum
 
Ell
8:57 AM
...I don't know things!
 
Why does GIMP need freeglut
 
@RMartinhoFernandes Facial expressions, you know
 
Why does anything need freeglut
 
@Pubby Because it has a gluten allergy
afk
 
9:16 AM
> P.S. by the way, my intellisense is completely broken in VS2010 in this project. Why?
lol
 
@sehe That does make sense.
 
> Martinho Fernandes, Markus Persson, and 3 others have Tweets for you
Stupid emails.
 
Google Wave is the future!
Oh wait.
Google Wave would have been a success if they didn't do a fucking private beta before.
 
sbi
@RadekdaknokSlupik It's the future in an alternative time line, though.
 
9:19 AM
@ScottW paper and pen ftw.
 
@ScottW Probably, though it'll always be called e-mail
 
It's now called Apache Wave and afaik open-source.
 
And dead. You forgot dead.
 
Good Guy Google — Product or service ain't a success, makes it open source.
It's time to get up. I'm hungry as somebody from a continent I shall not name.
 
@RadekdaknokSlupik wouldn't the good guy make successful stuff open too? And interoperable?
 
9:24 AM
@awoodland don't get too good. :p
Hexapoda is open-source and it won't even get slightly successful. They must be happy. xD
 
posted on June 05, 2012 by R. Martinho Fernandes

Let’s say we’re implementing a class template similar to boost::optional. Unlike the one in boost, which was implemented with C++03 features, we’re adding a constructor that forwards arguments to the constructor of the value type. A naïve initial definition of that class template could look like this: template <typename T> class optional { public: // forwarding co

 
@MooingDuck where'd you get that GCC/Clang combo? You should use 4.6 or 4.7. Anyways, there's some C++11 compat issues anyways, and I never tried/used type_info.
Facebook released their internal C++ libs.
 
Yeah.
A few interesting things there, but not really lots. At least for me.
 
how's their string class?
 
9:35 AM
Just started my computer. First thing I saw: Server.java.
 
@rubenvb Has a couple optimizations.
That's all.
 
oh. Damn. No fancy uberUnicodeString
 
It's a byte container.
 
This has got to be compiler handholding for SSE stuff right? pastebin.com/FKqvWGER
 
What types are involved? Could just be hand-unrolling not particularly for SSE.
 
9:40 AM
template <class Pod, class T>
inline void pod_fill(Pod* b, Pod* e, T c)
wow that's a new markdown fail
 
Nah, that's old.
 
So I guess just bytes
 
Is that from the folly code?
 
yeah
 
Being a template, I suspect it's not for SSE (though it doesn't hurt). Probably they noticed the compiler wasn't unrolling the loop properly and did it by hand.
 
9:44 AM
huh, I thought compilers were smart enough to do this themselves by now
 
strValue = std::string( packet->Data, rep.Length ).c_str(); - I can't believe this code really works (VC++9)
 
Hmm. It "works" in the sense that it gives you a dangling pointer.
 
depends on what strValue is of course.
 
Not really.
 
* strValue is std::string
 
9:48 AM
Oh.
 
so it gets copied
voila.
 
I wonder why they used c_str()
 
dunno
 
Yeah, why not just copy the thing. Or use assign.
 
9:50 AM
VC++ could wipe string buffer in Debug config in its destructor =\
 
wut?
 
or ~string() { m_data = "crap"; }
 
I wish std::string::string(char const*) was explicit now. If I want a std::string from a literal, I can "blah"_s it.
 
hm...
no, it won't help.
it should be ~string() { m_data[0] = '\0'; delete[] m_data; }
 
delete[] m_data; m_data = "crap"; would work too. No, it won't.
 
9:53 AM
then strValue would get empty string
 
@Abyx who says they're not using std::unique_ptr<char*>?
@Abyx why would that be?
 
@RMartinhoFernandes no, c_str copies m_data pointer
 
Yeah. Never mind.
I made the same mistake as you :S
 
10:10 AM
@Feeds Wow rmf, you're on a roll. Looking great so far (haven't read it fully)
 
I'm trying to keep a schedule of two posts per week, on Tuesdays and Fridays.
I need to rewrite half of the next post because I picked a bad example. One that didn't quite exhibit the problem I wanted to present a solution for :(
 
:)
> “That’s right. Our military had two, unflown, better-than-Hubble space telescopes just sitting around. [...] This is the state of our military-industrial-scientific complex in miniature: The military has so much money that it has two extra telescopes better than anything civilians have; meanwhile, NASA will need eight years to find enough change in the couches at Cape Canaveral to turn these gifts into something they can use. Anyone else find anything wrong with this state of affairs?”
Who said that ICT is wasting money on derailed projects?
 
By "just sitting around", do they mean the things were on the ground?
 
Yup. unflown as well
I'm having a hard time considering what was the decision process by DOD management: "Let's burn them so we don't loose face" vs. "Let's give them to NASA so at least _something_ might ever be done with them"

Tough call, that
 
10:25 AM
I'm hoping this isn't an attempt to violate the spirit of an (L)GPL license. "Here's our changes, have fun with that! (evil laugh)". I joke but it sounds like the only logical reason for doing this. — SpliFF Jun 1 at 4:55
lol
 
Loosing face would be suck.
 
are static function locals allocated at program startup or at initialization time (ie first function call)?
 
First pass.
Or second.
Or third.
First one that succeeds.
 
what do you mean "first that succeeds"? I was told by knowledgeable people (I believe it was Howard Hinnant) that such a function static local is even thread-safe cause all the non first threads will block until the variable is initialized.
 
What if initialization throws?
 
10:37 AM
Let's say it doesn't. Then it could only through on out-of-memory, which is the reason I asked in the first place.
 
class foo { foo() { if(rand()) throw 17; } }
void f() {
    static foo f;
}
@rubenvb Yes, but if it throws, it will get initialized on the next call.
That's what I meant.
 
ah ok. So allocation is also done at initialization time?
No static storage preallocated because that would be more efficient?
 
There is static storage preallocated.
 
OK. That's cool. Thanks.
 
Hola
crickets
 
10:49 AM
@KodeSeeker I was trying (and failing) to remember how you spell the rest of the Spanish I know :)
 
"failingly trying"
 
@awoodland Im afraid I didnt quite get you there :s
nm.
er is this way of computing quartiles correct ? `double lower_quartile=(size/2)%2==0?(homework[lquartile]+homework[lquartile+1])/2:homework[lquartile];
	double higher_quartile=(size/2)%2==0?(homework[hquartile]+homework[hquartile+1])/2:homework[hquartile];`   Anyone?
 
@KodeSeeker code formatting in chat is annoying :)
 
@awoodland Yeah I tried reformatting that a couple of times and failed. Sigh , I guess I must spend more time here. :)
 
@KodeSeeker depending on what exactly homework is that looks plausible
 
10:57 AM
@awoodland well its a vector <double> that stores the individual homework grades
Finally
Lol
 
I just discovered a "Java static class" thing is actually just an inheritablee namespace with access specifiers. Am I right?
 
@KodeSeeker I'd write some tests with simple cases and known expected results to be on the safe side
 
@awoodland gotcha.
 
@rubenvb Kind of, yeah.
 
@RMartinhoFernandes so the a class or struct is just an instantiable inheritable namespace with access specifiers?
 
11:01 AM
@rubenvb I'm not sure using it quite like that would be "good design" though
 
@awoodland well, I didn't invent "static class"... :P
 
@rubenvb Depends, really. There is no "static class" thing built into the language. But people sometimes do write final classes with nothing but static methods and with a private constructor to make it act as a namespace.
 
@RMartinhoFernandes there is a static class in Java as opposed to an inner class
 
@RMartinhoFernandes you're talking about c++ there right?
 
@awoodland Those are static nested classes.
Which are just normal classes, but nested.
@rubenvb No, Java. Things like java.util.Collections, which are nothing but glorified namespaces for free functions.
 
11:12 AM
@RMartinhoFernandes Hey, Spirit is under the Boost license, not GPL. But it sure may be considered obfuscated :)
@rubenvb c++11, yes
 
lol, someone linked Fred to c-for-dummies.com
 
@ScarletAmaranth ohai
@ScarletAmaranth Just woke up? Did you have a physics test or something
 
@RMartinhoFernandes Mind linking the question :D ?
@sehe nn, was watching Psych :) All finals done, got 4 months of nothing :)
 
6
Q: printing float, preserving precision

FredOverflowI am writing a program that prints floating point literals to be used inside another program. How many digits do I need to print in order to preserve the precision of the original float? Since a float has 24 * (log(2) / log(10)) = 7.2247199 decimal digits of precision, my initial thought was th...

 
11:20 AM
@RMartinhoFernandes That's an answer of century :)
 
@ScarletAmaranth I'm jealous
Technically GPL encumbered — sehe 6 secs ago
 
@sehe Gonna waste a few days big time, then I'll be looking for a few month programming job, not gonna chill entirely :)
 
That's the point. Still jealous
 
Depends on what you mean by "few days" i guess then :P
 
@ScarletAmaranth Oh, noes! You're killing all that free time? Think of the children!
 
11:27 AM
@RMartinhoFernandes Actually, if I didn't get a programming job for the summer, I'd still be programming during the summer so I might as well get paid for it :P
 
If the sole difference was that you got paid for it...
 
Meh, "kill all the time" means different things to different people.
I wouldn't be able to lay in bed watching the lotr trilogy over and over again for 4 months.
 
Exactly!
(But gosh, that does sound boring)
 
Sure does. Although I'm still not in a summery mood quite yet, scumbag brain refuses to realize just how much time to waste I have :)
 
> ... before @Tony dies of sexual frustration :(
really? I would die of sexual frustration????
 
11:37 AM
Author publishes book. Both author and publisher intend it to be DRM free. Retailers still slap DRM on it. Stupid suits.
 
Retailers can do that ?
 
I don't know if they can. They did it.
 
11:53 AM
You can even legally sell GPL software (not written by you).
 

« first day (598 days earlier)      last day (4351 days later) »