-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1b8439c
commit e93eba9
Showing
14 changed files
with
315 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
en C Pyfo neZ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
906609 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
doubly_linked_lists |