0
  • Could someone take a look at this for me and help me work out a decryption that would reverse a string that has been input by the user. I don't mean just doing the reverse of this procedure.

      push edx 
      push ecx 
      not eax 
      add eax,0x04 
      mov edx,eax 
      pop eax 
      xor eax,edx 
      pop edx 
      rol al,1 
      rol al,1
      rol al,1 
      sub al,0x02 
      ret
    

    *

The registers are: Inwards- ecx: encryption key. eax: character to be encrypted.

Outwards- eax: encrypted character

Thank you for taking the time to look.

  • 1
    Do you have any *specific* questions? "help me" isn't all that specific. – Drew McGowen Jul 25 '13 at 14:41
  • Where is the problem? do you have test data? – nio Jul 25 '13 at 14:47
  • possible duplicate of [How can I decrypt this encryption routine?](http://stackoverflow.com/questions/11677101/how-can-i-decrypt-this-encryption-routine) – harold Jul 25 '13 at 15:10
  • 1
    It's exactly the same code. And after almost exactly a year. Is it from a university course or something? – harold Jul 25 '13 at 15:13
  • Thanks for the feedback everyone. I'm actually doing a short course for my new job. Thanks @harold it is exactly the same as that problem a year ago. I have tried the solution from that in visual studio however the program keeps breaking and i get: **Unhandled exception at 0x772c15de** and **0xC0000005: Access violation.** In the same error message and it goes to **crtexe.c** Anyone any ideas on this? – user2619128 Jul 26 '13 at 11:53
  • The program is to encrypt a 6 character string and then decrypt. So i'm looking for the decryption routine in assembly code on this one – user2619128 Jul 26 '13 at 11:56
  • Here is the same error i'm getting but i just can't work out where i have an uninitialised pointer [http://stackoverflow.com/questions/5886103/why-could-i-get-an-unhandled-exception-access-violation-writing-in-c] – user2619128 Jul 26 '13 at 12:16
  • The solution from my answer there does not even use pointers to begin with, so that would be odd.. what function is at 0x772c15de? – harold Jul 26 '13 at 12:26
  • How can i find the function that is at that point? – user2619128 Jul 26 '13 at 12:37
  • Well in the debugger it would break there, and show the surrounding code etc.. – harold Jul 26 '13 at 13:06
  • Ah right, of course. This is where the code breaks in the **crtexe.c** `/* * The /GS security cookie must be initialized before any exception * handling targetting the current image is registered. No function * using exception handling can be called in the current image until * after __security_init_cookie has been called. */ __security_init_cookie(); return __tmainCRTStartup(); }` – user2619128 Jul 26 '13 at 13:14
  • Well, I don't know. Maybe post a new question just for the separate problem – harold Jul 26 '13 at 19:45

1 Answers1

0

The algorithm is symmetric because i could decrypt back every character and key combination.

These two functions were tested by a loop for any error in decrypting the value back:

#include <iostream>
using namespace std;

unsigned char enc(unsigned char ch, unsigned char key)
{
    unsigned char tmp = key^(~ch+(unsigned char)0x04);
    return (( (tmp<<3) | (tmp>>5) ) & 0xff)-0x02;
}

unsigned char dec(unsigned char ch, unsigned char key)
{
    unsigned char tmp = (ch+0x02);
    tmp = ((tmp>>3) | (tmp<<5)) & 0xff;
    return ~((tmp^key )-(unsigned char)0x04);
}

int main()
{
    // single encryption test
    char c = 'A';
    char key = 'K';
    cout << "single test:" << (char)enc(c, key) << endl;

    bool problem = false;
    int k, ch;
    for(k=0;k<256;k++)
    {

        for(ch=0;ch<256;ch++)
        {
            if( enc( dec((unsigned char)ch, (unsigned char)k), k) != ch )
            {
                problem = true;
                cout << "error k=" << k << "c=" << ch
                     << "result=" <<  (unsigned int)enc( dec((unsigned char)ch, (unsigned char)key), (unsigned char)key) << endl;

            }
        }
    }
    if(problem) cout << "There was a problem." << endl;
    else cout << "There was no problem." << endl;
}
nio
  • 5,141
  • 2
  • 24
  • 35