1+ /*
2+ MIT License
3+
4+ Copyright (c) 2022 m!haly4
5+
6+ Permission is hereby granted, free of charge, to any person obtaining a copy
7+ of this software and associated documentation files (the "Software"), to deal
8+ in the Software without restriction, including without limitation the rights
9+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ copies of the Software, and to permit persons to whom the Software is
11+ furnished to do so, subject to the following conditions:
12+
13+ The above copyright notice and this permission notice shall be included in all
14+ copies or substantial portions of the Software.
15+
16+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+ SOFTWARE.
23+ */
24+
25+ /*function declaration*/
26+ int system_write (int fd , const void * buf , int size );
27+
28+ /*declaration of few strings*/
29+ static const char error_message [] = "Invalid input:\nPlease enter the password\n" ;
30+ static const char password [] = "Hello" ;
31+ static const char data [] = "Success!\nThe secret data: <the data was deleted> :)\n" ;
32+
33+ /*function for calculating the length of the string*/
34+ static int string_length (const char * string )
35+ {
36+ int i = 0 ;
37+ while (string [i ])
38+ {
39+ i ++ ;
40+ }
41+
42+ return i ;
43+ }
44+
45+ /*function for comparing two strings*/
46+ static int string_compare (char * string , const char * bufer )
47+ {
48+ int i = 0 ;
49+
50+ /*to check that both lines are the same length*/
51+ if ((string_length (bufer )) == (string_length (string )))
52+ {
53+ while (string [i ])
54+ {
55+ if (string [i ] == bufer [i ])
56+ {
57+ ++ i ;
58+ }
59+ else
60+ {
61+ break ;
62+ }
63+ }
64+ }
65+ else
66+ {
67+ return 0 ;
68+ }
69+
70+ return i ;
71+ }
72+
73+ int main (int argc , char * * argv )
74+ {
75+ /*check at least 1 argument exist and check the password correctness*/
76+ if ((argc > 1 ) && (string_compare (argv [1 ], password ) == 5 ))
77+ {
78+ system_write (1 , data , sizeof (data )- 1 );
79+ /*
80+ system_write(1, argv[1], string_length(argv[1]));
81+ system_write(1, "\n", 1);
82+ */
83+ }
84+ else
85+ {
86+ /*error message*/
87+ system_write (1 , error_message , sizeof (error_message )- 1 );
88+ return 1 ;
89+ }
90+
91+ return 0 ;
92+ }
0 commit comments