-
Notifications
You must be signed in to change notification settings - Fork 9
/
convert.c
407 lines (389 loc) · 9.93 KB
/
convert.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
/*
** Copyright (c) 1999, 2000, 2001, 2002, 2003
** Adel I. Mirzazhanov. All rights reserved
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
** are met:
**
** 1.Redistributions of source code must retain the above copyright notice,
** this list of conditions and the following disclaimer.
** 2.Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** 3.The name of the author may not be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
** OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
** GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdlib.h>
#include <string.h>
#if !defined(WIN32) && !defined(_WIN32) && !defined(__WIN32) && !defined(__WIN32__)
#include <strings.h>
#endif
#ifndef APGBFM
# include "errs.h"
# include "randpass.h"
#endif
#include "convert.h"
/*
** GLOBALS
*/
/* small letters */
char let[26] =
{
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x', 'w', 'z'
};
/* capital letters */
char clet[26] =
{
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
'U', 'V', 'W', 'X', 'W', 'Z'
};
/*
** FUNCTIONS
*/
/*
** decapitalize() - This routine replaces all capital letters
** to small letters in the word:
** INPUT:
** char * - word.
** OUTPUT:
** none.
** NOTES:
** none.
*/
void
decapitalize (char *word)
{
int i = 0; /* counter */
int j = 0; /* counter */
int str_len = strlen(word);
for(j = 0; j < str_len; j++)
for(i=0; i < 26; i++)
if(word[j] == clet[i])
word[j] = let[i];
}
#ifndef APGBFM
/*
** capitalize() - This routine designed to modify sullable like this:
** adel ----> Adel
** dot ----> Dot
** etc.
** INPUT:
** char * - syllable.
** OUTPUT:
** none.
** NOTES:
** none.
*/
void
capitalize (char *syllable)
{
char tmp = 0x00;
int i = 0;
if ( randint(2) == TRUE)
{
(void)memcpy((void *)&tmp, (void *)syllable, sizeof(tmp));
for(i=0; i < 26; i++)
if ( let[i] == tmp )
if (is_restricted_symbol(clet[i]) != TRUE)
(void)memcpy ((void *)syllable, (void *)&clet[i], 1);
}
}
/*
** numerize() - This routine designed to modify single-letter
** syllable like this:
** a ----> 1 or 2 or 3 etc.
** u ----> 1 or 2 or 3 etc.
** etc.
** INPUT:
** char * - single-letter syllable
** OUTPUT:
** none.
** NOTES:
** none.
*/
void
numerize (char *syllable)
{
char *tmp;
if ( (tmp = (char *)calloc(1, 4)) == NULL)
err_sys_fatal("calloc");
if ( strlen (syllable) == 1 )
{
(void) gen_rand_symbol(tmp, S_NB);
(void)memcpy ((void *)syllable, (void *)tmp, 1);
}
free ((void *)tmp);
}
/*
** specialize() - This routine designed to modify single-letter syllable
** like this:
** a ----> # or $ or % etc.
** u ----> # or $ or % etc.
** etc.
** INPUT:
** char * - single-letter syllable.
** OUTPUT:
** none.
** NOTES:
** none.
*/
void
specialize (char *syllable)
{
char *tmp;
if ( (tmp = (char *)calloc(1, 4)) == NULL)
err_sys_fatal("calloc");
if ( strlen (syllable) == 1 )
{
(void) gen_rand_symbol(tmp, S_SS);
(void)memcpy ((void *)syllable, (void *)tmp, 1);
}
free ((void *)tmp);
}
/*
** symb2name - convert symbol to it's name
** INPUT:
** char * - one symbol syllable
** OUTPUT:
** none.
** NOTES:
** none.
*/
void
symb2name(char * syllable, char * h_syllable)
{
struct ssymb_names
{
char symbol;
char *name;
};
static struct ssymb_names ssn[42] =
{
{'1',"ONE"},
{'2',"TWO"},
{'3',"THREE"},
{'4',"FOUR"},
{'5',"FIVE"},
{'6',"SIX"},
{'7',"SEVEN"},
{'8',"EIGHT"},
{'9',"NINE"},
{'0',"ZERO"},
{33, "EXCLAMATION_POINT"},
{34, "QUOTATION_MARK"},
{35, "CROSSHATCH"},
{36, "DOLLAR_SIGN"},
{37, "PERCENT_SIGN"},
{38, "AMPERSAND"},
{39, "APOSTROPHE"},
{40, "LEFT_PARENTHESIS"},
{41, "RIGHT_PARENTHESIS"},
{42, "ASTERISK"},
{43, "PLUS_SIGN"},
{44, "COMMA"},
{45, "HYPHEN"},
{46, "PERIOD"},
{47, "SLASH"},
{58, "COLON"},
{59, "SEMICOLON"},
{60, "LESS_THAN"},
{61, "EQUAL_SIGN"},
{62, "GREATER_THAN"},
{63, "QUESTION_MARK"},
{64, "AT_SIGN"},
{91, "LEFT_BRACKET"},
{92, "BACKSLASH"},
{93, "RIGHT_BRACKET"},
{94, "CIRCUMFLEX"},
{95, "UNDERSCORE"},
{96, "GRAVE"},
{123, "LEFT_BRACE"},
{124, "VERTICAL_BAR"},
{125, "RIGHT_BRACE"},
{126, "TILDE"}
};
int i = 0;
int flag = FALSE;
if (strlen(syllable) == 1)
{
for (i = 0; i < 42; i++)
{
if(*syllable == ssn[i].symbol)
{
(void)memcpy((void*)h_syllable, (void*)ssn[i].name, strlen(ssn[i].name));
flag = TRUE;
}
}
if (flag != TRUE)
(void)memcpy((void*)h_syllable, (void*)syllable, strlen(syllable));
}
}
/*
** spell_word - spell the word
** INPUT:
** char * - pointer to the word
** char * - pointer to the spelled word
** OUTPUT:
** char * - pointer to the spelled word
** NULL - something is wrong
** NOTES:
** You should free() memory pointed by spelled_word after each use of spell_word
*/
char *
spell_word(char * word, char * spelled_word)
{
struct char_spell
{
char symbol;
char *name;
};
static struct char_spell cs[94] =
{
{'1',"ONE" },
{'2',"TWO" },
{'3',"THREE" },
{'4',"FOUR" },
{'5',"FIVE" },
{'6',"SIX" },
{'7',"SEVEN" },
{'8',"EIGHT" },
{'9',"NINE" },
{'0',"ZERO" },
{'A', "Alfa" },
{'B', "Bravo" },
{'C', "Charlie" },
{'D', "Delta" },
{'E', "Echo" },
{'F', "Foxtrot" },
{'G', "Golf" },
{'H', "Hotel" },
{'I', "India" },
{'J', "Juliett" },
{'K', "Kilo" },
{'L', "Lima" },
{'M', "Mike" },
{'N', "November" },
{'O', "Oscar" },
{'P', "Papa" },
{'Q', "Quebec" },
{'R', "Romeo" },
{'S', "Sierra" },
{'T', "Tango" },
{'U', "Uniform" },
{'V', "Victor" },
{'W', "Whiskey" },
{'X', "X_ray" },
{'Y', "Yankee" },
{'Z', "Zulu" },
{'a', "alfa" },
{'b', "bravo" },
{'c', "charlie" },
{'d', "delta" },
{'e', "echo" },
{'f', "foxtrot" },
{'g', "golf" },
{'h', "hotel" },
{'i', "india" },
{'j', "juliett" },
{'k', "kilo" },
{'l', "lima" },
{'m', "mike" },
{'n', "november" },
{'o', "oscar" },
{'p', "papa" },
{'q', "quebec" },
{'r', "romeo" },
{'s', "sierra" },
{'t', "tango" },
{'u', "uniform" },
{'v', "victor" },
{'w', "whiskey" },
{'x', "x_ray" },
{'y', "yankee" },
{'z', "zulu" },
{33, "EXCLAMATION_POINT"},
{34, "QUOTATION_MARK" },
{35, "CROSSHATCH" },
{36, "DOLLAR_SIGN" },
{37, "PERCENT_SIGN" },
{38, "AMPERSAND" },
{39, "APOSTROPHE" },
{40, "LEFT_PARENTHESIS" },
{41, "RIGHT_PARENTHESIS"},
{42, "ASTERISK" },
{43, "PLUS_SIGN" },
{44, "COMMA" },
{45, "HYPHEN" },
{46, "PERIOD" },
{47, "SLASH" },
{58, "COLON" },
{59, "SEMICOLON" },
{60, "LESS_THAN" },
{61, "EQUAL_SIGN" },
{62, "GREATER_THAN" },
{63, "QUESTION_MARK" },
{64, "AT_SIGN" },
{91, "LEFT_BRACKET" },
{92, "BACKSLASH" },
{93, "RIGHT_BRACKET" },
{94, "CIRCUMFLEX" },
{95, "UNDERSCORE" },
{96, "GRAVE" },
{123, "LEFT_BRACE" },
{124, "VERTICAL_BAR" },
{125, "RIGHT_BRACE" },
{126, "TILDE" }
};
int s_length = 0;
int i = 0;
int j = 0;
int word_len = strlen(word);
char * tmp_ptr;
char hyphen = '-';
char zero = 0x00;
/* Count the length of the spelled word */
for (i=0; i <= word_len; i++)
for (j=0; j < 94; j++)
if (word[i] == cs[j].symbol)
{
s_length = s_length + strlen(cs[j].name) + 1;
continue;
}
/* Allocate memory for spelled word */
if ( (spelled_word = (char *)calloc(1, (size_t)s_length)) == NULL)
return(NULL);
/* Construct spelled word */
tmp_ptr = spelled_word;
for (i=0; i < word_len; i++)
for (j=0; j < 94; j++)
if (word[i] == cs[j].symbol)
{
(void) memcpy((void *)tmp_ptr, (void *)cs[j].name, strlen(cs[j].name));
tmp_ptr = tmp_ptr + strlen(cs[j].name);
/* Place the hyphen after each symbol */
(void) memcpy((void *)(tmp_ptr), (void *)&hyphen, 1);
tmp_ptr = tmp_ptr + 1;
continue;
}
/* Remove hyphen at the end of the word */
tmp_ptr = tmp_ptr - 1;
(void) memcpy((void *)(tmp_ptr), (void *)&zero, 1);
return (spelled_word);
}
#endif /* APGBFM */