flip weird behaviour

Hello all,I’m doing some tests with qcrypt and openssl.I defined, using the qcrypt doc, two a function sha512 in this way:hash:qcrypt 2: (hash;2)sha512:{hash[x;“sha512”]}sha512 returns type is 4h.Then, I created a dictionary in this way:tstampauthkey!(10;sha512[“3”])and this is the outputtstamp | 10authkey| 0xcf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3eBut, if I do a flip of this dictionary: I have this:tstamp authkey--------------10 cf10 8310 e110 3510 7e10 ef10 b810 bd10 f110 54etc…why ?Is it possible to put the entire sha512 result in the column authkey?thanks,Fausto

Hi Fausto,

If you enlist the result of your sha512 it should put the entire result into the column:

tstampauthkey!(10;enlist sha512[“3”])

gives an output of

tstamp | 10

authkey| ,0xcf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e

and flipping this gives

tstamp authkey


10     0xcf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e

Hope this helps,

Dan

Hello Dan,thanks. The enlist sure helps :-)But I still cannot figure out why flip without enlist did in that way.thanks,faustoIl giorno gio 11 ott 2018 alle ore 11:25 ha scritto:>> Hi Fausto,>> If you enlist the result of your sha512 it should put the entire result into the column:>> tstampauthkey!(10;enlist sha512[“3”])>> gives an output of>> tstamp | 10> authkey| ,0xcf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e>> and flipping this gives>> tstamp authkey> -----------------------------------------------------------------------------------------------------------------------------------------> 10 0xcf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e>> Hope this helps,> Dan>> On Thursday, October 11, 2018 at 10:15:49 AM UTC+1, Fausto Saporito wrote:>>>> Hello all,>>>> I’m doing some tests with qcrypt and openssl.>> I defined, using the qcrypt doc, two a function sha512 in this way:>>>> hash:qcrypt 2: (hash;2)>> sha512:{hash[x;“sha512”]}>>>> sha512 returns type is 4h.>> Then, I created a dictionary in this way:>>>> tstampauthkey!(10;sha512[“3”])>>>> and this is the output>>>> tstamp | 10>> authkey| 0xcf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e>>>> But, if I do a flip of this dictionary: I have this:>>>> tstamp authkey>> -------------->> 10 cf>> 10 83>> 10 e1>> 10 35>> 10 7e>> 10 ef>> 10 b8>> 10 bd>> 10 f1>> 10 54>> etc…>>>> why ?>>>> Is it possible to put the entire sha512 result in the column authkey?>>>> thanks,>> Fausto>> –>

Submitted via Google Groups

This seems to explain it:
https://code.kx.com/q4m3/8_Tables/ - If you create a table as the flip of a column dictionary, item-wise extension is performed when the column dictionary is flipped into a table.

This means that if one of the values is not a list, it will be duplicated to fill the whole column. In your case, you want the opposite, which is enforced by the enlist.



tstamp is an atom, authkey is a list of bytes, just like 2 3 is a list of long integers:


q)flipab!(1;2 3)

a b

1 2

1 3


This is a feature of flip …it fills an atom out to the same length as the list

q)flip (1;1 2 3)

1 1

1 2

1 3

It did the same with your atom and list of bytes. 

Terry

Hello Terry and JW

thanks. It’s crystal clear now..

Regards

Fausto

Inviato da iPhone

Il giorno 11 ott 2018, alle ore 21:08, JW Buitenhuis <jwbuitenhuis@gmail.com> ha scritto:

This seems to explain it:
https://code.kx.com/q4m3/8_Tables/ - If you create a table as the flip of a column dictionary, item-wise extension is performed when the column dictionary is flipped into a table.

This means that if one of the values is not a list, it will be duplicated to fill the whole column. In your case, you want the opposite, which is enforced by the enlist.



tstamp is an atom, authkey is a list of bytes, just like 2 3 is a list of long integers:


q)flipab!(1;2 3)

a b

1 2

1 3