-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom_helpers.c
71 lines (60 loc) · 1.29 KB
/
custom_helpers.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "holberton.h"
/**
* mask_check - checks to see if a given flag indicator is present in the mask
* @mask: mask that may or may not contain the indicator
* @val: flag indicator to be checked for
*
* Return: TRUE if flag indicator is present, FALSE if not
*/
int mask_check(int mask, int val)
{
if ((mask & val) != 0)
return (TRUE);
return (FALSE);
}
/**
* rev_str - creates a string that is the reverse of the input string
* @str: string to be reverse
*
* Return: the reversed string
*/
char *rev_str(char *str)
{
char *new_str = malloc(_strlen(str) + 1);
new_str += _strlen(str);
*new_str = '\0';
while (*str != '\0')
{
new_str--;
*new_str = *str;
str++;
}
return (new_str);
}
/**
* rot_13 - creates the rot_13 encrypted version of the input string
* @str: string to be converted
*
* Return: the encrypted string
*/
char *rot_13(char *str)
{
char *new_str = malloc(_strlen(str) + 1);
char *new_ptr = new_str;
while (*str != '\0')
{
if ((*str >= 'a' && *str <= 'm')
|| (*str >= 'A' && *str <= 'M'))
*new_ptr = *str + 13;
else if (*str >= 'n' && *str <= 'z')
*new_ptr = 'a' + *str - 'n';
else if (*str >= 'N' && *str <= 'Z')
*new_ptr = 'A' + *str - 'N';
else
*new_ptr = *str;
str++;
new_ptr++;
}
*new_ptr = '\0';
return (new_str);
}