Skip to content

Commit 688e551

Browse files
authored
Added library to build your own crackmes
1 parent 352d665 commit 688e551

File tree

2 files changed

+433
-0
lines changed

2 files changed

+433
-0
lines changed
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
#include <stdio.h>
2+
#include <time.h>
3+
#include <stdlib.h>
4+
#include "stringzzz_crackme_library.h"
5+
6+
/*
7+
8+
Demonstration of the different stringzzz_crackme_library functions
9+
Note that due to the different odd characters output after each operation,
10+
the output may end up 'garbled up' and the rest may not display properly.
11+
This is just for example purposes, chances are you will not be displaying the strings
12+
in the actual crackme anyway.
13+
14+
By stringzzz, Ghostwarez Co. 2024
15+
16+
*/
17+
18+
int main() {
19+
srand(time(NULL)); //For genBox() function
20+
21+
//genBox
22+
int box[16]; //Must declare the box to pass to genBox
23+
genBox(box, 16, 30); //genBox(int out_box[], int box_size, int shuffles)
24+
25+
//Output the box in format for initializing the actual box in the crackme
26+
printf("box output: { ");
27+
for(int i = 0; i < 16; i++) {
28+
printf("%i", box[i]);
29+
if (i < 15) { printf(", "); }
30+
}
31+
printf(" };\n\n");
32+
33+
//genBytes
34+
int bytes[16]; //Must declare the bytes to pass to genBytes
35+
genBytes(bytes, 16, 127); //genBytes(int bytes, int byte_array_size, int max_value)
36+
37+
//Output the bytes in format for initializing the actual bytes in the crackme
38+
printf("bytes output: { ");
39+
for(int i = 0; i < 16; i++) {
40+
printf("%i", bytes[i]);
41+
if (i < 15) { printf(", "); }
42+
}
43+
printf(" };\n\n");
44+
45+
//sBox
46+
char test_string[] = "testing one two three";
47+
printf("Before S-Box: %s\n", test_string);
48+
int sbox[128]; //Must declare the box to pass to genBox
49+
genBox(sbox, 128, 100); //genBox(int out_box[], int box_size, int shuffles)
50+
sBox(test_string, string_length(test_string), sbox); //sBox(char string, int string_len, int sbox[])
51+
printf("After S-Box: %s\n", test_string);
52+
//Inverted sBox
53+
int inv_sbox[128];
54+
genInvertedBox(inv_sbox, sbox, 128); //genInvertedBox(int inv_box[], int box[], int box_size)
55+
sBox(test_string, string_length(test_string), inv_sbox); //sBox(char string, int string_len, int sbox[])
56+
printf("After Inverted S-Box: %s\n\n", test_string);
57+
58+
//pBox
59+
char test_string2[] = "testing one two three";
60+
printf("Before P-Box: %s\n", test_string2);
61+
int len1 = string_length(test_string2);
62+
int pbox[len1]; //Must declare the box to pass to genBox
63+
genBox(pbox, len1, 30); //genBox(int out_box[], int box_size, int shuffles)
64+
char test_string3[len1 + 1];
65+
pBox(test_string3, test_string2, len1, pbox); //pBox(char new_string[], char old_string[], int string_len, int pbox[])
66+
printf("After P-Box: %s\n", test_string3);
67+
//Inverted pBox
68+
int inv_pbox[len1];
69+
genInvertedBox(inv_pbox, pbox, len1); //genInvertedBox(int inv_box[], int box[], int box_size)
70+
char test_string4[len1 + 1];
71+
pBox(test_string4, test_string3, len1, inv_pbox); //pBox(char new_string[], char old_string[], int string_len, int pbox[])
72+
printf("After Inverted P-Box: %s\n\n", test_string4);
73+
74+
//addBytes
75+
char add_string[] = "testing one two three";
76+
printf("Before Add Bytes: %s\n", add_string);
77+
int add_bytes[len1];
78+
genBytes(add_bytes, len1, 127); //genBytes(int bytes[], int byte_array_size, int max_value)
79+
addBytes(add_string, len1, add_bytes, 128); //addBytes(char string[], int string_len, int bytes[], int mod)
80+
printf("After Add Bytes: %s\n", add_string);
81+
//subBytes
82+
subBytes(add_string, len1, add_bytes, 128); //subBytes(char string[], int string_len, int bytes[], int mod)
83+
printf("After Sub Bytes: %s\n\n", add_string);
84+
85+
//addNybbles
86+
char nybble_string[] = "testing one two three";
87+
printf("Before Add Nybbles: %s\n", nybble_string);
88+
int add_nybbles[len1 * 2];
89+
genBytes(add_nybbles, len1 * 2, 15); //genBytes(int bytes[], int byte_array_size, int max_value)
90+
addNybbles(nybble_string, len1, add_nybbles); //addNybbles(char string[], int string_len, int bytes[])
91+
printf("After Add Nybbles: %s\n", nybble_string);
92+
//subNybbles
93+
subNybbles(nybble_string, len1, add_nybbles); //subNybbles(char string[], int string_len, int bytes[])
94+
printf("After Sub Nybbles: %s\n\n", nybble_string);
95+
96+
//xorBytes
97+
char xor_string[] = "testing one two three";
98+
printf("Before xor bytes: %s\n", xor_string);
99+
int xor_bytes[len1];
100+
genBytes(xor_bytes, len1, 127); //genBytes(int bytes[], int byte_array_size, int max_value)
101+
xorBytes(xor_string, len1, xor_bytes); //xorBytes(char string[], int string_len, int bytes[])
102+
printf("After xor bytes: %s\n", xor_string);
103+
xorBytes(xor_string, len1, xor_bytes); //xorBytes(char string[], int string_len, int bytes[])
104+
printf("After xor bytes again: %s\n\n", xor_string);
105+
106+
//stringReversal
107+
char original_string[] = "this is a test";
108+
printf("String before reverse: %s\n", original_string);
109+
int rev_len = string_length(original_string);
110+
char reversed_string[rev_len + 1];
111+
stringReversal(reversed_string, original_string, rev_len); //stringReversal(char new_string[], char old_string[], int string_len)
112+
printf("String after reverse: %s\n", reversed_string);
113+
char reversed_string2[rev_len + 1];
114+
stringReversal(reversed_string2, reversed_string, rev_len); //stringReversal(char new_string[], char old_string[], int string_len)
115+
printf("String after reverse again: %s\n\n", reversed_string2);
116+
117+
//rotateNybbles
118+
char nybble_string3[] = "this is a test";
119+
printf("String before nybble rotation: %s\n", nybble_string3);
120+
int nybble_len = string_length(nybble_string3);
121+
rotateNybbles(nybble_string3, nybble_len); //rotateNybbles(char string[], int string_len)
122+
printf("String after nybble rotation: %s\n", nybble_string3);
123+
rotateNybbles(nybble_string3, nybble_len); //rotateNybbles(char string[], int string_len)
124+
printf("String after nybble rotation again: %s\n\n", nybble_string3);
125+
126+
//bitReversal
127+
char original_string2[] = "testing";
128+
printf("String before bit reverse: %s\n", original_string2);
129+
int rev_bit_len = string_length(original_string2);
130+
bitReversal(original_string2, rev_bit_len); //bitReversal(char string[], int string_len)
131+
printf("String after bit reverse: %s\n", original_string2);
132+
bitReversal(original_string2, rev_bit_len); //bitReversal(char string[], int string_len)
133+
printf("String after bit reverse again: %s\n\n", original_string2);
134+
135+
//bytesToNybbles
136+
//The main purpose of this (not shown) is to generate a P-Box the same size as nybbles_array
137+
// and run the nybble_array through it, permuting all the nybbles of the string.
138+
// They could then be reassembled
139+
char nybble_string1[] = "testing one two";
140+
printf("Original string: %s\n", nybble_string1);
141+
int len3 = string_length(nybble_string1);
142+
int nybble_array[len3 * 2];
143+
bytesToNybbles(nybble_string1, len3, nybble_array); //bytesToNybbles(char string[], int string_len, int nybbles[])
144+
printf("String as array of nybbles: ");
145+
for(int i = 0; i < len3 * 2; i++) {
146+
printf("%i ", nybble_array[i]);
147+
}
148+
printf("\n");
149+
//nybblesToBytes
150+
//Reassemble the nybbles back into a string
151+
char nybble_string2[len3 + 1];
152+
nybblesToBytes(nybble_string2, len3, nybble_array); //nybblesToBytes(char string[], int string_len, int nybbles[])
153+
printf("After reassemble back into string: %s\n\n", nybble_string2);
154+
155+
//bytesToBits
156+
//The main purpose of this (not shown) is to generate a P-Box the same size as bit_array
157+
// and run the bit_array through it, permuting all the bits of the string.
158+
// They could then be reassembled
159+
char test_string5[] = "testing";
160+
printf("Original string: %s\n", test_string5);
161+
int len2 = string_length(test_string5);
162+
int bit_array[len2 * 8];
163+
bytesToBits(test_string5, len2, bit_array); //bytesToBits(char string[], int string_len, int bits[])
164+
printf("String as array of bits: ");
165+
for(int i = 0; i < len2 * 8; i++) {
166+
printf("%i ", bit_array[i]);
167+
}
168+
printf("\n");
169+
//bitsToBytes
170+
//Reassemble the bits back into a string
171+
char test_string6[len2 + 1];
172+
bitsToBytes(test_string6, len2, bit_array); //bitsToBytes(char string[], int string_len, int bits[])
173+
printf("After reassemble back into string: %s\n\n", test_string6);
174+
175+
//Convert string to string of hex digits
176+
char test_string7[] = "testing one two three";
177+
printf("String as normal: %s\n", test_string7);
178+
int len4 = string_length(test_string7);
179+
char hex_string[len4 * 2 + 1];
180+
toHexString(hex_string, test_string7, len4); //toHexString(char new_string[], char old_string[], int string_len)
181+
printf("String as hex digits: %s\n", hex_string);
182+
//Convert same string to string of binary digits
183+
char bin_string[len4 * 8 + 1];
184+
toBinaryString(bin_string, test_string7, len4); //toBinaryString(char new_string[], char old_string[], int string_len)
185+
printf("String as binary digits: %s\n\n", bin_string);
186+
187+
return 0;
188+
}

0 commit comments

Comments
 (0)