From: Jennifer Faggi Renault on 22 Apr 2010 07:03 Hi all, i want to calcualte A = ROTL(Ac ^ t, u) + S ; in C code ^ : is the xor function + : addition modulo 2^32 ROTL: Circular left bit shift operator of 32-bit nonnegative integer X by n bits in matlab, i define ROTL function and it works good, and i tried to calculate A with Ac = '8108B207 ' t = '3BB4E79C' u= 'BA631FFF' and S = '8108B207' after converting each value on uint64 with the cmd: uint64(hex2dec(val)), i did A= mod(ROTL(bitxor(Ac,t),u) + S, 2^32); but i get a wrong result A='8108B207' instead of A ='9EE325D5' found with C code please can any one help me to find the error and fix it, and thanks in advance
From: Yi Cao on 22 Apr 2010 08:01 "Jennifer Faggi Renault" <asma_192(a)live.fr> wrote in message <hqpad9$5q5$1(a)fred.mathworks.com>... > Hi all, > i want to calcualte A = ROTL(Ac ^ t, u) + S ; > in C code ^ : is the xor function > + : addition modulo 2^32 > ROTL: Circular left bit shift operator of 32-bit nonnegative integer X by n bits > > in matlab, i define ROTL function and it works good, and i tried to calculate A > with Ac = '8108B207 ' > t = '3BB4E79C' > u= 'BA631FFF' > and S = '8108B207' > > after converting each value on uint64 with the cmd: uint64(hex2dec(val)), i did > A= mod(ROTL(bitxor(Ac,t),u) + S, 2^32); > but i get a wrong result A='8108B207' instead of A ='9EE325D5' found with C code > > please can any one help me to find the error and fix it, and thanks in advance > > You can diagnose the problem by comparing results at each step. For example, is bitxor(Ac,t) producing the same result as Ac ^ t in C? If so, are ROTL(bitxor(Ac,t),u) in Matlab and ROTL(Ac ^ t, u) in C the same? etc Then, you should be able to find where the problem comes from. HTH Yi
From: Jennifer Faggi Renault on 22 Apr 2010 09:26 > You can diagnose the problem by comparing results at each step. For example, is bitxor(Ac,t) producing the same result as Ac ^ t in C? If so, are ROTL(bitxor(Ac,t),u) in Matlab and ROTL(Ac ^ t, u) in C the same? etc Then, you should be able to find where the problem comes from. > > HTH > Yi Hi, that's exactly what i did, i follow the results of each code step by step and i noticed something weird: bitxor(Ac,t) gives the same result as (Ac ^ t) ROTL(bitxor(Ac,t),u) gives wrong result BUT , when i write the numéric values of bitxor(Ac,t) and u i get the true result : i mean ROTL(1001711516,3127058431) = 1DDA73CE fix the error but ROTL(v,u) gives 0 (v= bitxor(Ac,t)) why is it different????? can you help me please?
|
Pages: 1 Prev: indexing into array of objects passed as varargin? Next: Matlab can't plot!!! |