c - Low Level IO with Crypt -


i trying compare encrypted string taken each line of file aaaa-zzzz until finds match of password. guaranteed user password of 4 characters. trying take in file using lowlevel io , output new file decrypted passwords of each line. not best @ c programming yet please gentle. need direction on how create array or list going aaaa way zzzz , comparing each decrypted version of file line.

  1. how decrypt file line line , save char []
  2. how compare each line char [] until password found

for example:

if line $1$6gmkiope$i.zkp2evrxhdmapzyov.b. , next line $1$pkmkicve$wqfqztnmcqr7fqsnq7k2p0. assuming resulting password after decryption absz , taze new file result absz on first line , taze second line.

this have far:

#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h>  void pdie(const char *); void die(const char *);  #define buffer_size 1024   int main(void) {    char *pass;    int rfd;       int wfd;       char buffer[buffer_size];       char *bp;       int bufferchars;       int writtenchars;       if ((rfd = open("pass.txt", o_rdonly, 0)) < 0)       pdie("open failed");     if ((wfd = open("passout.txt", o_wronly | o_creat | o_trunc,                    s_irusr | s_iwusr | s_irgrp | s_iroth)) < 0)       pdie("open failed");     while (1)    {          if ((bufferchars = read(rfd, buffer, buffer_size)) > 0)       {          printf("%s", buffer);           bp = buffer;           pass = crypt(getpass(all(4,4,'a','z')), *bp);             printf(pass);          while (bufferchars > 0)          {             if ((writtenchars = write(wfd, bp, bufferchars)) < 0)                pdie("write failed");              bufferchars -= writtenchars;             bp += writtenchars;          }       }       else if (bufferchars == 0)            break;       else             pdie("read failed");    }    close(rfd);    close(wfd);     return 0; }   void pdie(const char *mesg) {     perror(mesg);    exit(1); }  void die(const char *mesg) {     fputs(mesg, stderr);    fputc('\n', stderr);    exit(1); }  int inc(char *c,char begin, char end){     if(c[0]==0) return 0;     if(c[0] == end){   // make algorithm stop @ char 'f'         c[0]=begin;     // can put other char                     return inc(c+sizeof(char), begin, end);     }        c[0]++;     return 1; }  int all(int a, int n,char begin, char end){     int i,j;     char *c = malloc((n+1)*sizeof(char));     for(i=a;i<=n;i++){         for(j=0;j<i;j++) c[j]=begin;         c[i]=0;         {             printf("%s\n",c);         } while(inc(c,begin,end));     }     free(c); } 

here file:

$1$6gmkiope$i.zkp2evrxhdmapzyov.b. $1$pkmkicve$wqfqztnmcqr7fqsnq7k2p0 $1$0lmkiuve$7monlu6rz/cufrbidk7pk. 


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -