Skip to content

Commit

Permalink
m
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmoudkhalef committed Dec 29, 2023
1 parent 1b8439c commit e93eba9
Show file tree
Hide file tree
Showing 14 changed files with 315 additions and 0 deletions.
21 changes: 21 additions & 0 deletions 0x17-doubly_linked_lists/0-print_dlistint.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "lists.h"

/**
* print_dlistint - prints doubly-linked list
* @h: address of head node
*
* Return: size of list
*/
size_t print_dlistint(const dlistint_t *h)
{
size_t i = 0;

while (h)
{
printf("%d\n", h->n);
h = h->next;
i++;
}
return (i);
}

20 changes: 20 additions & 0 deletions 0x17-doubly_linked_lists/1-dlistint_len.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "lists.h"

/**
* dlistint_len - returns length of dlist
* @h: address of head node
*
* Return: size of list
*/
size_t dlistint_len(const dlistint_t *h)
{
size_t i = 0;

while (h)
{
h = h->next;
i++;
}
return (i);
}

2 changes: 2 additions & 0 deletions 0x17-doubly_linked_lists/100-password
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
en C Pyfo neZ

2 changes: 2 additions & 0 deletions 0x17-doubly_linked_lists/102-result
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
906609

54 changes: 54 additions & 0 deletions 0x17-doubly_linked_lists/103-keygen.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/**
* main - Generates and prints passwords for the crackme5 executable.
* @argc: The number of arguments supplied to the program.
* @argv: An array of pointers to the arguments.
*
* Return: Always 0.
*/
int main(int __attribute__((__unused__)) argc, char *argv[])
{
char password[7], *codex;
int len = strlen(argv[1]), i, tmp;

codex = "A-CHRDw87lNS0E9B2TibgpnMVys5XzvtOGJcYLU+4mjW6fxqZeF3Qa1rPhdKIouk";

tmp = (len ^ 59) & 63;
password[0] = codex[tmp];

tmp = 0;
for (i = 0; i < len; i++)
tmp += argv[1][i];
password[1] = codex[(tmp ^ 79) & 63];

tmp = 1;
for (i = 0; i < len; i++)
tmp *= argv[1][i];
password[2] = codex[(tmp ^ 85) & 63];

tmp = 0;
for (i = 0; i < len; i++)
{
if (argv[1][i] > tmp)
tmp = argv[1][i];
}
srand(tmp ^ 14);
password[3] = codex[rand() & 63];

tmp = 0;
for (i = 0; i < len; i++)
tmp += (argv[1][i] * argv[1][i]);
password[4] = codex[(tmp ^ 239) & 63];

for (i = 0; i < argv[1][0]; i++)
tmp = rand();
password[5] = codex[(tmp ^ 229) & 63];

password[6] = '\0';
printf("%s", password);
return (0);
}

32 changes: 32 additions & 0 deletions 0x17-doubly_linked_lists/2-add_dnodeint.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "lists.h"

/**
* add_dnodeint - adds new head node to dlist
* @head: address of pointer to current head node
* @n: int field of new node
*
* Return: address of new node or NULL
*/
dlistint_t *add_dnodeint(dlistint_t **head, const int n)
{
dlistint_t *new = malloc(sizeof(dlistint_t));

if (!head || !new)
return (new ? free(new), NULL : NULL);

new->n = n;
new->prev = NULL;
if (!*head)
{
*head = new;
new->next = NULL;
}
else
{
new->next = *head;
(*head)->prev = new;
*head = new;
}
return (new);
}

35 changes: 35 additions & 0 deletions 0x17-doubly_linked_lists/3-add_dnodeint_end.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "lists.h"

/**
* add_dnodeint_end - adds new node to end of dlist
* @head: address of pointer to current head node
* @n: int field of new node
*
* Return: address of new node or NULL
*/
dlistint_t *add_dnodeint_end(dlistint_t **head, const int n)
{
dlistint_t *new = malloc(sizeof(dlistint_t)), *node;

if (!head || !new)
return (new ? free(new), NULL : NULL);

new->n = n;
new->next = NULL;
if (!*head)
{
new->prev = NULL;
*head = new;
}
else
{
node = *head;
while (node->next)
node = node->next;

node->next = new;
new->prev = node;
}
return (new);
}

20 changes: 20 additions & 0 deletions 0x17-doubly_linked_lists/4-free_dlistint.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "lists.h"

/**
* free_dlistint - frees a dlist
* @head: pointer to current head node
*
* Return: void
*/
void free_dlistint(dlistint_t *head)
{
dlistint_t *node;

while (head)
{
node = head;
head = head->next;
free(node);
}
}

23 changes: 23 additions & 0 deletions 0x17-doubly_linked_lists/5-get_dnodeint.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "lists.h"

/**
* get_dnodeint_at_index - returns node at given index
* @head: pointer to current head node
* @index: index of node to return
*
* Return: address of node at index
*/
dlistint_t *get_dnodeint_at_index(dlistint_t *head, unsigned int index)
{
unsigned int i = 0;

while (head)
{
if (i == index)
return (head);
head = head->next;
i++;
}
return (NULL);
}

20 changes: 20 additions & 0 deletions 0x17-doubly_linked_lists/6-sum_dlistint.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "lists.h"

/**
* sum_dlistint - sums the values of a dlist
* @head: pointer to current head node
*
* Return: int sum of values
*/
int sum_dlistint(dlistint_t *head)
{
int sum = 0;

while (head)
{
sum += head->n;
head = head->next;
}
return (sum);
}

41 changes: 41 additions & 0 deletions 0x17-doubly_linked_lists/7-insert_dnodeint.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include "lists.h"

/**
* insert_dnodeint_at_index - Inserts a new node in a dlistint_t
* list at a given position.
* @h: A pointer to the head of the dlistint_t list.
* @idx: The position to insert the new node.
* @n: The integer for the new node to contain.
*
* Return: If the function fails - NULL.
* Otherwise - the address of the new node.
*/
dlistint_t *insert_dnodeint_at_index(dlistint_t **h, unsigned int idx, int n)
{
dlistint_t *tmp = *h, *new;

if (idx == 0)
return (add_dnodeint(h, n));

for (; idx != 1; idx--)
{
tmp = tmp->next;
if (tmp == NULL)
return (NULL);
}

if (tmp->next == NULL)
return (add_dnodeint_end(h, n));

new = malloc(sizeof(dlistint_t));
if (new == NULL)
return (NULL);

new->n = n;
new->prev = tmp;
new->next = tmp->next;
tmp->next->prev = new;
tmp->next = new;

return (new);
}
1 change: 1 addition & 0 deletions 0x17-doubly_linked_lists/7-insert_dnodeint.c,
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

43 changes: 43 additions & 0 deletions 0x17-doubly_linked_lists/8-delete_dnodeint.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "lists.h"

/**
* delete_dnodeint_at_index - Deletes a node from a dlistint_t
* at a given index.
* @head: A pointer to the head of the dlistint_t.
* @index: The index of the node to delete.
*
* Return: Upon success - 1.
* Otherwise - -1.
*/
int delete_dnodeint_at_index(dlistint_t **head, unsigned int index)
{
dlistint_t *tmp = *head;

if (*head == NULL)
return (-1);

for (; index != 0; index--)
{
if (tmp == NULL)
return (-1);
tmp = tmp->next;
}

if (tmp == *head)
{
*head = tmp->next;
if (*head != NULL)
(*head)->prev = NULL;
}

else
{
tmp->prev->next = tmp->next;
if (tmp->next != NULL)
tmp->next->prev = tmp->prev;
}

free(tmp);
return (1);
}

1 change: 1 addition & 0 deletions 0x17-doubly_linked_lists/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
doubly_linked_lists

0 comments on commit e93eba9

Please sign in to comment.