Hot answers tagged

20 votes

What's the point of the modulo operation in the Caesar cipher formula?

Let's consider the encryption formula given in the problem set: cᵢ = (pᵢ + k) % 26 Here, as in the problem set,cᵢ represents the value of the encrypted or enciphered letter, pᵢ represents the value ...
user avatar
10 votes

How to handle the lack of argv[1] in caesar?

the issue is that you started your code int main( int argc, string argv[]) { int k = atoi(argv[1]; . . . } /// the mistakes is in the above assignment, if the there is no argv[1] so the OS will ...
user avatar
7 votes
Accepted

pset6 - caesar - check50 error: "expected exit code 1, not 0"

main in Python no longer has a special meaning, but is a regular function, its name only chosen to conform to conventions based in C. Try exit(1) instead of return 1. Relevant python docs: https://...
user avatar
  • 20.7k
6 votes

How to handle the lack of argv[1] in caesar?

The number of command-line arguments cannot be negative. In fact, it cannot even be < 1. See this answer for more details! If the number of command-line arguments is not 1 (i.e., argc != 2), your ...
user avatar
  • 17.4k
6 votes

How to handle "lack of argv[1]"

GAR, figured it out. I didn't take the details of "your program should yell at you" literally. This works now. if (argc != 2) { printf("YOU SCREWED UP!"); return 1; }
user avatar
5 votes

How to handle the lack of argv[1] in caesar?

You need to add your curly brackets (aka braces). Instead of if ( argc != 2 ) printf ("usage : ./caesar + key \n"); return 1; You should have: if ( argc != 2 ) { printf ("usage : ./...
user avatar
5 votes
Accepted

Ascii Becomes Negative?

By defaults, chars are signed values in the range -128 to 127. If, say, your plaintext[i] is 'x' (ie, 120) and you add a key of 10, you don't get 130. Instead, you get -126. Signed integers (chars)...
user avatar
  • 18.4k
5 votes

Segmentation fault (core dumped) in caesar

You should just run make caesar! :) Edit: Since you edited your question to a completely different one, a segmentation fault happens when you touch a memory location that you shouldn't touch. It's ...
user avatar
  • 17.4k
5 votes
Accepted

What does "expected output, not an exit code of 1" mean from check50?

The spec requires you to print a message to the user before returning 1. Looks like you aren't.
user avatar
  • 18.4k
5 votes
Accepted

Segmentation Fault and Returning 1

You have popped with many questions at the same time. Lets start with the simplest one. What's the relation between return value of a function and command line arguments? You don't return 1 because ...
user avatar
  • 3,316
5 votes

"Expected Expression" error on else function in caesar.c

@Cliff B's answer is almost correct except that it's not the semicolon that's breaking the syntax rule. it's the compound statement (the curly braces and the contents in between them). regardless of ...
user avatar
  • 17.4k
5 votes
Accepted

Modulo not working in caesar

Modulo is working correctly, but you've overlooked something. The idea behind using modulo is this. When you represent letters as numbers between 0 and 25 inclusive, and add a number to shift the ...
user avatar
  • 63.4k
5 votes
Accepted

Problem with caesar wrap

First of all you have to find the index in the alphabet of each letter in your plaintext. So if your plaintext is "abce" your indexes should be [0, 1, 2, 4] as A/a is 0 B/b is 1 ... Z/z is 25 You ...
user avatar
  • 7,326
4 votes
Accepted

My caesar output has no spaces

You don't necessarily have to use isblank() here. Instead, there should be an "else" case that executes when the "ith" character of the plain text to-be-encrypted is neither an uppercase nor lowercase ...
user avatar
  • 570
4 votes
Accepted

Why does isdigit(argv[1]) return segmentation fault?

Doesn't isdigit only work on chars, rather than argv[1] which is a string?
user avatar
4 votes

misleading description of int main(int argc, string argv[])

Nothing is misleading in the lectures, you interpreted them wrong. It should be noted that argv is itself not a string, it is collection of string type objects. Let me tell you the structure of ...
user avatar
  • 3,316
4 votes
Accepted

pset2 caesar converting from ascii to alphabetical

Your formula is correct as well as the understanding of the formula, only that you are mixing two things in a wrong way, look carefully at the following expression: ((('s[i]' - 97) + n) % 26) + 97) ...
user avatar
  • 5,172
4 votes
Accepted

This should be right (Caesar)

The output does not match the spec. This plaintext : should be this plaintext:. The same with ciphertext:. There is no space between the word and the :. While this may seem "overly strict", it is good ...
user avatar
4 votes
Accepted

Caesar code only works correctly when I add a random printf statement

It's a memory thing, as in you will get different results based on what is in memory.ctxt is declared as an array of chars. Here printf("ciphertext: %s\n", ctxt); is treating it like a string (viz ...
user avatar
3 votes

How to Encrypt Plaintext Properly When it Contains Non-Alphabetical Chars?

As others have said, you can reduce your loops by combining what they do into one loop. You don't need to store the user input, so you can modify it without worry. Other than that, I would just add ...
user avatar
  • 182
3 votes
Accepted

Why doesn't caesar pass check50 even though the output is correct?

You just need to add the return code "\n" at the end, the same way you added the rest of the characters.
user avatar
3 votes

I dont know where to start with caesar ciphere.I don't understand how the argv[ ] and argc really works

Essentially, argv[] is an array of size argc that tells you the parameters your code was called with. For instance, look at the make function you've been using - it takes one parameter, the name of ...
user avatar
  • 481
3 votes

Can someone explain me the point of the "int k = atoi((argv[1]);"?

In this problem set, you are not asked to get input from the user after the program starts but rather get it using command line arguments. command line arguments are basically just input that the user ...
user avatar
3 votes

pset2 - caesar - check 50 passes except for one weird error

Your program is not handling the case where the user does not provide a key. The array argv contains the command line arguments used to run the program. For example, the command "./caesar yxocll" ...
user avatar
  • 166
3 votes

What's the point of the modulo operation in the Caesar cipher formula?

The purpose of the formula is to calculate the new (cyphered) value for a given character on a string, considering a swift value. The formula has 4 components: ci = ciphered character pi = current ...
user avatar
3 votes
Accepted

compilation error multi-character character constant in caesar

Simple fix. Look at the line: int letter = 'plaintext[i]' ; You are trying to put the integer (ASCII) value of a letter stored at plaintext[i] into the variable letter. The idea is right, but look ...
user avatar
  • 63.4k
3 votes

pset2 (Hail, Caesar) - How to refine my code

One thing that sticks out about this is that you have special cases for spaces, commas, and exclamation marks. While I haven't tested your code directly, it looks like it wouldn't print characters ...
user avatar
  • 188
3 votes
Accepted

PSET 2 Caesar help

if (argc != 2) { return 1; printf("try again\n"); } else {.... why else, it is an unnecessary statement, if (argc != 2), exit the program, but simply the next line of code is executed, the ...
user avatar
  • 5,172
3 votes
Accepted

I just finished pset2 caesar. I get a segmentation fault if argc is other than 2

int k = atoi(argv[1]); if (argc != 2) {........... You are assuming that argv [1] exists before checking that really exists, if we have more than two arguments your program will work well, but if you ...
user avatar
  • 5,172
3 votes
Accepted

Pset2 - caesar - segmentation fault

You actually have two problems with seg faults. First, the one that you probably haven't seen yet. The code tries to assign argv[1] to key before verifying it exists on the next line. If you run the ...
user avatar
  • 63.4k

Only top scored, non community-wiki answers of a minimum length are eligible