Thread: Xor Encryption

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    1
    Rep Power
    0

    Xor Encryption


    Hi all ....i have a xor encryption file and the sender told me that :
    When you read it out it is crypted, with xor coding, 8 unfined hex value d2, subract 8bit unfined 4C then the file
    is a ordinary bin file.
    I dont understand what can i do to decrypt the file.
    pls someone help me
    Thanks in Advance
    Contrast
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,444
    Rep Power
    1873
    Well if by "unfined" you mean "unsigned", then perhaps

    Code:
    unsigned char c = a byte from your file
    c ^= 0xd2;
    c -= 0x4c;
    // write c to your new file
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0
    Salem thanks for your fast reply ...so i will must open the file with winhex or hexplorer or Notepad++ and what can i do to decrypt the file? Or if you have a better sugestion pls tell me it is very important for me.
    Thanks again
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0
    You're right Salem for your message on another forum but I'm trying to find a way that I can read the file ... I know it's very annoying guys like me to ask questions that may seem stupid to someone who knows.
    Thank you so much giving me immediately replied with the code should be put'll try to find a way to finish
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0
    I did finally with your help ... Thank Salem
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2014
    Location
    mumbai
    Posts
    1
    Rep Power
    0
    i am adding it out here as i could not start a new post.
    pentax firmware is obfuscated, someone has posted a code:
    #rename to main.c

    #include <stdio.h>
    #include <stdlib.h>

    void decrypt(void *this, int mode, void *fileBufferPtr);

    int main()
    {

    FILE *fp;
    FILE *pFile;
    int counter;
    fp = fopen("in.bin", "rb");

    if (fp == NULL) {
    printf("I couldn't open results.dat for writing.\n");
    exit(0);
    }

    fseek(fp, 0L, SEEK_END);
    size_t sz = ftell(fp);
    fseek(fp, 0L, SEEK_SET);

    int* buffer = (int*) malloc(sz);

    fread(buffer, sz, 1, fp);
    fclose(fp);

    for (counter = 0; counter < (sz / sizeof(int)); counter++)
    {
    // change the byte order
    int num = *(buffer + counter);

    int swapped = ((num>>24)&0xff) | // move byte 3 to byte 0
    ((num<<8)&0xff0000) | // move byte 1 to byte 2
    ((num>>8)&0xff00) | // move byte 2 to byte 1
    ((num<<24)&0xff000000); // byte 0 to byte 3

    *(buffer + counter) = swapped;
    }

    decrypt(NULL, 0, buffer);
    decrypt(NULL, 1, buffer);

    // now change the endian-ness again
    for (counter = 0; counter < (sz / sizeof(int)); counter++)
    {
    // change the byte order
    int num = *(buffer + counter);

    int swapped = ((num>>24)&0xff) | // move byte 3 to byte 0
    ((num<<8)&0xff0000) | // move byte 1 to byte 2
    ((num>>8)&0xff00) | // move byte 2 to byte 1
    ((num<<24)&0xff000000); // byte 0 to byte 3

    *(buffer + counter) = swapped;
    }

    /* Write your buffer to disk. */
    pFile = fopen("out.bin","wb");

    if (pFile)
    {
    fwrite(buffer, sz, 1, pFile);
    }
    else
    {
    puts("Something wrong writing to File.");
    }

    fclose(pFile);

    return 0;
    }

    how do i run this on using either Notepad++ with plugins, HXD or HDD hex editor neo

IMN logo majestic logo threadwatch logo seochat tools logo