change message size cap (was 128) to INT64_MAX
This commit is contained in:
parent
1a8f4bbd90
commit
da87b9a8a0
@ -12,6 +12,7 @@
|
|||||||
#include "dyninput.h"
|
#include "dyninput.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
@ -24,11 +25,12 @@ int main()
|
|||||||
,stdout
|
,stdout
|
||||||
);
|
);
|
||||||
char buf[4];
|
char buf[4];
|
||||||
|
int64_t maxsize = INT64_MAX;
|
||||||
fgets(buf, 3, stdin);
|
fgets(buf, 3, stdin);
|
||||||
int choice = strtol(buf, NULL, 10);
|
int choice = strtol(buf, NULL, 10);
|
||||||
|
|
||||||
fputs("Enter your message text: ", stdout);
|
fputs("Enter your message text: ", stdout);
|
||||||
char* msg = dyninput_str(INT64_MAX);
|
char* msg = dyninput_str(maxsize);
|
||||||
if (!msg)
|
if (!msg)
|
||||||
{
|
{
|
||||||
puts("ERROR: String input failed! Exiting...");
|
puts("ERROR: String input failed! Exiting...");
|
||||||
@ -41,18 +43,18 @@ int main()
|
|||||||
|
|
||||||
if (choice == 1)
|
if (choice == 1)
|
||||||
{
|
{
|
||||||
caesar_encrypt(msg, 128, key);
|
caesar_encrypt(msg, maxsize, key);
|
||||||
puts("\nYour encrypted message is:");
|
puts("\nYour encrypted message is:");
|
||||||
for (int i = 0; i < 128 && msg[i]; i++)
|
for (int i = 0; i < maxsize && msg[i]; i++)
|
||||||
{
|
{
|
||||||
putchar(msg[i]);
|
putchar(msg[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (choice == 2)
|
else if (choice == 2)
|
||||||
{
|
{
|
||||||
caesar_decrypt(msg, 128, key);
|
caesar_decrypt(msg, maxsize, key);
|
||||||
puts("\nYour decrypted message is:");
|
puts("\nYour decrypted message is:");
|
||||||
for (int i = 0; i < 128 && msg[i]; i++)
|
for (int i = 0; i < maxsize && msg[i]; i++)
|
||||||
{
|
{
|
||||||
putchar(msg[i]);
|
putchar(msg[i]);
|
||||||
}
|
}
|
||||||
|
10
src/crypt.c
10
src/crypt.c
@ -9,7 +9,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "crypt.h"
|
#include "crypt.h"
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -43,9 +45,9 @@ inline bool isupper(char c)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void caesar_encrypt(char* str, int size, int key)
|
void caesar_encrypt(char* str, int64_t size, int key)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < size && str[i] != '\n'; i++)
|
for (int64_t i = 0; i < size && str[i] != '\n'; i++)
|
||||||
if (str[i] != ' ')
|
if (str[i] != ' ')
|
||||||
{
|
{
|
||||||
bool upper = isupper(str[i]);
|
bool upper = isupper(str[i]);
|
||||||
@ -56,9 +58,9 @@ void caesar_encrypt(char* str, int size, int key)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void caesar_decrypt(char* str, int size, int key)
|
void caesar_decrypt(char* str, int64_t size, int key)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < size && str[i] != '\n'; i++)
|
for (int64_t i = 0; i < size && str[i] != '\n'; i++)
|
||||||
if (str[i] != ' ')
|
if (str[i] != ' ')
|
||||||
{
|
{
|
||||||
bool upper = isupper(str[i]);
|
bool upper = isupper(str[i]);
|
||||||
|
@ -9,8 +9,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
void caesar_encrypt(char* str, int size, int key);
|
void caesar_encrypt(char* str, int64_t size, int key);
|
||||||
|
|
||||||
void caesar_decrypt(char* str, int size, int key);
|
void caesar_decrypt(char* str, int64_t size, int key);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user