Sunday 15 August 2010

c - Low Level File I/O Compare Strings -


I am writing a program that takes a file with 3 rows of an encrypted password and all four lower case letters to them Compared with aaa - I have the only issue with Zzayz that I can not understand how to input the file line and how to compare it with 4 letter words individually. Then you should print 3 decrypted 4 letter words that are related to the password from the file. If there are any types to improve my code, please let me know I'm starting a new one on this, so I should have clear explanations and examples if possible, thanks.

Edit *****

The main problem in all functions and the main I do not want to print on the screen Ouch, Aab, Aak, etc., but I give it a four I want to put it in the array so that I can compare each individual file from each file individually using crypt. So I would like to advise how to put all the 456 9 7 combinations in the array, compare the code of each line, and print the solution on the screen.

The file appears as follows:

  $ 1 $ 6gMKIopE $ I.zkP2EvrXHDmApzYoV.B. $ 1 $ pkMKIcvE $ WQfqzTNmcQr7fqsNq7K2p0 $ 1 $ 0 Mmkiwu $ 7 Monlu 6 Arjed / Siyuefarbeedike 7 PK  

My code looks like this:

  #include & Lt; Sys / types.h & gt; # Include & lt; Sys / stat.h & gt; # Include & lt; Fcntl.h & gt; # Include & lt; Stdio.h & gt; # Include & lt; Stdlib.h & gt; # Include & lt; Unistd.h & gt; #define BUFFER_SIZE 1024 my_fgets (char * buf, int len, int f) {for (int i = 0; i & lt; len; i ++, buf ++) {int count = read (f, buf, 1) ; If (! Count || (buff [0] == '\ n')) {buff [0] = 0; Return i; }} Return 0; } Int cone (four * c, four starting, four end) {if (c [0] == 0) returned; If (c [0] == end) {// it creates algorithm to close at four 'F' C [0] = initially; // But you can put any other four return inc (c + sizeof (char), start, end); } C [0] ++; Return 1; } All four (int one, int n, char start, char end) {int i, j; Four * c = maulok ((n + 1) * size (four)); Four results [] = ""; For (i = one; i and lt; = n; i ++) {for (j = 0; j & lt; i; j ++) c [j] = start; C [i] = 0; Do {int k = sizeof (results); For (int g = 0; g  

I think you need to answer the question. Maybe you want the code below. Assume that you have a password, and you have a file that has an encrypted password list (or usually hash), you want to see if the password is correct or false. You compare the hash of the password with the hash in the file. I have not tested this code.

PS, I know if I'm off the road, I'll remove the answer.

  Zero crypt (four * hash, const char * password_test) {/ / Create a hash with password, or encrypt it or something else? } Int test_password (const char * filename, const char * password) {FILE * f; F = FOPAN (filename, "R"); If (! F) return 0; Four password_hash [256]; Crypt (password_hash, password); Four hash [256]; Four buff [1024]; Whereas (fgets (buf, sizeof (buf), f)! = Null) {crypt (hash, buf); If (strcmp (password_hash, hash) == 0) return 1; } Fclose (f); Return 0; } Zero main () {int result = test_password ("test.txt", "password"); If (result == 1) printf ("password is good \ n"); }  

open / read / close

  Brick May_fgets (char * Bufa, offers brick, brick f) {for ( Int i = 0; i & lt; len; i ++, buf ++) {int count = read (f, buf, 1); If (! Count || (buff [0] == '\ n')) {buff [0] = 0; Return i; }} Return 0; } Int main () {int f = open ("test.txt", O_RDONLY); If (F & L; 0) 0; Four buff [1024]; While (my_fgets (buf, sizeof (buf), f) printf ("% s \ n", buf); Close (f); }  

No comments:

Post a Comment