Find the answer to your Linux question:
Results 1 to 8 of 8
Wanted to know if there is any way in which the following output ./a.out will generate a file for me 255 Seperate times, I know this may sound weird but ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Gcc
    Gcc is offline
    Just Joined!
    Join Date
    Feb 2010
    Posts
    4

    Red face Decrytption


    Wanted to know if there is any way in which the following output ./a.out will generate a file for me 255 Seperate times, I know this may sound weird but basically what i am doing is decrypting a file using brute force.

    student:~/encoder1$ ./a.out text.bin attempt (1 - 255)

    for every time i attempt to try a KEY which works (1-255) a new file should be generated in my folder, the reason being so that i can see which is the correct file with the written text in plain English rather than the Unencypted file.

    I just want to know if this is even possible, or is there an alternate way around this for examples by creating a for loop within my code so that only the correct file which is in UPPER or LOWER case in English without and special charectors is detected indicating to me the correct key.

  2. #2
    Just Joined!
    Join Date
    Feb 2010
    Posts
    18
    Hi,

    you should read the manual page of bash
    $ man bash
    in particular the part relative to the "for"

    bye
    giammy
    Last edited by oz; 02-17-2010 at 09:55 PM. Reason: removed spam

  3. #3
    Linux User
    Join Date
    Dec 2009
    Posts
    264
    Do you intend to look manual into the files?
    What do you want to decrypt? what algorithmic was used?

    Most synchron encryptions use part of the file-content to encrypt.

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,677
    Also, the terms of use for these forums precludes helping people with their school work and assignments, other than in the most general of terms to point you in some direction or other (not necessarily the correct one).
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  6. #5
    Gcc
    Gcc is offline
    Just Joined!
    Join Date
    Feb 2010
    Posts
    4
    Hi sorry for late reply ...

    /*
    Encrypts a file using a permutation cipher.

    The permutation is simply ^ with a key [0-255].

    */

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

    void usage(char *);


    main(int argc, char *argv[])
    {
    FILE *encryptedout;
    FILE *plainin;
    int key;
    char *plainfilename, *encryptedfilename;


    if (argc != 4) usage(argv[0]);
    plainfilename = argv[1];
    encryptedfilename = argv[2];
    key = atoi(argv[3]);

    plainin = fopen(plainfilename,"r");
    encryptedout = fopen(encryptedfilename,"w");

    int c;
    while((c = getc(plainin)) != EOF)
    {
    // The following line is the encryption algorithm
    char ec = (char) (c^key);
    putc(ec,encryptedout);
    }

    close(plainin);
    close(encryptedout);
    }


    void usage(char * commandname)
    {
    printf("USAGE: %s plaintextfile encryptedfile key\n",commandname);
    printf(" Where plaintextfile is the file you wish to encrypt\n");
    printf(" and the encrypted version is placed in encryptedfile.\n");
    printf(" key takes a value in the range (0-255).\n");
    exit(0);
    }


    As you can see from the code the problem is that i cant come up with some sort of loop which allows me to try 255 keys without the manual brute force method . Ive had a look into the Bash manual but cant seem to find anything specific to what im looking for and unfortunately pipping is too complicated for me to fully understand given my current knowledge of C.

    I need to come up with some way to do do 255 keys without having to manually try it , or even if i have to manually type it the there should be some kind of indication showing me that the file contains the unencypted file .. I can cheat around this as I already know what the key for my file is, so if there is some way i can get a detection of a sequence of words within the file then it will know it is unencrypted.

    Please note i already know the key to the encrypted file however im trying to adapt this code so i dont have to go through the manual key process of ...

    student:~/encoder1$ ./a.out text.bin attempt (1 - 255)

    Is there anyway to overcome this ?

  7. #6
    Linux User
    Join Date
    Dec 2009
    Posts
    264
    That's a very old encryption ...
    It would be most easy if you add a while ...
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    void usage(char *);
    
    
    main(int argc, char *argv[])
    {
    FILE *encryptedout;
    FILE *plainin;
    int key;
    char *plainfilename, *encryptedfilename;
    
    
    if (argc != 4) usage(argv[0]);
    plainfilename = argv[1];
    encryptedfilename_ori = argv[2];
    key = atoi(argv[3]); 
    key = 0;
    
    plainin = fopen(plainfilename,"r");
    
    while(++key < 256){
    encryptedfilename=encryptedfilename_ori + key;
    encryptedout = fopen(encryptedfilename,"w");
    
    int c;
    while((c = getc(plainin)) != EOF)
    {
    // The following line is the encryption algorithm
    char ec = (char) (c^key);
    putc(ec,encryptedout);
    }
    
    close(encryptedout);
    
    }
    close(plainin);
    }
    
    
    void usage(char * commandname)
    {
    printf("USAGE: %s plaintextfile encryptedfile key\n",commandname); 
    printf(" Where plaintextfile is the file you wish to encrypt\n");
    printf(" and the encrypted version is placed in encryptedfile.\n");
    printf(" key takes a value in the range (0-255).\n");
    exit(0);
    }
    Should create an file for each key ... haven't tried it.

  8. #7
    Gcc
    Gcc is offline
    Just Joined!
    Join Date
    Feb 2010
    Posts
    4
    Thanks mate appreciate the help, one other thing i have considered is .. Yes its a very old form of encyption its only base64.. ive decoded the file and everything using openssl, not difficult to crack ..

    $ for ((i=0;i<10;i++)) do echo $i ;
    0
    1
    2
    3
    4
    5
    6

    etc ...

    Then perhaps$ for ((i=0;i<10;i++)) do ./prog file file $i > result_${i}.txt ; done

  9. #8
    Gcc
    Gcc is offline
    Just Joined!
    Join Date
    Feb 2010
    Posts
    4
    Okay problem solved guys usign a simple bash shell ...

    However I wanted to know if there is any way of detecting particular words within any given file in a folder ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •