Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check50/submit50 is not working #371

Closed
wangbuyubobo opened this issue Nov 12, 2024 · 5 comments
Closed

check50/submit50 is not working #371

wangbuyubobo opened this issue Nov 12, 2024 · 5 comments

Comments

@wangbuyubobo
Copy link

can anyone help how i know why the check50 is not working. pop up error: invalid slug. i used yesterday ok but suddenly today is not working. i tried pin show check50, it came bake the token information properly. Thanks.

@22119795
Copy link

22119795 commented Jan 6, 2025

#include <cs50.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <stdio.h>

// Function declarations with clearer names
bool is_all_digits(string input);
string encrypt_text(string input_text, int key);

int main(int argc, string argv[])
{
// Ensure the program is executed with exactly one command-line argument
if (argc != 2 || !is_all_digits(argv[1]))
{
printf("Usage: ./caesar key\n");
return 1;
}

// Convert the key from a string to an integer
int key = atoi(argv[1]);

// Get the plaintext input from the user
string plaintext = get_string("Plaintext: ");

// Encrypt the plaintext
string ciphertext = encrypt_text(plaintext, key);

// Output the ciphertext
printf("Ciphertext: %s\n", ciphertext);

// Free allocated memory for ciphertext
free(ciphertext);

return 0;

}

// Check if all characters in the input string are digits
bool is_all_digits(string input)
{
for (int i = 0; i < strlen(input); i++)
{
if (!isdigit(input[i]))
{
return false;
}
}
return true;
}

// Encrypt the input text using the Caesar cipher
string encrypt_text(string input_text, int key)
{
// Allocate memory for the encrypted text
string encrypted_text = malloc(strlen(input_text) + 1);
if (!encrypted_text)
{
printf("Memory allocation failed.\n");
exit(1);
}

// Encrypt each character
for (int i = 0; i < strlen(input_text); i++)
{
    if (isalpha(input_text[i]))
    {
        if (islower(input_text[i]))
        {
            encrypted_text[i] = ((input_text[i] - 'a' + key) % 26) + 'a';
        }
        else
        {
            encrypted_text[i] = ((input_text[i] - 'A' + key) % 26) + 'A';
        }
    }
    else
    {
        encrypted_text[i] = input_text[i];
    }
}

// Null-terminate the encrypted string
encrypted_text[strlen(input_text)] = '\0';

return encrypted_text;

}

@dmalan dmalan closed this as not planned Won't fix, can't repro, duplicate, stale Jan 6, 2025
@22119795
Copy link

22119795 commented Jan 6, 2025

submit50 cs50/problems/2024/x/ceasar
#include <cs50.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <stdio.h>

// Function declarations with clearer names
bool is_all_digits(string input);
string encrypt_text(string input_text, int key);

int main(int argc, string argv[])
{
// Ensure the program is executed with exactly one command-line argument
if (argc != 2 || !is_all_digits(argv[1]))
{
printf("Usage: ./caesar key\n");
return 1;
}

// Convert the key from a string to an integer
int key = atoi(argv[1]);

// Get the plaintext input from the user
string plaintext = get_string("Plaintext: ");

// Encrypt the plaintext
string ciphertext = encrypt_text(plaintext, key);

// Output the ciphertext
printf("Ciphertext: %s\n", ciphertext);

// Free allocated memory for ciphertext
free(ciphertext);

return 0;

}

// Check if all characters in the input string are digits
bool is_all_digits(string input)
{
for (int i = 0; i < strlen(input); i++)
{
if (!isdigit(input[i]))
{
return false;
}
}
return true;
}

// Encrypt the input text using the Caesar cipher
string encrypt_text(string input_text, int key)
{
// Allocate memory for the encrypted text
string encrypted_text = malloc(strlen(input_text) + 1);
if (!encrypted_text)
{
printf("Memory allocation failed.\n");
exit(1);
}

// Encrypt each character
for (int i = 0; i < strlen(input_text); i++)
{
    if (isalpha(input_text[i]))
    {
        if (islower(input_text[i]))
        {
            encrypted_text[i] = ((input_text[i] - 'a' + key) % 26) + 'a';
        }
        else
        {
            encrypted_text[i] = ((input_text[i] - 'A' + key) % 26) + 'A';
        }
    }
    else
    {
        encrypted_text[i] = input_text[i];
    }
}

// Null-terminate the encrypted string
encrypted_text[strlen(input_text)] = '\0';

return encrypted_text;

}

@dmalan
Copy link
Member

dmalan commented Jan 6, 2025

Best to post in any of CS50's communities, https://cs50.harvard.edu/x/communities/, so that any of us can answer! Or you can ask the duck at cs50.ai!

@22119795
Copy link

22119795 commented Jan 6, 2025

I like my homework

@22119795
Copy link

22119795 commented Jan 6, 2025

cs50

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants