1
+ /*
2
+ * brute.c (Rev.2) - APPEND VERSION - by Jigsy (https://github.com/Jigsy1) released under the Unlicense.
3
+ *
4
+ * Just a demo of looping through letter(s). A->B->C->...->AA->BA->...->...->XZZZ->YZZZ->ZZZZ->...
5
+ *
6
+ * Compiled on Windows 8.1 using TCC available from: https://bellard.org/tcc/
7
+ *
8
+ * How to:
9
+ * ----------
10
+ * ...> tcc -c brute.c
11
+ * ...> tcc -run brute.o
12
+ *
13
+ */
14
+
15
+ #include <stdio.h>
16
+ #include <string.h>
17
+
18
+ /* START OF PROTOTYPES */
19
+
20
+ void rotate (int index );
21
+
22
+ /* END OF PROTOTYPES */
23
+
24
+ const char CHAR_MAP [] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
25
+ #define MAPSIZE (sizeof(CHAR_MAP)/sizeof(CHAR_MAP[0]))
26
+ char STRING [MAPSIZE + 1 ] = "A" ; // +1 should account for \0.
27
+ const char END_STRING [] = "ZZZZ" ; // Make sure this is the last character of CHAR_MAP * strlen(STRING)!
28
+
29
+ void rotate (int index ) {
30
+ char * tempChar ;
31
+ int tempIndex ;
32
+ tempChar = strchr (CHAR_MAP , STRING [index ]);
33
+ tempIndex = (int ) (tempChar - CHAR_MAP );
34
+ // `-> Find the position of the current character in CHAR_MAP.
35
+ STRING [index ] = CHAR_MAP [(tempIndex + 1 ) % strlen (CHAR_MAP )];
36
+ if (CHAR_MAP [tempIndex ] == CHAR_MAP [(strlen (CHAR_MAP ) - 1 )]) {
37
+ STRING [index ] = CHAR_MAP [0 ];
38
+ if ((index + 1 ) == strlen (STRING )) {
39
+ STRING [(index + 1 )] = CHAR_MAP [0 ];
40
+ return ;
41
+ }
42
+ rotate ((index + 1 ));
43
+ }
44
+ }
45
+ int main (void ) {
46
+ int index = 0 ;
47
+ unsigned long int thisChar = 0 ;
48
+ for (;;) {
49
+ printf ("%s\n" , STRING );
50
+ if (strncmp (STRING , END_STRING , strlen (END_STRING )) == 0 ) {
51
+ // `-> STRING matches END_STRING so end here.
52
+ break ;
53
+ }
54
+ if (STRING [index ] == CHAR_MAP [(strlen (CHAR_MAP ) - 1 )]) {
55
+ if ((index + 1 ) == strlen (STRING )) {
56
+ STRING [(index + 1 )] = CHAR_MAP [0 ];
57
+ }
58
+ else {
59
+ rotate ((index + 1 ));
60
+ }
61
+ }
62
+ thisChar += 1 ;
63
+ STRING [index ] = CHAR_MAP [thisChar % strlen (CHAR_MAP )];
64
+ }
65
+ printf ("End.\n" );
66
+ return 0 ;
67
+ }
68
+
69
+ // EOF
0 commit comments