- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
typedef struct
{
char current;
char from;
char to;
} tdsSymbDiap;
uint8_t changeSymbol(tdsSymbDiap * const _pSymb, const tdsSymbDiap * const _pEnd)
{
if( (_pSymb < _pEnd) == 0 )
return 0;
if( ++_pSymb->current <= _pSymb->to )
return 0;
_pSymb->current = _pSymb->from;
return 1;
}
uint8_t moveToNextSymbol(tdsSymbDiap * const _pSymb, const tdsSymbDiap * const _pEnd)
{
if( (_pSymb < _pEnd) == 0 )
return 1;
return moveToNextSymbol( _pSymb + 1, _pEnd ) && changeSymbol( _pSymb, _pEnd );
};
void getWord(const tdsSymbDiap * _pSymb, const tdsSymbDiap * const _pEnd, char * _pWord)
{
while( _pSymb < _pEnd )
{
*_pWord = _pSymb->current;
++_pWord;
++_pSymb;
}
*_pWord = 0;
}
void generateSymbols(tdsSymbDiap * _pSymb, const char *_pWord, size_t _size)
{
if( _size == 0 )
return;
while( _size-- )
{
if( *_pWord == '@' )
{
_pSymb->from = 'a';
_pSymb->to = 'z';
}
else if( *_pWord == '#' )
{
_pSymb->from = 'A';
_pSymb->to = 'Z';
}
else if( *_pWord == '$' )
{
_pSymb->from = '0';
_pSymb->to = '9';
}
else
{
_pSymb->from = *_pWord;
_pSymb->to = *_pWord;
}
_pSymb->current = _pSymb->from;
++_pSymb;
++_pWord;
}
}
int main(void)
{
char word[ ] = "@4#2u$a#"; // @ - a..z; # - A..Z; $ - 0..9
const size_t wordSize = strlen(word);
if( wordSize == 0 )
return 1;
tdsSymbDiap *pWord = malloc( wordSize * sizeof(tdsSymbDiap) );
generateSymbols(pWord, word, wordSize);
do
{
getWord(pWord, pWord + wordSize, word);
printf("%s\n", word);
} while( moveToNextSymbol(pWord, pWord + wordSize) == 0 );
free(pWord);
return 0;
}