Zaszyfrowanie tekstu za pomocą funkcji crypt() z unistd.h

0

Tak jak w tytule chciałbym zaszyfrowac wygenerowane przez swój program hasło za pomocą funkcji crypt () ze unistd.h.

Jest to dla mnie troszkę czarna magia także postanowiłem zapytać na forum.

Oto kod zródłowy mojego programu :

Main.c

#define _XOPEN_SOURCE
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include "generator.h"
#include "input.h"


main (void)
{
    int length;

    printf("How long should the generated password be?\n");
    printf("Enter the number of characters: ");


   while ((scanf("%u", &length) != 1) || (length<=0) || length > strlen(password_source)) // Prosze o dlugosc az bedzie poprawna
    {

        while((temp=getchar()) != EOF && temp != '\n');
        {

        printf("Now input the data correctly please: \n");

        }

    }

    char *wska = generate(length);
    int j;

    for(j=0; j<length; j++)
    {
        printf("%c",wska[j]);
    }

    free(wska);

    printf("\n\n\nWhen we use crypt() on this password it will look like this :   \n\n\n",length);

  // Tutaj chcialbym wyswietlic zaszyfrowane za pomoca funkcji crypt () haslo ( to ktore powyzej wyswietla sie niezaszyfrowane)

    // Próbowałem zrobic to taką komendą:  printf("%c",*crypt(*wska[j], *salt));
    // ale salt nie jest zdefiniowane i nie wiem jak je zdefiniowac

return 0;
}

Tutaj jeszcze jest kod z definicji funkcji generate(length) :

#ifndef input_h
#define input_h
#define _XOPEN_SOURCE
#include "generator.h"
#include <stdio.h>
#include <unistd.h>


char *generate(int length)

{

    char *password;
    password = malloc(length * sizeof(*password)); // Przydzielam pamiec (w bajtach) o wielkosci sizeof(*password)

    const char tab[] = "Zrodlo do wygenerowania hasla";
    const size_t len = strlen(tab);

    char* generated_password = malloc((length+1) * sizeof(char));

    unsigned int i;
    unsigned int number_of_vovels=0;
    int spaces = 0;

    int k = 0;

    for(i = 0; i < length; i++)
    {

        if(tab[i] == 'A' || tab[i] == 'a' || tab[i] == 'E' || tab[i] == 'e' || tab[i] == 'I'  || tab[i] == 'i'  || tab[i] == 'O'  || tab[i] == 'o' || tab[i] == 'Y'  || tab[i] == 'y'   || tab[i] == 'U'  || tab[i] == 'u')
        {
            number_of_vovels++;

            if(number_of_vovels%2!=0)
            {
                generated_password[k] = '#';
            }
            else generated_password[k] = '*';

        }

        else   if(tab[i] ==' ')
        {
            spaces++;

            if(spaces%2!=0)
            {
                generated_password[k] = '1';
            }
            else    generated_password[k] = '2';

        }

        else
            generated_password[k] = tab[i];

        k++;

    }

    generated_password[++k] = NULL;

    char *wskaa = generated_password;

    return &generated_password[0];
}

Bardzo proszę o jakiekolwiek wskazówki/sugestie/konstruktywną krytykę. Z góry dziękuje i pozdrawiam.

1 użytkowników online, w tym zalogowanych: 0, gości: 1