# Tag Info

1

The problem lies here: int asciiValue = plaintext[i]+key%26; Simply put, it won't work at all. plaintext[i] contains an ASCII value for a letter. That's a number somewhere between 65 and 122 inclusive. Add a key to it and it's even larger. Now, what happens when you apply %26 to it? You ALWAYS get a number between 0 and 25 inclusive. In other words, you ...

1

As you know you've created a for loop that iterates once for each character introduced by the user of your program so, if you don't want to print printf("ciphertext: ......." for every character, you should only print the character like: printf("%c", YOURCHARVARIABLE);.

1

First to the error: i<len,k>=0 uses the comma operator, which evaluates its left side, discards the result, and evaluates to its right side. So i<len,k>=0 is the same as k>=0, the value of i<len is ignored. You're doing Caesar's cipher, right? This one looks like a strange crossover of caesar and vigenère. In Caesar's cipher, you shift ...

1

Currently it looks like you're looping through your ciphertext from 0 up to strlen(plaintext), however, you assigned ciphertext the size of strlen(plaintext)+1. Here's what's happening: The GetString() function gets a string from the user and, recalling what you might have seen in the lectures, every string is simply an array of characters ending with '\0' ...

1

cipher = (chr+key) % 26 So, if you enter, say d and a key of 5, then: cipher = ('d' + 5) % 26 cipher = (100 + 5) % 26 cipher = 1 1 is a non printable char. The formula for caesar given in the pset works on the assumption that your chars are in the range of 0 - 25 (not the ascii value). So you need to bring your 'd' down to that range (perhaps by ...

1

Simply put, your formula is flawed. Look at the formula that you have: code = code + user_key % 26; Assuming that you haven't altered the formula in your conversion to pseudocode, it has two problems. First, modulo has the same precedence rules as multiplication or division, so you would only be applying it to user_key and not to code or the sum of the ...

1

You're on the right track that something is wrong with J. The problem is that you've tied the index for the key, j, to the index for text, i. int j = i % strlen(keyword); You are probably seeing the encryption fail when you process a non-alpha in text. When a non-alpha is processed, such as a space, number or punctuation, the index for j must not be changed....

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