4
votes
Accepted
PSET 2 - Vigenere: How do I wrap around my key to the plaintext?
Well, I'll try to push you in the right direction without giving away the store here.
You say that you understand that you need to use a different index for the key and the plaintext, yet you are ...
4
votes
extra characters in Vigenere pset2 2016
First, notice that the check50 result and your result have different nonsense characters at the end.
Recall from the Week 2 Lecture "More on Strings" (starting around 1:18) the discussion about ...
4
votes
Accepted
vigenere sometimes prints extra characters at the end of ciphertext in an unpredictable pattern
The problem comes because cipher is declared a char array here char cipher[strlen(plain)];, but printed out using a string (aka char*) format here printf("ciphertext: %s\n", cipher);.
Remember, the ...
3
votes
Accepted
wrap around the keyword, vigenere
Look at your tests on the key. Here's one of them:
if (isupper(argv[1][c]))
When you encode a letter, you apply the modulo operation correctly to the key to get the right character, but when you are ...
3
votes
Accepted
Vigenere fails "world, say hello" with "baz" and "BaRFoo" with "BaZ"
Without digging deep into your code, I see two significant problems. They also happen to be the two most common errors on this pset. First, the code uses the same index, i, for both the plain text and ...
3
votes
Accepted
3
votes
Accepted
pset 2 vigenere at a loss
Firstly there are two compilation errors, that will prevent your code from even compiling (making me wonder whether you submitted a different version of your program to the check50).
The first one is ...
3
votes
Accepted
Vigenere -Isalpha only checking first char of key
Both clauses of the if/else contain return statements. When a return statement is encountered, it will immediately return control to the calling program with no further processing in the current ...
3
votes
Accepted
trail of strange characters after printing character array
Uhhuh. I see that it is doing a nice job of encoding and storing the encoded characters in an array. But have you also stored the end of string marker '\0' at the end of the string?
printf will ...
3
votes
Accepted
cs50/pset2/vigenere: Code works but check50 rejects 2 item
You are printing garbage values in the final printf statement:
printf("ciphertext: %s\n", cipher); //printing of ciphered text
You are asking it to print cipher as a string. You declared cipher as ...
3
votes
Accepted
Vigenere Segmentation understanding
This is a very, very common error for new programmers. The problem is the actual call to isalpha(). The isalpha() function takes a single char as input, but argv[1] is a string, not a char. Simply ...
3
votes
Why does the if else conditional give me a segmentation fault
First issue is that you blindly get argv[1] before actually checking the number of arguments. The segfault, however, comes from the fact you are passing a string to isalpha, whose argument is actually ...
3
votes
Accepted
Pset 2 Vigenere Increment Problem
This is a common error on this pset. The code needs two independent index variables to track the position within the plaintext and the key. You have two vars, i and cLength, but they are not ...
3
votes
I keep getting an error: incompatible pointer types passing 'string' (aka 'char *') to parameter of type 'string *' (aka 'char **')
This may sound mean, but the shift function is a mess. First, there's the error of the parameter mismatch. Note that declaring a string is really declaring a char *. Then, the parameter is itself an ...
2
votes
Accepted
check50 error in vigenere with baz and Hax0r2 argv
check50 has no bugs.
Your sandbox results show only one error 'szz' rather than 'rby' inside this string
Expecting the following on standard out — xoqmd, rby gflkp!\n ... but received the ...
2
votes
Accepted
What am I doing wrong in my pset2 vigenere code?
I see two significant issues. First, you have initialized countkey inside the for loop, so it will always reset to 0 at the top of the loop.
You should move all three of the variable declarations ...
2
votes
Accepted
There is something wrong with my keyformula in vigenere cipher
If the output of the program is too long, it's more likely due to incorrect control flow. Maybe i, which appears to be the index of the output array is going out of range?
Your gut instinct about the ...
2
votes
How to Wrap Around Array Indexes?
If you want to wrap negatively as well
(arrayIndex + arrayLength) % arrayLength
+ arrayLength ensures a positive result if your propgramming language supports Euclidean modulo.
2
votes
Accepted
pset2 Vigenere Modulo
In order to use modulo to wrap around the dictionary you first need to offset both key and plaintext to convert them to values between 0 and 25, and then add them and use modulo. That part is just as ...
2
votes
Cs50's vigerene encrypting problem
Your code has several issues. First, the way that you set the for loop up (incrementing both I and j on every pass) means that no matter what, the index for the key, j, is going to increment for ...
2
votes
Accepted
Why doesn't my vigenere work correctly for all inputs
Two classic errors. First, the index for the key is dependent the index for the plain text. They have to be independent of each other. The index for the plaintext will be incremented for every ...
2
votes
CS50 vigenere.c works for lower but not upper case letters
There are a couple of problems. The main one is that your code doesn't handle the case where the plain text and the key characters are not the same case. It assumes that if the plain text is lower ...
2
votes
Accepted
Having trouble with CS50 Vigenere Problem - Don't really know what is wrong
There's a small mistake in the elseif statement under if condition -
else if (isupper(s[i]) && islower(argv[1][j]))
{
printf("%c", ((((s[i] - 65) + (argv[1][j%kl] - 97)) % 26) ...
2
votes
Accepted
why won't my code print the strlen[text] amount of characters?
In this code, i and j would only be in synch for the first pass. Try tracking what will happen with paper and pencil. Say that strlen(text) is 7 and strlen(key) is 3. In the first outer loop, i ...
2
votes
Accepted
I have written this code for vigenere and it is giving 02 errors
The problem is that argv is an array of strings, and you try to use it as a single string.
See this line:
if (!isalpha (argv[1][i]))
and this:
if (isupper (argv[j]))
Can you spot the difference?
2
votes
Accepted
vigenere.c unknown problem / am I an idiot?
It's not so much being an idiot as it is having tunnel vision. ;-)
The problem isn't about vigKey. It's about what was done with the key string. If you look carefully at what the working code does, ...
2
votes
Finished vigenere, but it fails to work as it should
There are a few problems with the code that need to be dealt with. Much of it involves starting counts and indexes at 1 when they should start at 0.
First, the easy problem. The pset instructions ...
2
votes
Accepted
Vigenere Code Duplication / Design Flaw
It's good that you're thinking about this. It says that you're looking for better, more efficient ways to write code. This scenario is actually a red flag that maybe there is a better way to do ...
2
votes
Why doesn't this code work?
Because you are creating c as an array of strings. I think you meant to make c an array of n chars. Remember that a string is an array of chars in which the last char is a null terminator \0.
I ...
2
votes
vigenere.c key just wraps around ... if there is space in plain text it seems to ignore that key and move on to next
Please use argv[1] only after you've checked that argc is >=1, otherwise you might access an element that's after the array's end.
Instead of isdigit, I'd use !isalpha.
You could do that for example ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
vigenere × 495pset2 × 395
cs50x × 38
check50 × 29
c × 23
vigenere.c × 19
segmentation-fault × 17
key × 12
pset2-vigenere × 11
modulo × 9
wraparound × 9
string × 8
cs50-vigenere × 7
keyword × 7
error × 6
help × 5
cs50-pset2 × 5
caesar × 4
python × 4
pointers × 4
fails-check50-but-works × 4
loop × 4
week2 × 4
output × 4
isalpha × 4