Simple encryption program

Discussion in 'Win32' started by Trebbert, Sep 23, 2007.

  1. Trebbert

    Trebbert New Member

    Joined:
    Sep 23, 2007
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    -
    Location:
    Australia
    in C i am trying to do a simple encryption that gets the ASCII value of the character then doubles it and subtracts 25 then to decrypt adds 25 and divides by 2 but it does not seem to be working here is the relevant code.I am using Dev C++ and am just learning the WIN32 API so i have copied and modified most of this code from a tutorial.

    Code:
    case IDC_MAIN_EDIT:
        {
        int len = GetWindowTextLength(GetDlgItem(hwnd, IDC_MAIN_EDIT));
        if(len > 0)
        {
        int i,j;
        char* buf;
        buf = (char*)malloc( len + 1);
        GetDlgItemText(hwnd, IDC_MAIN_EDIT, buf, len + 1);
       
        //... do stuff with text ...
        for (i=0;i<len;i++)
        {
            j = buf[i];
       //     if(j >> 1 > 255)
           
            j = (j  * 2)^ (1/2);
            buf[i] =j;
        }
        SetDlgItemText(hwnd, IDC_MAIN_ENC,buf );
        
        GlobalFree((HANDLE)buf);
        }
    else
    SetDlgItemText(hwnd, IDC_MAIN_ENC,"" );
            
        }  
    break;
    
    case IDC_MAIN_ENC:
        {
        int len = GetWindowTextLength(GetDlgItem(hwnd, IDC_MAIN_ENC));
        if(len > 0)
        {
        int i,j;
        char* buf;
        buf = (char*)malloc( len + 1);
        GetDlgItemText(hwnd, IDC_MAIN_ENC, buf, len + 1);
       
        //... do stuff with text ...
        for (i=0;i<len;i++)
        {
            j = buf[i];
           // if((j << 1)>255)
           
            j = j ^ 2 /2;
            buf[i] =j;
        }
        SetDlgItemText(hwnd, IDC_MAIN_EDIT,buf );
        
        GlobalFree((HANDLE)buf);
        }
    else
    SetDlgItemText(hwnd, IDC_MAIN_EDIT,"" );
            
        }  
    break;
    
    Thanks
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice