Add: morse, rot13, and more docs
This commit is contained in:
@@ -66,6 +66,8 @@ void shell_install()
|
||||
register_command("echo", program_echo);
|
||||
register_command("sysinfo", program_sysinfo);
|
||||
register_command("conway", program_conway);
|
||||
register_command("rot13", program_rot13);
|
||||
register_command("morse", program_morse);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
|
||||
128
src/programs/ciphers.c
Normal file
128
src/programs/ciphers.c
Normal file
@@ -0,0 +1,128 @@
|
||||
#include "../libc/stdio.h"
|
||||
#include "ciphers.h"
|
||||
|
||||
void rot13(char* input, char* output)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
while (input[i] != '\0')
|
||||
{
|
||||
char c = input[i];
|
||||
|
||||
if (c >= 'a' && c <= 'z') {
|
||||
output[i] = ((c - 'a' + 13) % 26) + 'a';
|
||||
} else if (c >= 'A' && c <= 'Z') {
|
||||
output[i] = ((c - 'A' + 13) % 26) + 'A';
|
||||
} else {
|
||||
output[i] = c;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
output[i] = '\0';
|
||||
}
|
||||
|
||||
void program_rot13()
|
||||
{
|
||||
char input_buffer[BUFFER_SIZE];
|
||||
char output[BUFFER_SIZE];
|
||||
puts("String? ");
|
||||
get_input(input_buffer, BUFFER_SIZE);
|
||||
rot13(input_buffer, output);
|
||||
printf("\n%s\n", output);
|
||||
}
|
||||
|
||||
#include "../libc/string.h"
|
||||
#include "../libc/stdint.h"
|
||||
|
||||
const char* morse_alphabet[] = {
|
||||
".-", // A
|
||||
"-...", // B
|
||||
"-.-.", // C
|
||||
"-..", // D
|
||||
".", // E
|
||||
"..-.", // F
|
||||
"--.", // G
|
||||
"....", // H
|
||||
"..", // I
|
||||
".---", // J
|
||||
"-.-", // K
|
||||
".-..", // L
|
||||
"--", // M
|
||||
"-.", // N
|
||||
"---", // O
|
||||
".--.", // P
|
||||
"--.-", // Q
|
||||
".-.", // R
|
||||
"...", // S
|
||||
"-", // T
|
||||
"..-", // U
|
||||
"...-", // V
|
||||
".--", // W
|
||||
"-..-", // X
|
||||
"-.--", // Y
|
||||
"--.." // Z
|
||||
};
|
||||
|
||||
const char* morse_digits[] = {
|
||||
"-----", // 0
|
||||
".----", // 1
|
||||
"..---", // 2
|
||||
"...--", // 3
|
||||
"....-", // 4
|
||||
".....", // 5
|
||||
"-....", // 6
|
||||
"--...", // 7
|
||||
"---..", // 8
|
||||
"----." // 9
|
||||
};
|
||||
|
||||
void to_morse(const char* input, char* output) {
|
||||
int i = 0;
|
||||
int pos = 0;
|
||||
|
||||
while (input[i] != '\0') {
|
||||
char c = input[i];
|
||||
|
||||
if (c >= 'a' && c <= 'z') {
|
||||
const char* morse_code = morse_alphabet[c - 'a'];
|
||||
int j = 0;
|
||||
while (morse_code[j] != '\0') {
|
||||
output[pos++] = morse_code[j++];
|
||||
}
|
||||
} else if (c >= 'A' && c <= 'Z') {
|
||||
const char* morse_code = morse_alphabet[c - 'A'];
|
||||
int j = 0;
|
||||
while (morse_code[j] != '\0') {
|
||||
output[pos++] = morse_code[j++];
|
||||
}
|
||||
} else if (c >= '0' && c <= '9') {
|
||||
const char* morse_code = morse_digits[c - '0'];
|
||||
int j = 0;
|
||||
while (morse_code[j] != '\0') {
|
||||
output[pos++] = morse_code[j++];
|
||||
}
|
||||
} else if (c == ' ') {
|
||||
output[pos++] = ' ';
|
||||
}
|
||||
|
||||
output[pos++] = ' ';
|
||||
i++;
|
||||
}
|
||||
|
||||
if (pos > 0) {
|
||||
output[pos - 1] = '\0';
|
||||
} else {
|
||||
output[pos] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
void program_morse() {
|
||||
char output[512];
|
||||
char input_buffer[BUFFER_SIZE];
|
||||
puts("String? ");
|
||||
get_input(input_buffer, BUFFER_SIZE);
|
||||
to_morse(input_buffer, output);
|
||||
printf("\n%s\n", output);
|
||||
}
|
||||
|
||||
6
src/programs/ciphers.h
Normal file
6
src/programs/ciphers.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef CIPHERS_H
|
||||
#define CIPHERS_H
|
||||
|
||||
#define BUFFER_SIZE 256
|
||||
|
||||
#endif
|
||||
@@ -45,7 +45,7 @@ void program_uptime()
|
||||
|
||||
void program_help()
|
||||
{
|
||||
printf("help\tpanic\twords\tprimes\trainbow\tclear\nmath\tbf\t uptime echo\t sysinfo\tconway\n");
|
||||
printf("help\tpanic\twords\tprimes\trainbow\tclear\nmath\tbf\t uptime echo\t sysinfo\tconway\nrot13 morse\n");
|
||||
}
|
||||
|
||||
// Panic
|
||||
|
||||
@@ -11,6 +11,10 @@ void get_cpuid();
|
||||
void get_meminfo(unsigned int multiboot_info_address);
|
||||
void program_conway();
|
||||
|
||||
// Ciphers
|
||||
void program_rot13();
|
||||
void program_morse();
|
||||
|
||||
// Misc
|
||||
void program_rainbow();
|
||||
void program_clear();
|
||||
|
||||
Reference in New Issue
Block a user