-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathS2.C
More file actions
381 lines (323 loc) · 11 KB
/
Copy pathS2.C
File metadata and controls
381 lines (323 loc) · 11 KB
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
// Resolution data
typedef struct {
const char* label;
int width;
int height;
} Resolution;
Resolution resolutions[] = {
{"360p", 64, 20},
{"480p", 80, 25},
{"720p", 100, 30},
{"1080p", 120, 35},
{"1440p", 140, 40},
{"2160p", 160, 45},
{"4120p", 200, 55},
};
#define NUM_RESOLUTIONS (sizeof(resolutions) / sizeof(Resolution))
// ANSI color codes (use \x1b instead of \033 for Watcom/Turbo)
#define RESET "\x1b[0m"
#define BG_BLUE "\x1b[44m"
#define BG_GREEN "\x1b[102m"
#define FG_BLACK "\x1b[30m"
#define FG_WHITE "\x1b[97m"
#define FG_GREEN "\x1b[32m"
#define FG_CYAN "\x1b[36m"
#define FG_YELLOW "\x1b[33m"
#define FG_MAGENTA "\x1b[35m"
#define CLEAR "\x1b[2J\x1b[H"
// Globals
int screenWidth = 80;
int screenHeight = 25;
// Helper Functions
void clearScreen() {
printf(CLEAR);
}
void printHeader() {
clearScreen();
printf(FG_CYAN);
printf("==================================================\n");
printf(" Welcome to S2 HyperCalc Operating System \n");
printf(" by Coding Master 24 \n");
printf("==================================================\n\n");
printf(RESET);
}
void printTable() {
printf(FG_YELLOW);
printf("| Operation | Best Algorithm | Time Complexity | Use Case\n");
printf("|----------------------------|----------------------------|-----------------------|---------------------------------------------------------------\n");
printf(FG_WHITE);
printf("| Addition | Grade School Addition | O(n) | General-purpose addition of large numbers.\n");
printf("| Subtraction | Grade School Subtraction | O(n) | General-purpose subtraction of large numbers.\n");
printf("| Multiplication | Karatsuba Multiplication | O(n^1.585) | Efficient multiplication for large numbers.\n");
printf("| Multiplication (Very Large)| Schonhage-Strassen | O(n log n log log n) | Best for extremely large numbers (e.g., cryptography).\n");
printf("| Division | Newton-Raphson Division | O(n log n) | Fast division with high precision.\n");
printf("| Division (Very Large) | Schonhage-Strassen | O(n log n log log n) | Cryptographic-level division of large numbers.\n");
printf(RESET);
}
void drawBackground() {
int i, j;
clearScreen();
for (i = 0; i < screenHeight; i++) {
printf(BG_BLUE);
for (j = 0; j < screenWidth; j++) {
printf(" ");
}
printf(RESET "\n");
}
printf("\x1b[H");
}
void centerText(const char* text, const char* color) {
int len = strlen(text);
int pad = (screenWidth - len) / 2;
int i;
printf("%s", color);
for (i = 0; i < pad; i++) printf(" ");
printf("%s", text);
for (i = 0; i < screenWidth - pad - len; i++) printf(" ");
printf(RESET "\n");
}
void stripLeadingZeros(char* str) {
int i = 0;
while (str[i] == '0' && str[i + 1]) i++;
if (i > 0) memmove(str, str + i, strlen(str + i) + 1);
}
// Big Integer Arithmetic
void bigAdd(const char* a, const char* b, char* result) {
int i = strlen(a) - 1, j = strlen(b) - 1, carry = 0, k = 0, m;
char temp[2048] = {0};
while (i >= 0 || j >= 0 || carry) {
int sum = carry;
if (i >= 0) sum += a[i--] - '0';
if (j >= 0) sum += b[j--] - '0';
temp[k++] = (sum % 10) + '0';
carry = sum / 10;
}
for (m = 0; m < k; m++)
result[m] = temp[k - 1 - m];
result[k] = '\0';
}
void bigSubtract(const char* a, const char* b, char* result) {
int i = strlen(a) - 1, j = strlen(b) - 1, k = 0, borrow = 0, m;
char temp[2048] = {0};
while (i >= 0) {
int diff = a[i--] - '0' - borrow;
if (j >= 0) diff -= b[j--] - '0';
if (diff < 0) {
diff += 10;
borrow = 1;
} else {
borrow = 0;
}
temp[k++] = diff + '0';
}
while (k > 1 && temp[k - 1] == '0') k--;
for (m = 0; m < k; m++)
result[m] = temp[k - 1 - m];
result[k] = '\0';
}
void bigMultiply(const char* a, const char* b, char* result) {
int lenA = strlen(a), lenB = strlen(b);
int res[4096] = {0};
int i, j, start;
for (i = lenA - 1; i >= 0; i--) {
for (j = lenB - 1; j >= 0; j--) {
res[i + j + 1] += (a[i] - '0') * (b[j] - '0');
}
}
for (i = lenA + lenB - 1; i > 0; i--) {
if (res[i] >= 10) {
res[i - 1] += res[i] / 10;
res[i] %= 10;
}
}
start = 0;
while (start < lenA + lenB && res[start] == 0) start++;
if (start == lenA + lenB) {
strcpy(result, "0");
return;
}
for (i = start; i < lenA + lenB; i++)
result[i - start] = res[i] + '0';
result[lenA + lenB - start] = '\0';
}
void bigDivide(const char* a, int divisor, char* result) {
int len = strlen(a), rem = 0, k = 0, i;
for (i = 0; i < len; i++) {
int curr = rem * 10 + (a[i] - '0');
result[k++] = (curr / divisor) + '0';
rem = curr % divisor;
}
result[k] = '\0';
stripLeadingZeros(result);
}
// UI & Menu
void waitForEnter() {
printf("\n");
centerText("Press Enter to return to menu...", BG_BLUE FG_WHITE);
getchar(); getchar();
}
void drawTitleBar() {
printf("\x1b[1;1H");
centerText("S2 HyperCalc Operating System", BG_GREEN FG_BLACK);
printf("\n");
}
void drawMenu() {
int i;
int startY;
const char* menu[5];
// Assigning static string literals (must happen after declaration)
menu[0] = "[1] Home";
menu[1] = "[2] Settings";
menu[2] = "[3] About";
menu[3] = "[4] Calculator";
menu[4] = "[0] Exit";
drawBackground();
drawTitleBar();
startY = (screenHeight - 10) / 2;
for (i = 0; i < startY; i++) {
printf("\n");
}
for (i = 0; i < 5; i++) {
centerText(menu[i], BG_BLUE FG_WHITE);
}
printf("\n");
centerText("Enter your choice: ", BG_BLUE FG_WHITE);
}
void showScreen(const char* title, const char* content) {
drawBackground();
centerText(title, BG_GREEN FG_BLACK);
printf("\n\n");
centerText(content, BG_BLUE FG_WHITE);
waitForEnter();
}
void showSettings() {
int i, choice;
char line[128];
drawBackground();
centerText("SETTINGS - CHOOSE RESOLUTION", BG_GREEN FG_BLACK);
printf("\n");
for (i = 0; i < NUM_RESOLUTIONS; i++) {
sprintf(line, "[%d] %s (%dx%d)", i + 1, resolutions[i].label, resolutions[i].width, resolutions[i].height);
centerText(line, BG_BLUE FG_WHITE);
}
printf("\n");
centerText("Enter choice (1-7): ", BG_BLUE FG_WHITE);
scanf("%d", &choice);
getchar();
if (choice >= 1 && choice <= NUM_RESOLUTIONS) {
screenWidth = resolutions[choice - 1].width;
screenHeight = resolutions[choice - 1].height;
showScreen("SETTINGS", "Resolution updated successfully.");
} else {
showScreen("ERROR", "Invalid resolution choice.");
}
}
void calculator() {
char a[1024], b[1024], result[2048];
char op;
drawBackground();
centerText("BIG INTEGER CALCULATOR", BG_GREEN FG_BLACK);
printf("\n\n");
printf("Enter first number: ");
scanf("%s", a);
printf("Enter operator (+ - * /): ");
scanf(" %c", &op);
printf("Enter second number: ");
scanf("%s", b);
if (op == '+') {
bigAdd(a, b, result);
} else if (op == '-') {
bigSubtract(a, b, result);
} else if (op == '*') {
bigMultiply(a, b, result);
} else if (op == '/') {
int divisor = atoi(b);
if (divisor == 0) {
showScreen("ERROR", "Division by zero is undefined.");
return;
}
bigDivide(a, divisor, result);
} else {
showScreen("ERROR", "Invalid operator.");
return;
}
printf("\nResult = %s\n", result);
waitForEnter();
}
int home() {
printHeader();
printTable();
printf("\n" FG_MAGENTA);
printf(">> S2 HyperCalc OS is optimized for large-number computation and cryptographic performance.\n");
printf(">> Built for researchers, mathematicians, and power users.\n");
printf(">> Powered by next-gen number theory and algorithmic precision.\n");
printf(RESET);
printf("\n\nPress Enter to exit...");
getchar();
return 0;
}
int about() {
clearScreen();
printf(FG_CYAN);
printf("===========================================\n");
printf(" ABOUT - S2 NUMAX OS \n");
printf("===========================================\n\n");
printf(RESET);
printf(FG_WHITE);
printf("S2 NUMAX OS is a high-performance number-oriented\n");
printf("operating system built to handle extremely large\n");
printf("integer computations with unmatched precision and speed.\n\n");
printf(FG_YELLOW);
printf("Main Features:\n");
printf(FG_WHITE);
printf(" • Optimized algorithms for big-number arithmetic\n");
printf(" • Cryptographic support for ultra-large multiplications\n");
printf(" • Efficient and scalable core for scientific computing\n\n");
printf(FG_YELLOW);
printf("Supported Algorithms:\n");
printf(FG_WHITE);
printf(" - Grade School Addition / Subtraction\n");
printf(" - Karatsuba Multiplication\n");
printf(" - Schonhage-Strassen Multiplication & Division\n");
printf(" - Newton-Raphson Division\n\n");
printf(FG_YELLOW);
printf("Developed by:\n");
printf(FG_MAGENTA);
printf(" ➤ Coding Master 24\n");
printf(" ➤ Version: S2 NUMAX 1.0\n\n");
printf(FG_GREEN);
printf(">> Designed for researchers, cryptographers, and\n");
printf(" anyone working with high-precision numerics.\n\n");
printf(RESET);
printf("Press Enter to return...");
getchar();
return 0;
}
int main() {
char choice;
screenWidth = resolutions[1].width;
screenHeight = resolutions[1].height;
while (1) {
drawMenu();
choice = getchar();
getchar();
switch (choice) {
case '1': home(); break;
case '2': showSettings(); break;
case '3': about(); break;
case '4': calculator(); break;
case '0':
drawBackground();
centerText("Exiting... Bye!", BG_GREEN FG_BLACK);
printf("\nExiting S2 NUMAX OS... Goodbye!\n");
exit(0);
default:
showScreen("ERROR", "Invalid choice.");
break;
}
}
}