-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetfile2.c
104 lines (97 loc) · 1.8 KB
/
getfile2.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "main.h"
#include <stdlib.h>
/**
* rev_string - Reverses the order of characters in a string.
* @s: A pointer to a null-terminated string to be reversed.
*/
void rev_string(char *s)
{
int head, tail;
int len;
char tmp;
if (s == NULL)
{
s = "(null)";
}
for (len = 0; s[len] != '\0'; len++)
;
head = 0;
tail = len - 1;
while (head < tail)
{
tmp = *(s + head);
*(s + head) = *(s + tail);
*(s + tail) = tmp;
head++;
tail--;
}
}
/**
* get_rev - returns a reversed copy of a string
* @s: string to be reversed
* Return: string reversed
*/
char *get_rev(char *s)
{
char *ptr = NULL;
ptr = get_string(s);
if (!ptr)
{
return (NULL);
}
if (s)
{
rev_string(ptr);
}
return (ptr);
}
/**
* rot13 - performs rot13 encryption on a string
* @s: string to be encrypted
*
* Return: pointer to the encrypted string
*/
char *rot13(char *s)
{
char *ptr;
int i;
char c[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
char r[] = {'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
'y', 'z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
'U', 'V', 'W', 'X', 'Y', 'Z', 'A', 'B', 'C', 'D', 'E',
'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M'};
for (ptr = s; *ptr != '\0'; ptr++)
{
for (i = 0; i < 52; i++)
{
if (*ptr == c[i])
{
*ptr = r[i];
break;
}
}
}
return (s);
}
/**
* get_rot13 - get rot13
* @s: string
* Return: ptr to string
*/
char *get_rot13(char *s)
{
char *ptr = NULL;
ptr = get_string(s);
if (!ptr)
return (NULL);
if (s)
{
rot13(ptr);
}
return (ptr);
}