Hi and I am making a script but am having a slight math logic problem. Below is an example of an encoder I am working on.

``````for(int m=0;m<80;m++)
{
if(m<=19)
{
f = (b & c) | ((~b) & d);
k = 0x5A827999;
}
else if(m<=39)
{
f = b ^ c ^ d;
k = 0x6ED9EBA1;
}
else if(m<=59)
{
f = (b & c) | (b & d) | (c & d);
k = 0x8F1BBCDC;
}
else
{
f = b ^ c ^ d;
k = 0xCA62C1D6;
}
temp = (rotateleft(a,5) + f + e + k + word[m]) & 0xFFFFFFFF;
e = d;
d = c;
c = rotateleft(b,30);
b = a;
a = temp;

}``````

Then below is the decoder. The decoder is meant to reverse the math but can't seem to get the value of variable e. However I do know the value of e on the first and last loop rounds but all other loop rounds e needs to be calculated. Does anybody know what I'm doing wrong because I can't seem to figure it out? Below is what I have tried and although all is fine e is unknown making the whole script go crazy.

``````for (int m=79; m>=0; m--) {
temp = a;
a = b;
b = rotateright(c,30);
c = d;
d = e;
if(m<=19)
{
f = (b & c) | ((~b) & d);
k = 0x5A827999;
}
else if(m<=39)
{
f = b ^ c ^ d;
k = 0x6ED9EBA1;
}
else if(m<=59)
{
f = (b & c) | (b & d) | (c & d);
k = 0x8F1BBCDC;
}
else
{
f = b ^ c ^ d;
k = 0xCA62C1D6;
}
}``````

Thanks.

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by cwarn23

if u use separate loops .. then u are only saving the last value of e in the first loop.

But surley there is some algebra equation I can do to solve this isn't there?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.